valetudo
valetudo copied to clipboard
[Feature request] Update from Web UI + reboot
Hi,
I would like to suggest allowing an update of valetudo RE (only) from the web UI, somehow as an extension to just checking if there's a new version available (as already implemented). This would also require to trigger a reboot of the robot from the UI which may also be useful in other cases.
So far, I came up with a small shell script that I executed on the robot to do the update for me ~~(still misses many sanity checks)~~:
#!/bin/bash
INFO='\033[0;36m[INFO] '
ERROR='\033[0;31m[ERROR] '
NC='\033[0m' # No Color
if [[ $EUID -ne 0 ]]; then
echo -e "${ERROR}This script must be run as root.${NC}"
exit 1
fi
URL="https://github.com/rand256/valetudo/releases/latest/download/valetudo.tar.gz"
if [[ $# -eq 1 ]]; then
if [[ $1 != http?(s)://*valetudo.tar.gz ]]; then
echo -e "${ERROR}Provided URL=$1 is invalid. Using default $URL.${NC}"
else
URL=$1
fi
fi
# Test for wget:
if ! [ -x "$(command -v wget)" ]; then
read -p "wget not found (required to download the latest release)! Install? (y/n) " -n 1 -r
echo # move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
apt-get update
apt-get clean # there may not be much free disk space
apt-get install wget
apt-get clean
fi
fi
echo -e "${INFO}Stopping valetudo service... ${NC}"
service valetudo stop >/dev/null
echo -e "${INFO}Backing up old valetudo for now... ${NC}"
mkdir /mnt/data/temp_update_files
mv /usr/local/bin/valetudo /mnt/data/temp_update_files/valetudo.old
echo -e "${INFO}Downloading $URL release... ${NC}"
cd /mnt/data/temp_update_files/
error=0
if wget -q $URL; then
echo -e "${INFO}Decompressing and installing... ${NC}"
if tar -xf valetudo.tar.gz; then
mv valetudo /usr/local/bin
else
echo -e "${ERROR}Unable to decompress downloaded image (corrupted?), rolling back... ${NC}"
mv /mnt/data/temp_update_files/valetudo.old /usr/local/bin/valetudo
error=1
fi
else
echo -e "${ERROR}Unable to download latest release at $URL (you can also pass your own), rolling back... ${NC}"
mv /mnt/data/temp_update_files/valetudo.old /usr/local/bin/valetudo
error=1
fi
echo -e "${INFO}Cleaning up...${NC}"
cd ..
rm -rf /mnt/data/temp_update_files
if [[ $error -eq 0 ]]; then
read -p "Updated successfully. A reboot is required. Reboot this robot now? (y/n) " -n 1 -r
echo # move to a new line
if [[ $REPLY =~ ^[Yy]$ ]]; then
echo -e "${INFO}Rebooting in 5s, valetudo should become available again at http://$(hostname) (or http://$(hostname -I))... ${NC}"
sleep 5
reboot
else
service valetudo start
fi
else
service valetudo start
fi
This requires and therefore installs wget
but there may be a smarter way (to save the space of wget). However, you must execute this script on the robot via ssh ~~in /usr/local/bin/
~~ but I assume there's a way to do it from valetudo RE / the web UI?
(It's similar to what was asked in https://github.com/rand256/valetudo/issues/78 but my request is just wrt valetudo RE.)
What do you think about this idea? 🙈
Edit: just seen https://github.com/rand256/valetudo/issues/66 - but the main focus of this is the update capability.
Edit2: improved the script wrt. @pidator 's comment, thanks! (Patching rc.local
and hosts
files still missing though/yet.)
Edit3: just seen https://github.com/rand256/valetudo/wiki/Updating-valetudo-binary-on-2008--firmware which claims that a reboot is not necessary (but does this requires a "2008+" fw image?). Does it work on gen1 too (which I am using)? Guess, no. Is there any reliable way to distinguish between gen1 and gen2 within the script? Nonetheless and regardless of my improvements to the code, this script was initially intended to just serve as a starting point to integrate this into valetudo RE ... 🙈 @rand256 What do you think about this?
Edit4: improved script to allow an URL as command line argument (optional) to download / update to a specific version. There are also some more improvements to handling errors, rolling back and the generell cflow. Also added to start the valetudo service again (which seems sufficient).
So far, I came up with a small shell script that I executed on the robot to do the update for me ...
You should consider the following important points in your script (independently of the integration of your request in valetudo re):
- stopping valetudo first before move/delete/overwrite the binary!! this can be done (on Gen1) via
service valetudo stop
- the space on root partition is limited, therefore using
/mnt/data
for local download and unpacking location of the new binary file should be better (you can check available disk space withdf -h
) - also include the two files
hosts
andrc.local
of the/deployment/etc/
folder of this repository in your update procedure, because changes in these files are probably necessary to run valetudo without problems.
Thanks for your hints! I've revisited the script and updated my initial post. :-)
Gen2 uses other command for stopping and rebooting:
/etc/init/S11valetudo stop /etc/init/S11valetudo start
Gen2 uses other command for stopping and rebooting:
It's only on the firmware version 2008+.
- also include the two files
hosts
andrc.local
of the/deployment/etc/
folder of this repository in your update procedure, because changes in these files are probably necessary to run valetudo without problems.
I do miss to mention the important file
valetudo.conf
from deployment section also !!