2015-12-07 22:57:19 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
set -e
|
|
|
|
set -o pipefail
|
|
|
|
|
2016-06-16 23:35:03 +00:00
|
|
|
# Set to "latest" for the latest build.
|
|
|
|
: ${REALM_CORE_VERSION:=1.1.2}
|
|
|
|
|
|
|
|
if [ "$1" = '--version' ]; then
|
|
|
|
echo "$REALM_CORE_VERSION"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
# The 'node' argument will result in realm-node build being downloaded.
|
|
|
|
if [ "$1" = 'node' ]; then
|
|
|
|
CORE_DIR="core-node"
|
|
|
|
|
|
|
|
if [ "$(uname)" = 'Darwin' ]; then
|
|
|
|
CORE_DOWNLOAD_FILE="realm-core-node-osx-$REALM_CORE_VERSION.tar.gz"
|
|
|
|
else
|
|
|
|
CORE_DOWNLOAD_FILE="realm-core-node-linux-$REALM_CORE_VERSION.tar.gz"
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
CORE_DIR='core'
|
|
|
|
CORE_DOWNLOAD_FILE="realm-core-$REALM_CORE_VERSION.tar.bz2"
|
|
|
|
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-06-16 23:35:03 +00:00
|
|
|
echo "Downloading dependency: $CORE_DIR $REALM_CORE_VERSION"
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-06-17 20:17:01 +00:00
|
|
|
local TMP_DIR="${TMPDIR:-/tmp}/core_bin"
|
2016-06-16 23:35:03 +00:00
|
|
|
local CORE_TAR="$TMP_DIR/$CORE_DOWNLOAD_FILE"
|
2016-03-10 00:10:09 +00:00
|
|
|
local CORE_TMP_TAR="$CORE_TAR.tmp"
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-03-10 00:10:09 +00:00
|
|
|
mkdir -p "$TMP_DIR"
|
|
|
|
|
|
|
|
if [ ! -f "$CORE_TAR" ]; then
|
2016-06-16 23:35:03 +00:00
|
|
|
curl -f -L -s "https://static.realm.io/downloads/core/$CORE_DOWNLOAD_FILE" -o "$CORE_TMP_TAR" ||
|
|
|
|
die "Downloading $CORE_DIR failed. Please try again once you have an Internet connection."
|
2016-03-10 00:10:09 +00:00
|
|
|
mv "$CORE_TMP_TAR" "$CORE_TAR"
|
2016-03-06 16:20:04 +00:00
|
|
|
else
|
2016-06-16 23:35:03 +00:00
|
|
|
echo "Using cached $CORE_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-06-16 23:35:03 +00:00
|
|
|
rm -rf "$CORE_DIR"
|
|
|
|
tar -xzf "$CORE_TAR"
|
|
|
|
mv core "$CORE_DIR-$REALM_CORE_VERSION"
|
2016-03-06 16:22:29 +00:00
|
|
|
)
|
2015-12-07 22:57:19 +00:00
|
|
|
|
2016-06-16 23:35:03 +00:00
|
|
|
rm -rf "$CORE_DIR-$REALM_CORE_VERSION" "$CORE_DIR"
|
|
|
|
mv "$TMP_DIR/$CORE_DIR-$REALM_CORE_VERSION" .
|
|
|
|
ln -s "$CORE_DIR-$REALM_CORE_VERSION" "$CORE_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-06-16 23:35:03 +00:00
|
|
|
if [ ! -e "$CORE_DIR" ]; then
|
2016-03-10 00:10:09 +00:00
|
|
|
download_core
|
2016-06-16 23:35:03 +00:00
|
|
|
elif [ -d "$CORE_DIR" -a -d ../realm-core -a ! -L "$CORE_DIR" ]; then
|
2016-03-06 16:20:04 +00:00
|
|
|
# Allow newer versions than expected for local builds as testing
|
|
|
|
# with unreleased versions is one of the reasons to use a local build
|
2016-06-16 23:35:03 +00:00
|
|
|
if ! check_release_notes "$CORE_DIR/release_notes.txt"; then
|
2016-03-10 00:10:09 +00:00
|
|
|
die "Local build of core is out of date."
|
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
|
2016-06-16 23:35:03 +00:00
|
|
|
elif [ ! -L "$CORE_DIR" ]; then
|
|
|
|
echo "$CORE_DIR is not a symlink. Deleting..."
|
|
|
|
rm -rf "$CORE_DIR"
|
2016-03-06 16:22:29 +00:00
|
|
|
download_core
|
2016-03-10 00:10:09 +00:00
|
|
|
# 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
|
2016-06-16 23:35:03 +00:00
|
|
|
elif ! grep -m 1 . "$CORE_DIR/release_notes.txt" | check_release_notes; then
|
2016-03-10 00:10:09 +00:00
|
|
|
download_core
|
|
|
|
else
|
|
|
|
echo "The core library seems to be up to date."
|
2016-03-06 16:20:04 +00:00
|
|
|
fi
|