diff --git a/bin/update/00-run.sh b/bin/update/00-run.sh new file mode 100755 index 0000000..eb34a16 --- /dev/null +++ b/bin/update/00-run.sh @@ -0,0 +1,34 @@ +#!/bin/bash -e + +RELEASE=$1 +UMBREL_PATH=$2 +UMBREL_USER=$3 + +echo "==== OTA UPDATE ===== | STAGE: PRE-UPDATE" +echo "Installing Umbrel $1 at $2" + +# Update status file +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 20, "description": "Backing up"} +EOF + +# Cleanup just in case there's temp stuff lying around from previous update +echo "Cleaning up any previous backup" +[ -d /tmp/umbrel-backup ] && rm -rf /tmp/umbrel-backup + +# Fix permissions +echo "Fixing permissions" +chown -R $UMBREL_USER:$UMBREL_USER $UMBREL_PATH/ + +# Backup +echo "Backing up existing directory tree" +rsync -av $UMBREL_PATH/ \ + --exclude='.*' \ + --exclude='bitcoin' \ + --exclude='lnd' \ + --exclude='db' \ + --exclude='secrets' \ + --exclude='tor' \ + /tmp/umbrel-backup/ + +echo "Successfully backed up to /tmp/umbrel-backup" \ No newline at end of file diff --git a/bin/update/01-run.sh b/bin/update/01-run.sh new file mode 100755 index 0000000..348a5ea --- /dev/null +++ b/bin/update/01-run.sh @@ -0,0 +1,62 @@ +#!/bin/bash -e + +RELEASE=$1 +UMBREL_PATH=$2 +UMBREL_USER=$3 + +echo "==== OTA UPDATE ===== | STAGE: INSTALL UPDATE" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 33, "description": "Configuring settings"} +EOF + +# Checkout to the new release +cd /tmp/umbrel-$RELEASE + +echo "Removing unwanted stuff" +# Remove unwanted stuff +rm -rf bitcoin +rm -rf lnd +rm -rf db +rm -rf tor +rm -rf secrets + +# Update RPC Password in docker-compose.yml +echo "Updating RPC Password in docker-compose.yml" +RPCPASS=`cat $UMBREL_PATH/secrets/rpcpass.txt` +sed -i "s/RPCPASS/${RPCPASS}/g;" docker-compose.yml + +echo "Setting regtest" +sed -i 's/mainnet/regtest/g; ' docker-compose.yml +sed -i "s/RPCPORT/18443/g;" docker-compose.yml + +# Pull new images +echo "Pulling new images" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 40, "description": "Downloading new Docker images"} +EOF +docker-compose --file /tmp/umbrel-$RELEASE/docker-compose.yml pull + +# Stop existing containers +echo "Stopping existing containers" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 70, "description": "Removing old containers"} +EOF +su - $UMBREL_USER -c "cd $UMBREL_PATH; docker-compose --file $UMBREL_PATH/docker-compose.yml down" + +# Overlay home dir structure with new dir tree +echo "Overlaying $UMBREL_PATH/ with new directory tree" +rsync -av /tmp/umbrel-$RELEASE/ \ + --exclude='.*' \ + $UMBREL_PATH/ + +#Fix permissions +echo "Fixing permissions" +chown -R $UMBREL_USER:$UMBREL_USER $UMBREL_PATH/ + +# Start updated containers +echo "Starting new containers" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 80, "description": "Starting new containers"} +EOF +cd $UMBREL_PATH +su - $UMBREL_USER -c "cd $UMBREL_PATH; docker-compose --file $UMBREL_PATH/docker-compose.yml up --detach --remove-orphans" \ No newline at end of file diff --git a/bin/update/02-run.sh b/bin/update/02-run.sh new file mode 100755 index 0000000..533e0af --- /dev/null +++ b/bin/update/02-run.sh @@ -0,0 +1,9 @@ +#!/bin/bash -e + +RELEASE=$1 +UMBREL_PATH=$2 +UMBREL_USER=$3 + +echo "==== OTA UPDATE ===== | STAGE: POST-UPDATE" + +# Nothing here for now \ No newline at end of file diff --git a/bin/update/03-run.sh b/bin/update/03-run.sh new file mode 100755 index 0000000..42ff2b3 --- /dev/null +++ b/bin/update/03-run.sh @@ -0,0 +1,26 @@ +#!/bin/bash -e + +RELEASE=$1 +UMBREL_PATH=$2 +UMBREL_USER=$3 + +echo "==== OTA UPDATE ===== | STAGE: SUCCESS" + +# Delete previous (unused) images +echo "Deleting previous images" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 90, "description": "Deleting previous images"} +EOF +# docker image prune --all --force + +# Cleanup +echo "Removing backup" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 95, "description": "Removing backup"} +EOF +[ -d /tmp/umbrel-backup ] && rm -rf /tmp/umbrel-backup + +echo "Successfully installed Umbrel $RELEASE" +cat < $UMBREL_PATH/bin/update/status.json +{"state": "success", "progress": 100, "description": "Successfully installed Umbrel $RELEASE"} +EOF \ No newline at end of file diff --git a/bin/update/README.md b/bin/update/README.md new file mode 100644 index 0000000..3b2bfff --- /dev/null +++ b/bin/update/README.md @@ -0,0 +1 @@ +# Over-The-Air (OTA) Updates \ No newline at end of file diff --git a/bin/update/start.sh b/bin/update/start.sh new file mode 100755 index 0000000..3b71cc9 --- /dev/null +++ b/bin/update/start.sh @@ -0,0 +1,56 @@ +#!/bin/bash -e + +UMBREL_PATH=$(dirname $(readlink -f $0)) +RELEASE="v$(cat $UMBREL_PATH/statuses/start-update)" +UMBREL_USER=umbrel + +echo "==== OTA UPDATE ===== | STAGE: DOWNLOAD" + +if [ -z $(grep '[^[:space:]]' $UMBREL_PATH/statuses/start-update) ] ;then + echo "Empty start update signal file. Version not found" + exit 1 +fi + +# Make sure an update is not in progress +[ -f "$UMBREL_PATH/statuses/update-in-progress" ] && exit 2; + +echo "Creating lock" +touch $UMBREL_PATH/statuses/update-in-progress + +# Cleanup just in case there's temp stuff lying around from previous update +echo "Cleaning up any previous mess" +[ -d /tmp/umbrel-$RELEASE ] && rm -rf /tmp/umbrel-$RELEASE + +# Update status file +cat < $UMBREL_PATH/bin/update/status.json +{"state": "installing", "progress": 10, "description": "Downloading Umbrel $RELEASE"} +EOF + +# Clone new release +echo "Downloading Umbrel $RELEASE" + +cd /tmp/umbrel-$RELEASE +wget -qO- "https://raw.githubusercontent.com/mayankchhabra/umbrel/$RELEASE/install-box.sh" +./install-box.sh + +cd bin/update + +echo "Running update install scripts of the new release" +for i in {00..99}; do + if [ -x ${i}-run.sh ]; then + echo "Begin ${i}-run.sh" + ./${i}-run.sh $RELEASE $UMBREL_PATH $UMBREL_USER + echo "End ${i}-run.sh" + fi +done + +echo "Deleting cloned repository" +[ -d /tmp/umbrel-$RELEASE ] && rm -rf /tmp/umbrel-$RELEASE + +echo "Deleting update signal file" +rm -f $UMBREL_PATH/statuses/start-update + +echo "Removing lock" +rm -f $UMBREL_PATH/statuses/update-in-progress + +exit 0 \ No newline at end of file diff --git a/bin/update/status.json b/bin/update/status.json new file mode 100644 index 0000000..b006031 --- /dev/null +++ b/bin/update/status.json @@ -0,0 +1,5 @@ +{ + "state": "success", + "progress": 100, + "description": "" +} \ No newline at end of file diff --git a/version.json b/version.json new file mode 100644 index 0000000..740da7e --- /dev/null +++ b/version.json @@ -0,0 +1,5 @@ +{ + "version": "0.1.3-beta", + "name": "Umbrel v0.1.3 Beta", + "notes": "This version introduces a number of bug fixes and features." +} \ No newline at end of file