Browse Source

OTA base

ota-updates
Mayank 5 years ago
parent
commit
75e4dd02ed
No known key found for this signature in database GPG Key ID: D037D60476CE748C
  1. 34
      bin/update/00-run.sh
  2. 62
      bin/update/01-run.sh
  3. 9
      bin/update/02-run.sh
  4. 26
      bin/update/03-run.sh
  5. 1
      bin/update/README.md
  6. 56
      bin/update/start.sh
  7. 5
      bin/update/status.json
  8. 5
      version.json

34
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 <<EOF > $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"

62
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 <<EOF > $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 <<EOF > $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 <<EOF > $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 <<EOF > $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"

9
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

26
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 <<EOF > $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 <<EOF > $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 <<EOF > $UMBREL_PATH/bin/update/status.json
{"state": "success", "progress": 100, "description": "Successfully installed Umbrel $RELEASE"}
EOF

1
bin/update/README.md

@ -0,0 +1 @@
# Over-The-Air (OTA) Updates

56
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 <<EOF > $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

5
bin/update/status.json

@ -0,0 +1,5 @@
{
"state": "success",
"progress": 100,
"description": ""
}

5
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."
}
Loading…
Cancel
Save