diff --git a/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh b/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh index 45bd55b..5bd35f1 100755 --- a/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh +++ b/conf/homeassistant_conf_files/bin/upgrade_homeassistant.sh @@ -1,12 +1,49 @@ #!/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="/opt/yunohost/$app" -local MY_PYTHON=$(readlink -e "$final_path/bin/python") +########## 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)'." # create the virtual environment +MY_PYTHON=$(readlink -e "$final_path/bin/python") +[ ! -z "$DEBUG" ] && log "Using pyhton '$MY_PYTHON'." $MY_PYTHON -m venv "$final_path" # activate the virtual environment @@ -23,3 +60,5 @@ pip install --upgrade $app # restart homeassistant systemd service sudo systemctl restart $app@$app.service + +exit 0 diff --git a/conf/homeassistant_conf_files/configuration.yaml b/conf/homeassistant_conf_files/configuration.yaml index c92879f..924eb99 100644 --- a/conf/homeassistant_conf_files/configuration.yaml +++ b/conf/homeassistant_conf_files/configuration.yaml @@ -13,11 +13,3 @@ http: # Apply default set of integrations default_config: - -# Switches -switch: - - platform: command_line - switches: - upgrade_homeassistant: - command_on: "bash -c /home/homeassistant/.homeassistant/bin/upgrade_homeassistant.sh" - friendly_name: Upgrade Home Assistant diff --git a/manifest.json b/manifest.json index 91c707c..f3517cc 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "Home automation platform", "fr": "Plateforme domotique" }, - "version": "0.117.6~ynh1", + "version": "2021.1.5~ynh1", "url": "https://github.com/home-assistant/home-assistant", "license": "Apache-2.0", "maintainer": { diff --git a/scripts/_common.sh b/scripts/_common.sh index 4b358cd..a1ce676 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -3,7 +3,7 @@ # # Release to install -VERSION=2021.1.4 +VERSION=2021.1.5 # Package dependencies PKG_DEPENDENCIES="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5"