mynode/rootfs/standard/usr/bin/mynode_upgrade.sh

76 lines
1.9 KiB
Bash
Raw Normal View History

2019-06-15 23:02:44 +00:00
#!/bin/bash
set -x
#set -e
source /usr/share/mynode/mynode_config.sh
2020-02-24 01:39:40 +00:00
BETA=0
while test $# -gt 0
do
case "$1" in
beta) echo "Installing a beta..."
2020-02-24 01:39:40 +00:00
BETA=1
;;
*) echo "Unknown Argument: $1"
exit 1
;;
esac
shift
done
2019-06-15 23:02:44 +00:00
# Setup
2020-01-26 04:57:43 +00:00
rm -rf /opt/mynode_release_latest.tar.gz
rm -rf /opt/mynode_release.pub
rm -rf /opt/upgrade/
mkdir -p /opt/upgrade/
2019-11-05 02:16:55 +00:00
mkdir -p /home/admin/upgrade_logs/
2019-06-15 23:02:44 +00:00
# Download Latest
2020-02-24 01:39:40 +00:00
if [ $BETA = 0 ]; then
torify wget $UPGRADE_DOWNLOAD_URL -O /opt/mynode_release_latest.tar.gz
torify wget $UPGRADE_DOWNLOAD_SIGNATURE_URL -O /opt/mynode_release_latest.sha256
2020-02-24 01:39:40 +00:00
else
torify wget $UPGRADE_BETA_DOWNLOAD_URL -O /opt/mynode_release_latest.tar.gz
torify wget $UPGRADE_BETA_DOWNLOAD_SIGNATURE_URL -O /opt/mynode_release_latest.sha256
2020-02-24 01:39:40 +00:00
fi
torify wget $UPGRADE_PUBKEY_URL -O /opt/mynode_release.pub
2019-06-15 23:02:44 +00:00
2020-01-26 04:57:43 +00:00
openssl dgst -sha256 -verify /opt/mynode_release.pub -signature /opt/mynode_release_latest.sha256 /opt/mynode_release_latest.tar.gz
2019-06-15 23:02:44 +00:00
if [ $? -ne 0 ]; then
echo "UPGRADE FAILED! Hash did not match!" >> /var/log/upgrade.log
exit 1
fi
# Clear beta install marking
rm -f /usr/share/mynode/beta_version
2019-06-15 23:02:44 +00:00
# Extract to temp location
2020-01-26 04:57:43 +00:00
tar -xvf /opt/mynode_release_latest.tar.gz -C /opt/upgrade/
2019-06-15 23:02:44 +00:00
# Install files
2020-01-26 04:57:43 +00:00
VERSION=$(cat /opt/upgrade/out/rootfs_*/usr/share/mynode/version)
if [ $IS_X86 = 1 ]; then
rsync -r -K /opt/upgrade/out/rootfs_${DEVICE_TYPE}/* / 2>&1
else
2020-01-26 17:46:45 +00:00
cp -rf /opt/upgrade/out/rootfs_${DEVICE_TYPE}/* / 2>&1
2020-01-26 04:57:43 +00:00
fi
2019-06-15 23:02:44 +00:00
sleep 1
sync
sleep 1
# Run post upgrade script
VERSION=$(cat /usr/share/mynode/version)
2019-11-16 20:46:00 +00:00
touch $UPGRADE_ERROR_FILE
for i in {1..5}
do
/bin/bash /usr/bin/mynode_post_upgrade.sh > /home/admin/upgrade_logs/upgrade_log_${VERSION}_post_${i}.txt 2>&1
RC=$?
if [ "${RC}" -eq "0" ]; then
2019-11-16 20:46:00 +00:00
rm -f $UPGRADE_ERROR_FILE
break
fi
sleep 10s
done
2019-11-16 20:46:00 +00:00
chown -R admin:admin /home/admin/upgrade_logs
sync