You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.9 KiB

#!/usr/bin/env bash
set -euo pipefail
5 years ago
5 years ago
UMBREL_ROOT=$(dirname $(readlink -f ../../$0))
# UMBREL_ROOT=/home/umbrel
RELEASE="v$(cat $UMBREL_ROOT/events/signals/update)"
5 years ago
UMBREL_USER=umbrel
5 years ago
if [ $(whoami) != 'root' ]; then
UMBREL_USER=$(whoami)
fi
5 years ago
echo
5 years ago
echo "======================================="
echo "============= OTA UPDATE =============="
echo "======================================="
echo "========== Stage: Download ============"
echo "======================================="
echo
5 years ago
if [ -z $(grep '[^[:space:]]' $UMBREL_ROOT/events/signals/update) ]; then
5 years ago
echo "Empty update signal file. No release version not found."
5 years ago
exit 1
fi
5 years ago
# Make sure an update is not in progres
if [ -f "$UMBREL_ROOT/statuses/update-in-progress" ]; then
echo "An update is already in progress. Exiting now."
exit 2
fi
5 years ago
echo "Creating lock"
5 years ago
touch $UMBREL_ROOT/statuses/update-in-progress
5 years ago
# 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
5 years ago
cat <<EOF > $UMBREL_ROOT/statuses/update-status.json
5 years ago
{"state": "installing", "progress": 10, "description": "Downloading Umbrel $RELEASE"}
EOF
# Clone new release
echo "Downloading Umbrel $RELEASE"
cd /tmp/umbrel-$RELEASE
5 years ago
wget -qO- "https://raw.githubusercontent.com/mayankchhabra/umbrel/$RELEASE/install-box.sh" | sh
5 years ago
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"
5 years ago
./${i}-run.sh $RELEASE $UMBREL_ROOT $UMBREL_USER
5 years ago
echo "End ${i}-run.sh"
fi
done
echo "Deleting cloned repository"
[ -d /tmp/umbrel-$RELEASE ] && rm -rf /tmp/umbrel-$RELEASE
5 years ago
# echo "Deleting update signal file"
# rm -f $UMBREL_ROOT/events/signals/update
5 years ago
echo "Removing lock"
5 years ago
rm -f $UMBREL_ROOT/statuses/update-in-progress
5 years ago
exit 0