2022-01-08 10:04:57 +01:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# upgrade_homeassistant.sh - Simple shell script to upgrade homeassistant installed in a python environnement
|
|
|
|
#
|
|
|
|
|
|
|
|
# Uncomment to enable debugging to stderr (prints full client output and more)
|
|
|
|
DEBUG=0
|
|
|
|
|
|
|
|
# define usefull variables
|
|
|
|
app="homeassistant"
|
|
|
|
final_path="/var/www/$app"
|
|
|
|
data_path="/home/yunohost.app/$app"
|
|
|
|
|
|
|
|
########## END OF CONFIGURATION ##########
|
|
|
|
|
|
|
|
|
|
|
|
########## SCRIPT CODE FOLLOWS, DON'T TOUCH! ##########
|
|
|
|
|
|
|
|
# Log messages to log file.
|
|
|
|
log() {
|
|
|
|
echo "$(date)\t$1" >> $LOG_FILE
|
|
|
|
}
|
|
|
|
|
|
|
|
has_sudo() {
|
|
|
|
local prompt
|
|
|
|
prompt=$(sudo -nv 2>&1)
|
|
|
|
if [ $? -eq 0 ]; then
|
|
|
|
echo "has sudo pass set"
|
|
|
|
elif echo $prompt | grep -q '^sudo:'; then
|
|
|
|
echo "has sudo needs pass"
|
|
|
|
else
|
|
|
|
echo "can't sudo"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# Reset log file.
|
|
|
|
if [ ! -z "$DEBUG" ]; then
|
|
|
|
LOG_FILE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)"/upgrade_homeassistant.log"
|
|
|
|
[ -f "$LOG_FILE" ] && :> "$LOG_FILE"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check User and permissions
|
|
|
|
[ ! -z "$DEBUG" ] && log "User '$(whoami)' is running that script and '$(has_sudo)'."
|
|
|
|
|
2022-01-20 20:55:09 +01:00
|
|
|
# upgrade the virtual environment
|
2022-01-08 10:04:57 +01:00
|
|
|
MY_PYTHON=$(readlink -e "$final_path/bin/python")
|
|
|
|
[ ! -z "$DEBUG" ] && log "Using pyhton '$MY_PYTHON'."
|
2022-01-20 20:55:09 +01:00
|
|
|
$MY_PYTHON -m venv --upgrade "$final_path"
|
2022-01-08 10:04:57 +01:00
|
|
|
|
|
|
|
# activate the virtual environment
|
|
|
|
source "$final_path/bin/activate"
|
|
|
|
|
|
|
|
# install last version of wheel
|
|
|
|
pip --cache-dir "$data_path/.cache" install --upgrade wheel
|
|
|
|
|
2022-01-20 20:55:09 +01:00
|
|
|
# install last version of mysqlclient
|
|
|
|
pip --cache-dir "$data_path/.cache" install --upgrade mysqlclient
|
|
|
|
|
2022-01-08 10:04:57 +01:00
|
|
|
# upgrade homeassistant python package
|
|
|
|
pip --cache-dir "$data_path/.cache" install --upgrade $app
|
|
|
|
|
|
|
|
# restart homeassistant systemd service
|
|
|
|
sudo systemctl restart $app.service
|
2022-03-07 20:34:31 +01:00
|
|
|
[ ! -z "$DEBUG" ] && log "Last $app service start : $(sudo systemctl status $app.service | grep Started | tail -1)"
|
2022-01-08 10:04:57 +01:00
|
|
|
|
|
|
|
exit 0
|