1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/homeassistant_ynh.git synced 2024-09-03 19:26:16 +02:00
homeassistant_ynh/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh

62 lines
1.5 KiB
Bash
Raw Normal View History

2019-06-09 18:30:25 +02:00
#!/bin/bash
2021-02-02 20:37:53 +01:00
#
# 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
2019-06-09 18:30:25 +02:00
# define usefull variables
app="homeassistant"
2021-12-07 17:29:01 +01:00
final_path="/var/www/$app"
2019-06-09 18:30:25 +02:00
2021-02-02 20:37:53 +01:00
########## 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)'."
2019-06-09 18:30:25 +02:00
# create the virtual environment
2021-02-02 20:37:53 +01:00
MY_PYTHON=$(readlink -e "$final_path/bin/python")
[ ! -z "$DEBUG" ] && log "Using pyhton '$MY_PYTHON'."
2020-11-14 14:10:51 +01:00
$MY_PYTHON -m venv "$final_path"
2019-06-09 18:30:25 +02:00
# activate the virtual environment
2020-11-14 14:10:51 +01:00
source "$final_path/bin/activate"
2019-06-09 18:30:25 +02:00
2020-11-14 14:10:51 +01:00
# install last version of wheel
2021-12-07 08:44:15 +01:00
pip --no-cache-dir install --upgrade wheel
2019-06-09 18:30:25 +02:00
# upgrade homeassistant python package
2021-12-07 08:44:15 +01:00
pip --no-cache-dir install --upgrade $app
2019-06-09 18:30:25 +02:00
# restart homeassistant systemd service
2021-12-07 08:44:15 +01:00
sudo systemctl restart $app.service
2021-02-02 20:37:53 +01:00
exit 0