From 36192c45e173724b6ef3dcf14f7b87ee952155e8 Mon Sep 17 00:00:00 2001 From: Luke Childs Date: Thu, 13 Aug 2020 14:27:30 +0700 Subject: [PATCH] Add --ota and --path option to update script --- events/triggers/update | 2 +- scripts/update/update | 40 +++++++++++++++++++++++++++++++++++----- 2 files changed, 36 insertions(+), 6 deletions(-) diff --git a/events/triggers/update b/events/triggers/update index 8bfbcf2..c2e017f 100755 --- a/events/triggers/update +++ b/events/triggers/update @@ -2,4 +2,4 @@ UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)" -"${UMBREL_ROOT}/scripts/update/update" +"${UMBREL_ROOT}/scripts/update/update" --ota diff --git a/scripts/update/update b/scripts/update/update index 7b83344..69b5399 100755 --- a/scripts/update/update +++ b/scripts/update/update @@ -14,6 +14,22 @@ check_dependencies jq wget git rsync UMBREL_ROOT="$(readlink -f $(dirname "${BASH_SOURCE[0]}")/../..)" RELEASE=$(cat "$UMBREL_ROOT"/statuses/update-status.json | jq .updateTo -r) +update_type="" +if [[ "${1}" == "--ota" ]]; then + update_type="ota" +elif [[ "${1}" == "--path" ]]; then + update_type="path" + update_path="${2}" +else + echo "Update requires \"--ota\" or \"--path \" option." + exit 1 +fi + +if [[ "${update_type}" == "path" ]] && [[ ! -f "${update_path}/.umbrel" ]]; then + echo "Update path doesn't seem to be an Umbrel install." + exit 1 +fi + echo echo "=======================================" echo "=============== UPDATE ================" @@ -40,11 +56,25 @@ cat < "$UMBREL_ROOT"/statuses/update-status.json {"state": "installing", "progress": 10, "description": "Downloading Umbrel $RELEASE", "updateTo": "$RELEASE"} EOF -# Clone new release -echo "Downloading Umbrel $RELEASE" -mkdir -p "$UMBREL_ROOT"/.umbrel-"$RELEASE" -cd "$UMBREL_ROOT"/.umbrel-"$RELEASE" -curl -L "https://github.com/getumbrel/umbrel/archive/$RELEASE.tar.gz" | tar -xz --strip-components=1 +# Download new release +if [[ "${update_type}" == "ota" ]]; then + echo "Downloading Umbrel ${RELEASE}" + mkdir -p "${UMBREL_ROOT}/.umbrel-${RELEASE}" + cd "${UMBREL_ROOT}/.umbrel-${RELEASE}" + curl -L "https://github.com/getumbrel/umbrel/archive/$RELEASE.tar.gz" | tar -xz --strip-components=1 +fi + +# Copy over new release from path +if [[ "${update_type}" == "path" ]]; then + echo "Copying Umbrel ${RELEASE} from ${update_path}" + mkdir -p "${UMBREL_ROOT}/.umbrel-${RELEASE}" + cp --recursive \ + --archive \ + --no-target-directory \ + "${update_path}" "${UMBREL_ROOT}/.umbrel-${RELEASE}" + cd "${UMBREL_ROOT}/.umbrel-${RELEASE}" +fi + # Run update scripts echo "Running update install scripts of the new release"