I’m trying to write what I though would be a simple script to update hass, it won’t work…it doesn’t activate the virtual environment.
#!/bin/bash
cd /home/homeassistant/.homeassistant/
sudo su -s /bin/bash homeassistant
source /srv/homeassistant/bin/activate
pip3 install --upgrade homeassistant
Permissions as below:
-rwxr-xr-x 1 homeassistant nogroup 439 Mar 3 12:28 upgrade-hass.sh
It switches the user and moves to the home assistant dir bit doesn’t activate the virtual environment?
I’ve checked all my paths etc and all work in their own right from the CL?
OK, that makes absolute sense. thank you.
however, I think this may be my lack of Linux knowledge…
ive hashed out the pip --upgrade line for testing purposes for now, so when I run the script from within its directory location, as the pi user by sudo ./update.sh the script runs (minus actually upgrading) and then returns to the CL prompt, only know im logged in as user homeassistant and have moved to my home assistant dir /home/homeassistant/.homeassistant
as the script incudes the activate virtual env. id expect for the virtual environment to be active also, but it is not…should it be?
Not sure if I’m honest, the whole permissions thing is very important so it may be that because you’re running the script as sudo pi, but have then changed user to homeassistant, you don’t have the permissions as pi to activate the venv.
Realistically, you need to give permission to the user that’s going to be completing the actions, so in this case you should change to the homeassistant user first, then run the script (obviously the script would no longer need to change user). Or you should give the script permissions to run as the pi user, and in the script change user, activate the venv, perform the upgrade, deactivate the venv and exit the homeassistant user.
I think the latter is where @Tinkerer is heading with <<<EOM but I’m not familiar with that syntax.
I suspect it’s the crossing user permissions that’s causing the issue.
yes I did indeed try your approach and it also did not work.
it went through the motions of the script, but failed at the pip3 install --upgrade homeassistant step as the virtual env wasn’t activated (Im assuming)
pi@media-pi:/home/homeassistant/.homeassistant/bash_scripts $ sudo ./upgrade-hass.sh
Requirement already up-to-date: homeassistant in /srv/homeassistant/lib/python3.5/site-packages
Collecting exit
Could not find a version that satisfies the requirement exit (from versions: )
No matching distribution found for exit