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

64 lines
1.8 KiB
Bash
Raw Normal View History

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)
2023-01-10 20:35:31 +01:00
#DEBUG=1
2022-01-08 10:04:57 +01:00
# define usefull variables
app="homeassistant"
2023-02-12 22:01:31 +01:00
install_dir="/var/www/$app"
data_dir="/home/yunohost.app/$app"
2022-01-08 10:04:57 +01:00
########## END OF CONFIGURATION ##########
########## SCRIPT CODE FOLLOWS, DON'T TOUCH! ##########
# Log messages to log file.
log() {
2023-01-10 20:35:31 +01:00
echo "$(date) $1" >> $LOG_FILE
2022-01-08 10:04:57 +01:00
}
# Reset log file.
if [ ! -z "$DEBUG" ]; then
LOG_FILE=$(cd -P -- "$(dirname -- "$0")" && pwd -P)"/upgrade_homeassistant.log"
[ -f "$LOG_FILE" ] && :> "$LOG_FILE"
fi
2022-01-20 20:55:09 +01:00
# upgrade the virtual environment
2023-02-12 22:01:31 +01:00
MY_PYTHON=$(readlink -e "$install_dir/bin/python")
2022-01-08 10:04:57 +01:00
[ ! -z "$DEBUG" ] && log "Using pyhton '$MY_PYTHON'."
2023-02-12 22:01:31 +01:00
$MY_PYTHON -m venv --upgrade "$install_dir"
2022-01-08 10:04:57 +01:00
2023-01-10 20:35:31 +01:00
# Run source in a 'sub shell'
(
# activate the virtual environment
set +o nounset
[ ! -z "$DEBUG" ] && log "Activate the virtual environment"
2023-02-12 22:01:31 +01:00
source "$install_dir/bin/activate"
2023-01-10 20:35:31 +01:00
set -o nounset
# add pip
[ ! -z "$DEBUG" ] && log "Upgrade pip"
2023-02-12 22:01:31 +01:00
"$install_dir/bin/python3" -m ensurepip --upgrade
2023-01-10 20:35:31 +01:00
local VERBOSE
[ ! -z "$DEBUG" ] && VERBOSE="--log $LOG_FILE"
2022-01-08 10:04:57 +01:00
2023-02-12 22:01:31 +01:00
# install last version of wheel, pip & mysqlclient
[ ! -z "$DEBUG" ] && log "Install latest pip version of wheel, pip & mysqlclient"
"$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel pip mysqlclient $VERBOSE
2022-01-20 20:55:09 +01:00
2023-01-10 20:35:31 +01:00
# upgrade homeassistant python package
[ ! -z "$DEBUG" ] && log "Install latest pip version of $app"
2023-02-12 22:01:31 +01:00
"$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade $app $VERBOSE
2023-01-10 20:35:31 +01:00
)
2022-01-08 10:04:57 +01:00
# restart homeassistant systemd service
2023-01-10 20:35:31 +01:00
[ ! -z "$DEBUG" ] && log "Restart $app systemd service"
2022-01-08 10:04:57 +01:00
sudo systemctl restart $app.service
exit 0