2015-12-07 22:57:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2016-11-10 12:51:37 +00:00
|
|
|
source_root="$(dirname "$0")"
|
|
|
|
|
2016-06-16 23:35:03 +00:00
|
|
|
# Set to "latest" for the latest build.
|
2016-11-10 12:51:37 +00:00
|
|
|
: ${REALM_CORE_VERSION:=$(sed -n 's/^REALM_CORE_VERSION=\(.*\)$/\1/p' ${source_root}/../dependencies.list)}
|
|
|
|
: ${REALM_SYNC_VERSION:=$(sed -n 's/^REALM_SYNC_VERSION=\(.*\)$/\1/p' ${source_root}/../dependencies.list)}
|
2016-06-16 23:35:03 +00:00
|
|
|
|
|
|
|
if [ "$1" = '--version' ]; then
|
|
|
|
echo "$REALM_CORE_VERSION"
|
|
|
|
exit 0
|
2016-11-14 13:26:33 +00:00
|
|
|
elif [ "$1" = '--versionSync' ]; then
|
|
|
|
echo "$REALM_SYNC_VERSION"
|
|
|
|
exit 0
|
2016-06-16 23:35:03 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# The 'node' argument will result in realm-node build being downloaded.
|
|
|
|
if [ "$1" = 'node' ]; then
|
2016-11-11 16:42:35 +00:00
|
|
|
ENABLE_SYNC="$2"
|
2016-06-16 23:35:03 +00:00
|
|
|
CORE_DIR="core-node"
|
2016-11-09 23:01:42 +00:00
|
|
|
SYNC_DIR='node-sync'
|
2016-06-16 23:35:03 +00:00
|
|
|
|
|
|
|
if [ "$(uname)" = 'Darwin' ]; then
|
2016-10-05 00:27:09 +00:00
|
|
|
PLATFORM_TAG="node-osx-"
|
2016-11-09 23:01:42 +00:00
|
|
|
SYNC_PLATFORM_TAG="node-cocoa-"
|
2016-06-16 23:35:03 +00:00
|
|
|
CORE_DOWNLOAD_FILE="realm-core-node-osx-$REALM_CORE_VERSION.tar.gz"
|
2016-12-06 11:43:25 +00:00
|
|
|
SYNC_DOWNLOAD_FILE="realm-sync-$SYNC_PLATFORM_TAG$REALM_SYNC_VERSION.tar.gz"
|
2016-06-16 23:35:03 +00:00
|
|
|
else
|
2016-10-05 00:27:09 +00:00
|
|
|
PLATFORM_TAG="node-linux-"
|
2016-11-09 23:01:42 +00:00
|
|
|
SYNC_PLATFORM_TAG="node-cocoa-"
|
2016-06-16 23:35:03 +00:00
|
|
|
CORE_DOWNLOAD_FILE="realm-core-node-linux-$REALM_CORE_VERSION.tar.gz"
|
2016-11-10 13:42:58 +00:00
|
|
|
SYNC_DOWNLOAD_FILE=""
|
2016-06-16 23:35:03 +00:00
|
|
|
fi
|
2016-11-10 13:42:58 +00:00
|
|
|
|
2016-12-06 11:43:25 +00:00
|
|
|
SYNC_EXTRACT="tar -xvf"
|
2016-11-09 23:01:42 +00:00
|
|
|
EXTRACTED_DIR="realm-sync-node-cocoa-$REALM_SYNC_VERSION"
|
2016-06-16 23:35:03 +00:00
|
|
|
else
|
2016-11-11 16:42:35 +00:00
|
|
|
ENABLE_SYNC="yes" # FIXME: This means that both core and sync will be downloaded for non "node" targets.
|
|
|
|
# Should be 0 or 1. We do not need to download both
|
2016-06-16 23:35:03 +00:00
|
|
|
CORE_DIR='core'
|
2016-10-05 00:27:09 +00:00
|
|
|
PLATFORM_TAG=""
|
2016-11-09 23:01:42 +00:00
|
|
|
SYNC_DIR='sync'
|
2016-11-08 16:59:30 +00:00
|
|
|
CORE_DOWNLOAD_FILE="realm-core-$PLATFORM_TAG$REALM_CORE_VERSION.tar.xz"
|
2016-11-09 23:01:42 +00:00
|
|
|
SYNC_DOWNLOAD_FILE="realm-sync-cocoa-$SYNC_PLATFORM_TAG$REALM_SYNC_VERSION.tar.xz"
|
|
|
|
SYNC_EXTRACT="tar -xvf"
|
|
|
|
EXTRACTED_DIR="core"
|
2016-06-16 23:35:03 +00:00
|
|
|
fi
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-03-10 00:10:09 +00:00
|
|
|
# Start current working directory at the root of the project.
|
|
|
|
cd "$(dirname "$0")/.."
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-03-10 00:10:09 +00:00
|
|
|
die() {
|
|
|
|
echo "$@" >&2
|
|
|
|
exit 1
|
|
|
|
}
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-03-06 16:20:04 +00:00
|
|
|
download_core() {
|
2016-10-05 00:27:09 +00:00
|
|
|
local DIR=$1
|
|
|
|
local VERSION=$2
|
|
|
|
local DOWNLOAD_FILE=$3
|
|
|
|
local SERVER_DIR=$4
|
2016-11-09 16:25:25 +00:00
|
|
|
local UNTAR=$5
|
|
|
|
local UNTARRED_DIR=$6
|
2016-10-05 00:27:09 +00:00
|
|
|
echo "Downloading dependency: $DIR $VERSION"
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-10-05 00:27:09 +00:00
|
|
|
local TMP_DIR="${TMPDIR:-/tmp}/$DIR"
|
|
|
|
local TAR="$TMP_DIR/$DOWNLOAD_FILE"
|
|
|
|
local TMP_TAR="$TAR.tmp"
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-03-10 00:10:09 +00:00
|
|
|
mkdir -p "$TMP_DIR"
|
|
|
|
|
2016-10-05 00:27:09 +00:00
|
|
|
if [ ! -f "$TAR" ]; then
|
2016-11-09 16:25:25 +00:00
|
|
|
echo "https://static.realm.io/downloads/$SERVER_DIR/$DOWNLOAD_FILE"
|
2016-10-05 00:27:09 +00:00
|
|
|
curl -f -L -s "https://static.realm.io/downloads/$SERVER_DIR/$DOWNLOAD_FILE" -o "$TMP_TAR" ||
|
|
|
|
die "Downloading $DIR failed. Please try again once you have an Internet connection."
|
|
|
|
mv "$TMP_TAR" "$TAR"
|
2016-03-06 16:20:04 +00:00
|
|
|
else
|
2016-10-05 00:27:09 +00:00
|
|
|
echo "Using cached $DIR from TMPDIR"
|
2016-03-06 16:22:29 +00:00
|
|
|
fi
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-03-06 16:22:29 +00:00
|
|
|
(
|
2016-03-10 00:10:09 +00:00
|
|
|
cd "$TMP_DIR"
|
2016-10-05 00:27:09 +00:00
|
|
|
rm -rf "$DIR"
|
2016-11-09 16:51:19 +00:00
|
|
|
eval "$UNTAR" "$TAR"
|
2016-11-09 16:25:25 +00:00
|
|
|
mv "$UNTARRED_DIR" "$DIR-$VERSION"
|
2016-03-06 16:22:29 +00:00
|
|
|
)
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-10-05 00:27:09 +00:00
|
|
|
(
|
|
|
|
cd vendor
|
|
|
|
rm -rf "$DIR-$VERSION" "$DIR"
|
|
|
|
mv "$TMP_DIR/$DIR-$VERSION" .
|
|
|
|
ln -s "$DIR-$VERSION" "$DIR"
|
|
|
|
)
|
2016-03-10 00:10:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
check_release_notes() {
|
|
|
|
grep -Fqi "$REALM_CORE_VERSION RELEASE NOTES" "$@"
|
2016-03-06 16:20:04 +00:00
|
|
|
}
|
2016-03-10 00:10:09 +00:00
|
|
|
|
2016-11-11 16:42:35 +00:00
|
|
|
DOWNLOAD_CORE=1
|
|
|
|
|
|
|
|
if ! [ -z "$REALM_CORE_PREFIX" ]; then
|
|
|
|
DOWNLOAD_CORE=0
|
|
|
|
echo "Skipping the core download because REALM_CORE_PREFIX is defined."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ENABLE_SYNC" == 1 ]; then
|
|
|
|
DOWNLOAD_CORE=0
|
|
|
|
echo "Skipping the core download because ENABLE_SYNC is true."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DOWNLOAD_CORE" == 1 ]; then
|
2016-11-11 13:46:16 +00:00
|
|
|
if [ ! -e "vendor/$CORE_DIR" ]; then
|
|
|
|
download_core $CORE_DIR $REALM_CORE_VERSION $CORE_DOWNLOAD_FILE core "tar -xzf" core
|
|
|
|
elif [ -d "vendor/$CORE_DIR" -a -d ../realm-core -a ! -L "vendor/$CORE_DIR" ]; then
|
|
|
|
# Allow newer versions than expected for local builds as testing
|
|
|
|
# with unreleased versions is one of the reasons to use a local build
|
|
|
|
if ! check_release_notes "vendor/$CORE_DIR/CHANGELOG.txt"; then
|
|
|
|
die "Local build of core is out of date."
|
|
|
|
else
|
|
|
|
echo "The core library seems to be up to date."
|
|
|
|
fi
|
|
|
|
elif [ ! -L "vendor/$CORE_DIR" ]; then
|
|
|
|
echo "vendor/$CORE_DIR is not a symlink. Deleting..."
|
|
|
|
rm -rf "vendor/$CORE_DIR"
|
|
|
|
download_core $CORE_DIR $REALM_CORE_VERSION $CORE_DOWNLOAD_FILE core "tar -xzf" core
|
|
|
|
# With a prebuilt version we only want to check the first non-empty
|
|
|
|
# line so that checking out an older commit will download the
|
|
|
|
# appropriate version of core if the already-present version is too new
|
|
|
|
elif ! grep -m 1 . "vendor/$CORE_DIR/CHANGELOG.txt" | check_release_notes; then
|
|
|
|
download_core $CORE_DIR $REALM_CORE_VERSION $CORE_DOWNLOAD_FILE core "tar -xzf" core
|
2016-03-06 16:20:04 +00:00
|
|
|
else
|
2016-03-06 16:22:29 +00:00
|
|
|
echo "The core library seems to be up to date."
|
2016-03-06 16:20:04 +00:00
|
|
|
fi
|
|
|
|
fi
|
2016-10-05 00:27:09 +00:00
|
|
|
|
2016-11-11 16:42:35 +00:00
|
|
|
DOWNLOAD_SYNC=1
|
|
|
|
if ! [ -z "$REALM_SYNC_PREFIX" ]; then
|
|
|
|
DOWNLOAD_SYNC=0
|
|
|
|
echo "Skipping the sync download because REALM_SYNC_PREFIX is defined."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$ENABLE_SYNC" == 0 ]; then
|
|
|
|
DOWNLOAD_SYNC=0
|
|
|
|
echo "Skipping the sync download because ENABLE_SYNC is false."
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [ "$DOWNLOAD_SYNC" == 1 ]; then
|
2016-11-11 13:46:16 +00:00
|
|
|
if [ -n "$SYNC_DOWNLOAD_FILE" ];then
|
|
|
|
if [ ! -e "vendor/$SYNC_DIR" ]; then
|
|
|
|
download_core $SYNC_DIR $REALM_SYNC_VERSION $SYNC_DOWNLOAD_FILE sync "$SYNC_EXTRACT" $EXTRACTED_DIR
|
|
|
|
elif [ -d "vendor/$SYNC_DIR" -a -d ../realm-sync -a ! -L "vendor/$SYNC_DIR" ]; then
|
|
|
|
# Allow newer versions than expected for local builds as testing
|
|
|
|
# with unreleased versions is one of the reasons to use a local build
|
|
|
|
if ! check_release_notes "vendor/$SYNC_DIR/version.txt"; then
|
|
|
|
die "Local build of sync is out of date."
|
|
|
|
else
|
|
|
|
echo "The sync library seems to be up to date."
|
|
|
|
fi
|
|
|
|
elif [ ! -L "vendor/$SYNC_DIR" ]; then
|
|
|
|
echo "vendor/$SYNC_DIR is not a symlink. Deleting..."
|
|
|
|
rm -rf "vendor/$SYNC_DIR"
|
|
|
|
download_core $SYNC_DIR $REALM_SYNC_VERSION $SYNC_DOWNLOAD_FILE sync "$SYNC_EXTRACT" $EXTRACTED_DIR
|
|
|
|
# With a prebuilt version we only want to check the first non-empty
|
|
|
|
# line so that checking out an older commit will download the
|
|
|
|
# appropriate version of core if the already-present version is too new
|
|
|
|
elif ! grep -m 1 . "vendor/$SYNC_DIR/version.txt"; then
|
|
|
|
download_core $SYNC_DIR $REALM_SYNC_VERSION $SYNC_DOWNLOAD_FILE sync "$SYNC_EXTRACT" $EXTRACTED_DIR
|
2016-11-10 13:42:58 +00:00
|
|
|
else
|
|
|
|
echo "The sync library seems to be up to date."
|
|
|
|
fi
|
2016-10-05 00:27:09 +00:00
|
|
|
fi
|
|
|
|
fi
|