From 4e773d97fed43c2731256792a6730d38e7d7e64d Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Sun, 6 Mar 2016 08:20:04 -0800 Subject: [PATCH 1/3] don't download/unpack core unnecessarily --- scripts/download-core.sh | 64 ++++++++++++++++++++++++++++------------ 1 file changed, 45 insertions(+), 19 deletions(-) diff --git a/scripts/download-core.sh b/scripts/download-core.sh index ac74df80..d619641c 100755 --- a/scripts/download-core.sh +++ b/scripts/download-core.sh @@ -5,26 +5,52 @@ set -o pipefail : ${REALM_CORE_VERSION:=0.95.6} # set to "current" to always use the current build -echo "Downloading dependency: core ${REALM_CORE_VERSION}" +download_core() { + echo "Downloading dependency: core ${REALM_CORE_VERSION}" -TMP_DIR="$TMPDIR/core_bin" -mkdir -p "${TMP_DIR}" -CORE_TMP_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp" -CORE_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2" + TMP_DIR="$TMPDIR/core_bin" + mkdir -p "${TMP_DIR}" + CORE_TMP_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp" + CORE_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2" -if [ ! -f "${CORE_TAR}" ]; then - curl -f -L -s "https://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2" -o "${CORE_TMP_TAR}" || - (echo "Downloading core failed. Please try again once you have an Internet connection." && exit 1) - mv "${CORE_TMP_TAR}" "${CORE_TAR}" + if [ ! -f "${CORE_TAR}" ]; then + curl -f -L -s "https://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2" -o "${CORE_TMP_TAR}" || + (echo "Downloading core failed. Please try again once you have an Internet connection." && exit 1) + mv "${CORE_TMP_TAR}" "${CORE_TAR}" + else + echo "Using cached core from TEMPDIR" + fi + + ( + cd "${TMP_DIR}" + rm -rf core + tar xjf "${CORE_TAR}" + mv core core-${REALM_CORE_VERSION} + ) + + rm -rf core-${REALM_CORE_VERSION} core + mv ${TMP_DIR}/core-${REALM_CORE_VERSION} . + ln -s core-${REALM_CORE_VERSION} core +} +if [ -d core -a -d ../realm-core -a ! -L core ]; 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 ! $(grep -i "${REALM_CORE_VERSION} Release notes" core/release_notes.txt >/dev/null); then + echo "Local build of core is out of date." + exit 1 + else + echo "The core library seems to be up to date." + fi +elif ! [ -L core ]; then + echo "core is not a symlink. Deleting..." + rm -rf core + download_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 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then + download_core + else + echo "The core library seems to be up to date." fi -( - cd "${TMP_DIR}" - rm -rf core - tar xjf "${CORE_TAR}" - mv core core-${REALM_CORE_VERSION} -) - -rm -rf core-${REALM_CORE_VERSION} core -mv ${TMP_DIR}/core-${REALM_CORE_VERSION} . -ln -s core-${REALM_CORE_VERSION} core From a9e9710f8228a4ad51874206296fcb4c6697968b Mon Sep 17 00:00:00 2001 From: Ari Lazier Date: Sun, 6 Mar 2016 08:22:29 -0800 Subject: [PATCH 2/3] fix spacing --- scripts/download-core.sh | 66 ++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/scripts/download-core.sh b/scripts/download-core.sh index d619641c..faa08b18 100755 --- a/scripts/download-core.sh +++ b/scripts/download-core.sh @@ -6,51 +6,51 @@ set -o pipefail : ${REALM_CORE_VERSION:=0.95.6} # set to "current" to always use the current build download_core() { - echo "Downloading dependency: core ${REALM_CORE_VERSION}" + echo "Downloading dependency: core ${REALM_CORE_VERSION}" - TMP_DIR="$TMPDIR/core_bin" - mkdir -p "${TMP_DIR}" - CORE_TMP_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp" - CORE_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2" + TMP_DIR="$TMPDIR/core_bin" + mkdir -p "${TMP_DIR}" + CORE_TMP_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp" + CORE_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2" - if [ ! -f "${CORE_TAR}" ]; then - curl -f -L -s "https://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2" -o "${CORE_TMP_TAR}" || - (echo "Downloading core failed. Please try again once you have an Internet connection." && exit 1) - mv "${CORE_TMP_TAR}" "${CORE_TAR}" + if [ ! -f "${CORE_TAR}" ]; then + curl -f -L -s "https://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2" -o "${CORE_TMP_TAR}" || + (echo "Downloading core failed. Please try again once you have an Internet connection." && exit 1) + mv "${CORE_TMP_TAR}" "${CORE_TAR}" else - echo "Using cached core from TEMPDIR" - fi + echo "Using cached core from TEMPDIR" + fi - ( - cd "${TMP_DIR}" - rm -rf core - tar xjf "${CORE_TAR}" - mv core core-${REALM_CORE_VERSION} - ) + ( + cd "${TMP_DIR}" + rm -rf core + tar xjf "${CORE_TAR}" + mv core core-${REALM_CORE_VERSION} + ) - rm -rf core-${REALM_CORE_VERSION} core - mv ${TMP_DIR}/core-${REALM_CORE_VERSION} . - ln -s core-${REALM_CORE_VERSION} core + rm -rf core-${REALM_CORE_VERSION} core + mv ${TMP_DIR}/core-${REALM_CORE_VERSION} . + ln -s core-${REALM_CORE_VERSION} core } if [ -d core -a -d ../realm-core -a ! -L core ]; 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 ! $(grep -i "${REALM_CORE_VERSION} Release notes" core/release_notes.txt >/dev/null); then - echo "Local build of core is out of date." - exit 1 + echo "Local build of core is out of date." + exit 1 else - echo "The core library seems to be up to date." + echo "The core library seems to be up to date." fi elif ! [ -L core ]; then - echo "core is not a symlink. Deleting..." - rm -rf core - download_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 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then - download_core - else - echo "The core library seems to be up to date." + echo "core is not a symlink. Deleting..." + rm -rf core + download_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 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then + download_core + else + echo "The core library seems to be up to date." fi From eac5f570b60e18a2b94e7f65bc64e6148997377d Mon Sep 17 00:00:00 2001 From: Scott Kyle Date: Wed, 9 Mar 2016 16:10:09 -0800 Subject: [PATCH 3/3] Logic and style fixes for download-core script --- scripts/download-core.sh | 72 ++++++++++++++++++++++++---------------- 1 file changed, 43 insertions(+), 29 deletions(-) diff --git a/scripts/download-core.sh b/scripts/download-core.sh index faa08b18..f749351c 100755 --- a/scripts/download-core.sh +++ b/scripts/download-core.sh @@ -5,52 +5,66 @@ set -o pipefail : ${REALM_CORE_VERSION:=0.95.6} # set to "current" to always use the current build +# Start current working directory at the root of the project. +cd "$(dirname "$0")/.." + +die() { + echo "$@" >&2 + exit 1 +} + download_core() { - echo "Downloading dependency: core ${REALM_CORE_VERSION}" + echo "Downloading dependency: core $REALM_CORE_VERSION" - TMP_DIR="$TMPDIR/core_bin" - mkdir -p "${TMP_DIR}" - CORE_TMP_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2.tmp" - CORE_TAR="${TMP_DIR}/core-${REALM_CORE_VERSION}.tar.bz2" + local TMP_DIR="$TMPDIR/core_bin" + local CORE_TAR="$TMP_DIR/core-$REALM_CORE_VERSION.tar.bz2" + local CORE_TMP_TAR="$CORE_TAR.tmp" - if [ ! -f "${CORE_TAR}" ]; then - curl -f -L -s "https://static.realm.io/downloads/core/realm-core-${REALM_CORE_VERSION}.tar.bz2" -o "${CORE_TMP_TAR}" || - (echo "Downloading core failed. Please try again once you have an Internet connection." && exit 1) - mv "${CORE_TMP_TAR}" "${CORE_TAR}" + mkdir -p "$TMP_DIR" + + if [ ! -f "$CORE_TAR" ]; then + curl -f -L -s "https://static.realm.io/downloads/core/realm-core-$REALM_CORE_VERSION.tar.bz2" -o "$CORE_TMP_TAR" || + die "Downloading core failed. Please try again once you have an Internet connection." + mv "$CORE_TMP_TAR" "$CORE_TAR" else - echo "Using cached core from TEMPDIR" + echo "Using cached core from TMPDIR" fi ( - cd "${TMP_DIR}" + cd "$TMP_DIR" rm -rf core - tar xjf "${CORE_TAR}" - mv core core-${REALM_CORE_VERSION} + tar xjf "$CORE_TAR" + mv core "core-$REALM_CORE_VERSION" ) - rm -rf core-${REALM_CORE_VERSION} core - mv ${TMP_DIR}/core-${REALM_CORE_VERSION} . - ln -s core-${REALM_CORE_VERSION} core + rm -rf "core-$REALM_CORE_VERSION" core + mv "$TMP_DIR/core-$REALM_CORE_VERSION" . + ln -s "core-$REALM_CORE_VERSION" core } -if [ -d core -a -d ../realm-core -a ! -L core ]; then + +check_release_notes() { + grep -Fqi "$REALM_CORE_VERSION RELEASE NOTES" "$@" +} + +if [ ! -e core ]; then + download_core +elif [ -d core -a -d ../realm-core -a ! -L core ]; 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 ! $(grep -i "${REALM_CORE_VERSION} Release notes" core/release_notes.txt >/dev/null); then - echo "Local build of core is out of date." - exit 1 + if ! check_release_notes core/release_notes.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 core ]; then +elif [ ! -L core ]; then echo "core is not a symlink. Deleting..." rm -rf core download_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 . core/release_notes.txt | grep -i "${REALM_CORE_VERSION} RELEASE NOTES" >/dev/null); then - download_core - else - echo "The core library seems to be up to date." +# 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 . core/release_notes.txt | check_release_notes; then + download_core +else + echo "The core library seems to be up to date." fi -