HA upgrade script

I have created a .sh file where I have the steps to stop, upgrade and start Home Assistant.

#!/bin/bash
sudo systemctl stop [email protected]
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
python3 -m pip install --upgrade homeassistant
deactivate
su pi
sudo systemctl start [email protected]

I’m not a Linux guru, but I understand It’s not possible to run this as it involves changing user (and maybe the Virtual Pyton environment makes it difficult).

All steps are working if I manually enter them one by one.

I want to automate this a bit. Thanks for all advice!

//Zamb

this is my solution for your script by using cron

so first we need to create a file at /etc/cron.hourly/update_hass

and that file check if an update flag is found

kinda like this

#!/bin/bash
upgrade_log=/home/homeassistant/update.log
update_flag=/home/homeassistant/update.flag
if [ -f $update_flag ]; then
   rm $upgrade_log
   sleep 5
   systemctl stop [email protected]
   source /srv/homeassistant/bin/activate
   python3 -m pip install --upgrade homeassistant >> $upgrade_log
   deactivate
   systemctl start [email protected]
   rm $update_flag
fi

and then have this in shellscript.yaml

update_and_restart_hass_with_logging: "/bin/bash /home/homeassistant/.homeassistant/includes/scripts/shell/update_hass.sh"

and last but not least if you use custom_ui like me have that updated upon updating everything else my update_hass.sh

#!/bin/bash

update_homeassistant () {
cd /home/homeassistant/.homeassistant/
/home/homeassistant/.homeassistant/customui_updater
sleep 10
touch /home/homeassistant/update.flag
}
update_homeassistant

then you need a sensor to tell you if there is an update available

Why don’t you look at the hassbian update script, which does exactly what you are trying to do.

1 Like