Hi Marijus,
thanks for your reply, i have adjusted the script so it checks for the timestamp of the installkey file, if this was changed within the last 5 minutes, no update is performed. after the update, the installkey file timestamp is refreshed.
that way there is no need to wait for unplugging the USB drive and no boot loop.
the neat thing is also, that it can easily be enabled or disabled with a Task in RMS by pushing the file /etc/rc.local
#!/bin/sh
# Define the password and config file
INSTALL_KEY="xxx"
KEY_FILE_PATH="/mnt/sda1/RUT/installkey"
# Check if USB is mounted
if [ ! -d /mnt/sda1 ]; then
echo "/mnt/sda1 does not exist. exiting"
exit 0
fi
if [ ! -e $KEY_FILE_PATH ]; then
echo "no installkey found. Exiting update script."
exit 0
else
echo "installkey file found"
# checking time since last update
CURRENT_TIME=$(date +%s)
FILE_TIME=$(date -r "$KEY_FILE_PATH" +%s)
DIFF_TIME=$((CURRENT_TIME - FILE_TIME))
if [ $DIFF_TIME -le 300 ]; then
echo "The sysupgrade was performed within the last 5 minutes. Exiting."
exit 0
fi
# Check if password file contains the correct password
if grep -Fxq "$INSTALL_KEY" /mnt/sda1/RUT/installkey; then
echo "installkey is correct"
# creating a backup
echo "creating backup config"
rm -f /mnt/sda1/RUT/config-backup.tar.gz
sysupgrade -b /mnt/sda1/RUT/config-backup.tar.gz
if [ -e /mnt/sda1/RUT/config.tar.gz ]; then
echo "restoring config"
sysupgrade -r /mnt/sda1/RUT/config.tar.gz
if [ $? -eq 0 ]; then
echo "The sysupgrade command was successful."
# update timestamp on the installkey file
touch "$KEY_FILE_PATH"
reboot
else
echo "The sysupgrade command failed."
exit 1
fi
fi
exit 0
else
echo "installkey is incorrect. Exiting."
exit 1
fi
fi
best
Wolfgang