2019-06-19 03:52:49 +00:00
|
|
|
#!/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"
|
2019-08-01 00:38:28 +00:00
|
|
|
if [ "$#" -lt 1 ]; then
|
2019-06-19 03:52:49 +00:00
|
|
|
echo -n "Dev PC IP Address: "
|
|
|
|
read ip_address
|
|
|
|
else
|
|
|
|
ip_address="$1"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# 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
|
|
|
|
|
|
|
|
# Extract on top of mynode fs
|
|
|
|
rm -rf /tmp/rootfs/
|
|
|
|
mkdir -p /tmp/rootfs/
|
|
|
|
tar -xvf /tmp/mynode_rootfs_${DEVICE_TYPE}.tar.gz -C /tmp/rootfs/
|
|
|
|
|
|
|
|
# Install files
|
|
|
|
cp -rf /tmp/rootfs/out/rootfs_${DEVICE_TYPE}/* /
|
|
|
|
systemctl daemon-reload
|
|
|
|
|
|
|
|
# Sleep and sync FS
|
2019-08-01 00:38:28 +00:00
|
|
|
echo "Syncing filesystem..."
|
2019-06-19 03:52:49 +00:00
|
|
|
sleep 1
|
|
|
|
sync
|
|
|
|
|
2019-08-01 00:38:28 +00:00
|
|
|
# Restart or reboot
|
|
|
|
if [ "$#" -ge 2 ]; then
|
|
|
|
# Restart service
|
|
|
|
if [ "$2" = "www" ]; then
|
|
|
|
echo "Restarting www service..."
|
|
|
|
systemctl restart www
|
2019-08-10 01:07:46 +00:00
|
|
|
elif [ "$2" = "files" ]; then
|
|
|
|
echo "Only updating files... Done."
|
2019-08-01 00:38:28 +00:00
|
|
|
else
|
|
|
|
# Service not found, reboot
|
2019-08-16 03:18:32 +00:00
|
|
|
echo "Service not found, doing full upgrade and rebooting device..."
|
|
|
|
/bin/bash /usr/bin/mynode_post_upgrade.sh
|
2019-08-01 00:38:28 +00:00
|
|
|
reboot
|
|
|
|
fi
|
|
|
|
else
|
|
|
|
echo "Rebooting device..."
|
|
|
|
reboot
|
|
|
|
fi
|