RUT Config upload automatically via USB

Hi,

I would very much appreciate, if an automatic backup upload via USB drive would be possible. We are currently handling over 150 RUTX12 and RUT955 devices which are installed in vehicles (busses to be exact) and we need to be able change the config when the device is in the workshop. No workshop technician has access to the RMS portal and so we need to involve more people than necessary. we also regularly have problems with activating the rms services (currently it is NOT possible to activate a service!!!)!

I would therefore suggest the following behavior:
When the router is started while a USB drive is connected, the router checks first for a firmware in a specified folder and if this is equal to the installed firmware, it checks for a config backup in another specified folder. If the backup is valid for the current firmware, the backup is installed.

so if both are present and need to be installed, the router reboots twice and is up to date!

suggested folder structure:
/RUT
→ /firmware
→ /config

there has been a topic about this, but this has not been answered satisfactorily:

This would very much simplify our upgrade process!

thanks!

Hello,

This is not implemented and probably will not be implemented for obvious security reasons.

But your idea could be realized with a startup script that executes the sysupgrade -r <your_file> command if your specified circumstances are met.

Kind regards,

Hi Marijus,

thanks for your quick reply and your suggestion, I will look into this. Does the sysupgrade command check for firmware and/or config compatibility?

An automatic update could be disabled by default and, when enabled, only password protected backups allowed.

Hello,

Yes, sysupgrade -r <file> does perform file validation.

2024-05-13-12-05-39-192.168.100.1 (root)

Kind regards,

Also, you mentioned having problems with RMS. What specific issues have you been facing?

Hi Marijus,

the problems with RMS seem to have been temporary. I couldn’t activate any services for at least half an hour around 10:00 (GMT+2) today but it works again now.

also I would appreciate if you could discuss my suggestion to activate an USB update with password protection with the team.

Best
Wolfgang

Hello,

We noticed that Rms as a service was experiencing some stability issues around this time. If you notice any similar prolonged issues, please contact us.

Regarding your suggestion, we’ll take it into consideration when thinking about additional feature implementation.

Kind regards,

thanks Marijus!

one more question: i’m now working on a startup script like you suggested. I would first like to check if the firmware is up to date and install a new firmware only if necessary. unfortunately I cannot find an easy solution to check if the firmware version is equal or above the .bin file which I included on the stick (which is necessary for the config file).

Is there a possibility to compare the version of the bin file and the currently installed one? currently the firmware gets installed over and over again and I don’t get as far as to install

another question: can I set the startup script via a “task” command from the RMS?

okay, so assuming that there is no firmware update necessary, the following startup script works so far for me (including a small install key check to prevent malicious use).

I created a Task in RMS to replace the file /etc/rc.local (which I found out to be the startup script) with a file with the following content:

#!/bin/sh

# Define the password and config file
INSTALL_KEY="xxx"

# Check if USB is mounted
if [ -e /mnt/sda1/RUT/installkey ]; then
    echo "installkey file found"
	# 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."
				
				while true; do
					# Check if USB is mounted
					if [ -e /mnt/sda1 ]; then
						echo "please disconnect USB drive!"
					else
						echo "Rebooting..."
						reboot
						
						exit 0
					fi
					sleep 5
				done
			else
				echo "The sysupgrade command failed."
				exit 1
			fi
		fi
		exit 0
	else
		echo "installkey is incorrect. Exiting."
		
		exit 1
	fi
else
    echo "no installkey found. Exiting update script."
    exit 1
fi

then, when plugging in a USB device with the following file structure, the config update is performed. After unplugging the USB device another reboot is performed to ensure it’s not installed over and over.

File structure:

/RUT/installkey # a file with the installkey which needs to be replaced in the script above
/RUT/config.tar.gz # the config file which will be installed

Note: this assumes that the usb drive is automatically mounted to /mnt/sda1 which is usually the case.

The easiest solution I can think of checking firmware version is to have the .bin file named to the version and compare it to contents of /etc/version. Not sure of any other way as you have to somehow extract the .bin and find the version in there.

Hello,

Nice work, @silentdrummer! Just some pointers for a script:

*The script checks if /mnt/sda1/RUT/installkey exists, but it doesn’t ensure that /mnt/sda1 itself is mounted. It’s a good practice to check if the mount point exists and is accessible before accessing files within it. If /mnt/sda1 is not mounted, attempting to access files within it will result in errors, potentially causing unexpected behavior or failure of the script.

*The script waits indefinitely for the USB drive to be disconnected before rebooting. It might be worth adding a timeout mechanism to avoid indefinite waiting.

And as @pwsh stated, etc/version is the best location to get the current firmware version.

Kind regards,

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

1 Like

This topic was automatically closed 40 hours after the last reply. New replies are no longer allowed.