mynode/rootfs/standard/usr/bin/mynode-local-upgrade

77 lines
1.9 KiB
Plaintext
Raw Normal View History

#!/bin/bash
# mynode-local-upgrade
# This script needs to be run with sudo
# It reqeusts an IP, downloads the latest rootfs, installs it, and reboots the device
set -e
source /usr/share/mynode/mynode_config.sh
# Prompt for IP
echo "Make sure your PC is running 'make start_file_server'..."
ip_address="error"
if [ "$#" -lt 1 ]; then
echo -n "Dev PC IP Address: "
read ip_address
else
ip_address="$1"
fi
2020-08-11 04:08:38 +00:00
# Clear /var/log tmpfs (remake necessary folders)
2020-04-07 17:36:30 +00:00
rm -rf /var/log/*
2020-08-11 04:08:38 +00:00
mkdir -p /var/log/nginx
2020-04-07 17:36:30 +00:00
# Delete any existing rootfs tarball and download new one
rm -f mynode_rootfs_${DEVICE_TYPE}.tar.gz
wget http://${ip_address}:8000/mynode_rootfs_${DEVICE_TYPE}.tar.gz -O /tmp/mynode_rootfs_${DEVICE_TYPE}.tar.gz --progress=bar
# Extract on top of mynode fs
rm -rf /tmp/rootfs/
mkdir -p /tmp/rootfs/
echo -n "Extracting rootfs TAR for ${DEVICE_TYPE}... "
tar -xf /tmp/mynode_rootfs_${DEVICE_TYPE}.tar.gz -C /tmp/rootfs/
echo Done!
# Install files
2022-01-17 17:29:21 +00:00
rsync -r -K /tmp/rootfs/out/rootfs_${DEVICE_TYPE}/* /
# Sleep and sync FS
echo "Syncing filesystem..."
sleep 1
sync
2022-01-17 17:29:21 +00:00
# Reload systemd files
systemctl daemon-reload
# Restart or reboot
if [ "$#" -ge 2 ]; then
# Restart service
if [ "$2" = "www" ]; then
echo "Restarting www service..."
systemctl restart www
2022-01-17 17:29:21 +00:00
elif [ "$2" = "mempool" ]; then
echo "Restarting mempool service..."
systemctl restart mempool &
elif [ "$2" = "files" ]; then
echo "Only updating files... Done."
elif [ "$2" = "reboot" ]; then
echo "Rebooting..."
else
# Service not found, reboot
echo "Unknown service, rebooting"
2019-12-19 03:45:44 +00:00
/usr/bin/mynode_stop_critical_services.sh
reboot
fi
else
# Default, full upgrade
echo "Full upgrade, running post upgrade script and rebooting device..."
/bin/bash /usr/bin/mynode_post_upgrade.sh
2019-11-21 02:02:33 +00:00
if [ $? -ne 0 ]; then
echo "ERROR: Post upgrade script failed!"
exit 1
fi
reboot
fi