75 lines
1.9 KiB
Bash
Executable File
75 lines
1.9 KiB
Bash
Executable File
#!/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
|
|
|
|
# Clear /var/log tmpfs (remake necessary folders)
|
|
rm -rf /var/log/*
|
|
mkdir -p /var/log/nginx
|
|
|
|
# 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
|
|
if [ $IS_X86 = 1 ] || [ $IS_RASPI4_ARM64 = 1 ]; then
|
|
rsync -r -K /tmp/rootfs/out/rootfs_${DEVICE_TYPE}/* /
|
|
else
|
|
cp -rf /tmp/rootfs/out/rootfs_${DEVICE_TYPE}/* /
|
|
fi
|
|
systemctl daemon-reload
|
|
|
|
# Sleep and sync FS
|
|
echo "Syncing filesystem..."
|
|
sleep 1
|
|
sync
|
|
|
|
# Restart or reboot
|
|
if [ "$#" -ge 2 ]; then
|
|
# Restart service
|
|
if [ "$2" = "www" ]; then
|
|
echo "Restarting www service..."
|
|
systemctl restart www
|
|
elif [ "$2" = "files" ]; then
|
|
echo "Only updating files... Done."
|
|
elif [ "$2" = "reboot" ]; then
|
|
echo "Rebooting..."
|
|
else
|
|
# Service not found, reboot
|
|
echo "Unknown service, rebooting"
|
|
/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
|
|
if [ $? -ne 0 ]; then
|
|
echo "ERROR: Post upgrade script failed!"
|
|
exit 1
|
|
fi
|
|
reboot
|
|
fi
|