diff --git a/check_process b/check_process index d34ff26..52d2af2 100644 --- a/check_process +++ b/check_process @@ -7,14 +7,14 @@ setup_sub_dir=0 setup_root=1 setup_nourl=0 - setup_private=0 - setup_public=0 - upgrade=0 - upgrade=0 from_commit=4eaade48e9bdccf56a53f09a269b2e5ba7621296 + setup_private=1 + setup_public=1 + upgrade=1 + upgrade=1 from_commit=4eaade48e9bdccf56a53f09a269b2e5ba7621296 backup_restore=1 multi_instance=0 - port_already_use=0 - change_url=0 + port_already_use=1 + change_url=1 ;;; Options Notification=all ;;; Upgrade options diff --git a/scripts/_common.sh b/scripts/_common.sh index 82b1c02..0f67779 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,25 +1,31 @@ -# -# Common variables & functions -# +#!/bin/bash + +#================================================= +# COMMON VARIABLES +#================================================= # Release to install -VERSION=2021.12.8 +app_version=2021.12.8 # 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 libturbojpeg0 libmariadbclient-dev libmariadb-dev-compat" +pkg_dependencies="python3 python3-dev python3-venv python3-pip libffi-dev libssl-dev libjpeg-dev zlib1g-dev autoconf build-essential libopenjp2-7 libtiff5 libturbojpeg0 libmariadbclient-dev libmariadb-dev-compat" # Requirements (Major.Minor.Patch) # PY_VERSION=$(curl -s "https://www.python.org/ftp/python/" | grep ">3.9" | tail -n1 | cut -d '/' -f 2 | cut -d '>' -f 2) # Pyhton 3.9.2 will be shiped with bullseye -PY_REQUIRED_VERSION=3.9.2 +py_required_version=3.9.2 + +#================================================= +# PERSONAL HELPERS +#================================================= # Create homeassistant user mynh_system_user_create () { - USER_GROUPS="" - [ $(getent group dialout) ] && USER_GROUPS="${USER_GROUPS} dialout" - [ $(getent group gpio) ] && USER_GROUPS="${USER_GROUPS} gpio" - [ $(getent group i2c) ] && USER_GROUPS="${USER_GROUPS} i2c" - ynh_system_user_create --username="$app" --groups="$USER_GROUPS" --home_dir="$data_path" + user_groups="" + [ $(getent group dialout) ] && user_groups="${user_groups} dialout" + [ $(getent group gpio) ] && user_groups="${user_groups} gpio" + [ $(getent group i2c) ] && user_groups="${user_groups} i2c" + ynh_system_user_create --username=$app --groups="$user_groups" --home_dir="$data_path" } @@ -41,34 +47,40 @@ myynh_version_compare () { # 0 -> A = B # 1 -> A > B # 2 -> A < B - if [[ $1 == $2 ]] ; then + if [[ $1 == $2 ]] + then echo 0; return fi local IFS=. local i ver1=($1) ver2=($2) # fill empty fields in ver1 with zeros - for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) ; do + for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) + do ver1[i]=0 done - for ((i=0; i<${#ver1[@]}; i++)) ; do - if [[ -z ${ver2[i]} ]] ; then + for ((i=0; i<${#ver1[@]}; i++)) + do + if [[ -z ${ver2[i]} ]] + then # fill empty fields in ver2 with zeros ver2[i]=0 fi - if ((10#${ver1[i]} > 10#${ver2[i]})) ; then + if ((10#${ver1[i]} > 10#${ver2[i]})) + then echo 1; return fi - if ((10#${ver1[i]} < 10#${ver2[i]})) ; then + if ((10#${ver1[i]} < 10#${ver2[i]})) + then echo 2; return fi done echo 1; return } -# Package dependencies -# usage: myynh_install_dependencies --python="3.8.6" +# Install specific python version +# usage: myynh_install_python --python="3.8.6" # | arg: -p, --python= - the python version to install -myynh_install_dependencies () { +myynh_install_python () { # Declare an array to define the options of this helper. local legacy_args=u local -A args_array=( [p]=python= ) @@ -76,14 +88,12 @@ myynh_install_dependencies () { # Manage arguments with getopts ynh_handle_getopts_args "$@" - # Install main dependencies from apt - ynh_install_app_dependencies "${PKG_DEPENDENCIES}" - # Check python version from APT local PY_APT_VERSION=$(python3 --version | cut -d ' ' -f 2) # Check existing built version of python in /usr/local/bin - if [ -e "/usr/local/bin/python${python:0:3}" ]; then + if [ -e "/usr/local/bin/python${python:0:3}" ] + then local PY_BUILT_VERSION=$(/usr/local/bin/python${python:0:3} --version \ | cut -d ' ' -f 2) else @@ -91,20 +101,27 @@ myynh_install_dependencies () { fi # Compare version - if [ $(myynh_version_compare $PY_APT_VERSION $python) -le 1 ]; then + if [ $(myynh_version_compare $PY_APT_VERSION $python) -le 1 ] + then # APT >= Required ynh_print_info --message="Using provided python3..." + MY_PYTHON="python3" + else # Either python already built or to build - if [ $(myynh_version_compare $PY_BUILT_VERSION $python) -le 1 ]; then + if [ $(myynh_version_compare $PY_BUILT_VERSION $python) -le 1 ] + then # Built >= Required ynh_print_info --message="Using already used python3 built version..." + MY_PYTHON="/usr/local/bin/python${PY_BUILT_VERSION:0:3}" + else ynh_print_info --message="Installing additional dependencies to build python..." - PKG_DEPENDENCIES="${PKG_DEPENDENCIES} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar" - ynh_install_app_dependencies "${PKG_DEPENDENCIES}" + + pkg_dependencies="${pkg_dependencies} tk-dev libncurses5-dev libncursesw5-dev libreadline6-dev libdb5.3-dev libgdbm-dev libsqlite3-dev libbz2-dev libexpat1-dev liblzma-dev wget tar" + ynh_install_app_dependencies "${pkg_dependencies}" # APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin ynh_print_info --message="Building python (may take a while)..." # Store current direcotry @@ -130,7 +147,7 @@ myynh_install_dependencies () { fi fi # Save python version in settings - ynh_app_setting_set --app="$app" --key=python --value="$python" + ynh_app_setting_set --app=$app --key=python --value="$python" } # Install/Upgrade Homeassistant in virtual environement @@ -145,7 +162,7 @@ myynh_install_homeassistant () { && echo 'install last version of mysqlclient' \ && pip --cache-dir "$data_path/.cache" install --upgrade mysqlclient \ && echo 'install Home Assistant' \ - && pip --cache-dir "$data_path/.cache" install --upgrade $app==$VERSION \ + && pip --cache-dir "$data_path/.cache" install --upgrade $app==$app_version \ " } diff --git a/scripts/backup b/scripts/backup index fcbb6d0..81e7a0e 100644 --- a/scripts/backup +++ b/scripts/backup @@ -25,14 +25,14 @@ ynh_print_info --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -port=$(ynh_app_setting_get --app="$app" --key=port) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -data_path=$(ynh_app_setting_get --app="$app" --key=data_path) -log_file=$(ynh_app_setting_get --app="$app" --key=log_file) -path_url=$(ynh_app_setting_get --app="$app" --key=path_url) -python=$(ynh_app_setting_get --app="$app" --key=python) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) +log_file=$(ynh_app_setting_get --app=$app --key=log_file) +path_url=$(ynh_app_setting_get --app=$app --key=path_url) +python=$(ynh_app_setting_get --app=$app --key=python) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) #================================================= # DECLARE DATA AND CONF FILES TO BACKUP @@ -83,7 +83,7 @@ ynh_backup --src_path="$(dirname "$log_file")" # BACKUP THE MYSQL DATABASE #================================================= ynh_print_info --message="Backing up the MySQL database..." -ynh_mysql_dump_db --database="$db_name" > db.sql +ynh_mysql_dump_db --database=$db_name > db.sql #================================================= # END OF SCRIPT diff --git a/scripts/change_url b/scripts/change_url index fd09911..d4cb65b 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -23,7 +23,7 @@ new_domain=$YNH_APP_NEW_DOMAIN #================================================= ynh_script_progression --message="Loading installation settings..." -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP @@ -54,7 +54,7 @@ fi #================================================= ynh_script_progression --message="Stopping a systemd service..." -ynh_systemd_action --service_name="$app" --action=stop --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" #================================================= # MODIFY URL IN NGINX CONF @@ -80,7 +80,7 @@ fi #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app" --action=start --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action=start --log_path="/var/log/$app/$app.log" #================================================= # RELOAD NGINX diff --git a/scripts/install b/scripts/install index bd0d117..bcaf8c3 100644 --- a/scripts/install +++ b/scripts/install @@ -42,17 +42,17 @@ path_url="/" ynh_script_progression --message="Validating installation parameters..." [ ! -d "$final_path" ] || ynh_die --message="There is already a directory: $final_path " -ynh_webpath_register --app="$app" --domain="$domain" --path_url="$path_url" +ynh_webpath_register --app=$app --domain="$domain" --path_url="$path_url" #================================================= # STORE SETTINGS FROM MANIFEST #================================================= ynh_script_progression --message="Storing installation settings..." -ynh_app_setting_set --app="$app" --key=domain --value="$domain" -ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" -ynh_app_setting_set --app="$app" --key=data_path --value="$data_path" -ynh_app_setting_set --app="$app" --key=log_file --value="$log_file" -ynh_app_setting_set --app="$app" --key=path_url --value="$path_url" +ynh_app_setting_set --app=$app --key=domain --value="$domain" +ynh_app_setting_set --app=$app --key=final_path --value="$final_path" +ynh_app_setting_set --app=$app --key=data_path --value="$data_path" +ynh_app_setting_set --app=$app --key=log_file --value="$log_file" +ynh_app_setting_set --app=$app --key=path_url --value="$path_url" #================================================= # STANDARD MODIFICATIONS @@ -62,14 +62,15 @@ ynh_app_setting_set --app="$app" --key=path_url --value="$path_url" ynh_script_progression --message="Finding an available port..." port=$(ynh_find_port 8123) -ynh_app_setting_set --app="$app" --key=port --value="$port" +ynh_app_setting_set --app=$app --key=port --value="$port" #================================================= # INSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Installing dependencies..." -myynh_install_dependencies --python="$PY_REQUIRED_VERSION" +ynh_install_app_dependencies $pkg_dependencies +myynh_install_python --python="$py_required_version" #================================================= # CREATE DEDICATED USER @@ -83,10 +84,10 @@ mynh_system_user_create #================================================= ynh_script_progression --message="Creating a MySQL database..." -db_name=$(ynh_sanitize_dbid --db_name="$app") -db_user="$db_name" -ynh_app_setting_set --app="$app" --key=db_name --value="$db_name" -ynh_mysql_setup_db --db_user="$db_user" --db_name="$db_name" +db_name=$(ynh_sanitize_dbid --db_name=$app) +db_user=$db_name +ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -95,11 +96,11 @@ ynh_script_progression --message="Setting up source files..." # create a directory for the installation of Home Assistant myynh_create_dir "$final_path" -chown -R "$app": "$final_path" +chown -R $app: "$final_path" # create a directory for the datas of Home Assistant myynh_create_dir "$data_path/.cache" -chown -R "$app": "$data_path" +chown -R $app: "$data_path" # installation in a virtual environment ynh_script_progression --message="Installing Home Assistant in a virtual environment..." @@ -157,7 +158,7 @@ myynh_set_permissions ynh_script_progression --message="Integrating service in YunoHost..." # add service in admin panel -yunohost service add "$app" --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port +yunohost service add $app --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port #================================================= # START SYSTEMD SERVICE @@ -165,13 +166,13 @@ yunohost service add "$app" --description="Home Assistant server" --log="$log_fi ynh_script_progression --message="Starting a systemd service..." # start systemd service with --verbose -ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600 +ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600 # remove --verbose from systemd service ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service" ynh_store_file_checksum --file="/etc/systemd/system/$app.service" systemctl daemon-reload -ynh_systemd_action --service_name="$app" --action=restart +ynh_systemd_action --service_name=$app --action=restart #================================================= # SETUP SSOWAT diff --git a/scripts/remove b/scripts/remove index 1d765b0..fdaccca 100644 --- a/scripts/remove +++ b/scripts/remove @@ -18,15 +18,15 @@ ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -port=$(ynh_app_setting_get --app="$app" --key=port) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -data_path=$(ynh_app_setting_get --app="$app" --key=data_path) -log_file=$(ynh_app_setting_get --app="$app" --key=log_file) -path_url=$(ynh_app_setting_get --app="$app" --key=path_url) -python=$(ynh_app_setting_get --app="$app" --key=python) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) -db_user="$db_name" +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) +log_file=$(ynh_app_setting_get --app=$app --key=log_file) +path_url=$(ynh_app_setting_get --app=$app --key=path_url) +python=$(ynh_app_setting_get --app=$app --key=python) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # STANDARD REMOVE @@ -34,9 +34,9 @@ db_user="$db_name" # REMOVE SERVICE INTEGRATION IN YUNOHOST #================================================= -if ynh_exec_warn_less yunohost service status "$app" >/dev/null ; then +if ynh_exec_warn_less yunohost service status $app >/dev/null ; then ynh_script_progression --message="Removing $app service integration..." - yunohost service remove "$app" + yunohost service remove $app fi #================================================= @@ -44,7 +44,7 @@ fi #================================================= ynh_script_progression --message="Stopping and removing the systemd service..." -ynh_remove_systemd_config --service="$app" +ynh_remove_systemd_config --service=$app #================================================= # REMOVE LOGROTATE CONFIGURATION @@ -58,7 +58,7 @@ ynh_remove_logrotate #================================================= ynh_script_progression --message="Removing the MySQL database..." -ynh_mysql_remove_db --db_user="$db_user" --db_name="$db_name" +ynh_mysql_remove_db --db_user=$db_user --db_name=$db_name #================================================= # REMOVE APP MAIN DIR @@ -121,7 +121,7 @@ ynh_secure_remove --file="$(dirname "$log_file")" #================================================= ynh_script_progression --message="Removing the dedicated system user..." -ynh_system_user_delete --username="$app" +ynh_system_user_delete --username=$app #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index 9dd04c3..b9cd252 100644 --- a/scripts/restore +++ b/scripts/restore @@ -30,15 +30,15 @@ ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -port=$(ynh_app_setting_get --app="$app" --key=port) -final_path=$(ynh_app_setting_get --app="$app" --key=final_path) -data_path=$(ynh_app_setting_get --app="$app" --key=data_path) -log_file=$(ynh_app_setting_get --app="$app" --key=log_file) -path_url=$(ynh_app_setting_get --app="$app" --key=path_url) -python=$(ynh_app_setting_get --app="$app" --key=python) -db_name=$(ynh_app_setting_get --app="$app" --key=db_name) -db_user="$db_name" +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) +final_path=$(ynh_app_setting_get --app=$app --key=final_path) +data_path=$(ynh_app_setting_get --app=$app --key=data_path) +log_file=$(ynh_app_setting_get --app=$app --key=log_file) +path_url=$(ynh_app_setting_get --app=$app --key=path_url) +python=$(ynh_app_setting_get --app=$app --key=python) +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name #================================================= # CHECK IF THE APP CAN BE RESTORED @@ -86,16 +86,17 @@ mkdir -p $data_path #================================================= ynh_script_progression --message="Reinstalling dependencies..." -myynh_install_dependencies --python="$python" +ynh_install_app_dependencies $pkg_dependencies +myynh_install_python --python="$python" #================================================= # RESTORE THE MYSQL DATABASE #================================================= ynh_script_progression --message="Restoring the MySQL database..." -db_pwd=$(ynh_app_setting_get --app="$app" --key=mysqlpwd) -ynh_mysql_setup_db --db_user="$db_user" --db_name="$db_name" --db_pwd="$db_pwd" -ynh_mysql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql +db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) +ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd="$db_pwd" +ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql #================================================= # RESTORE VARIOUS FILES @@ -112,7 +113,7 @@ ynh_restore_file --origin_path="$(dirname "$log_file")" ynh_script_progression --message="Restoring the systemd configuration..." ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable "$app".service --quiet +systemctl enable $app.service --quiet #================================================= # RESTORE THE LOGROTATE CONFIGURATION @@ -132,14 +133,14 @@ myynh_set_permissions #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add "$app" --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port +yunohost service add $app --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." -ynh_systemd_action --service_name="$app" --action=start +ynh_systemd_action --service_name=$app --action=start #================================================= # GENERIC FINALIZATION @@ -155,12 +156,3 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= ynh_script_progression --message="Restoration completed for $app" --last - -#for debug purpose -for ((i = 1 ; i <= 10 ; i++)); do - ynh_print_warn --message= "\r$i) $(date)" - ynh_local_curl - #curl --silent --show-error --insecure --location --header "Host: $domain" --resolve "$domain":443:127.0.0.1 "https://localhost/" - echo -e -n "\r" - sleep 10 -done diff --git a/scripts/upgrade b/scripts/upgrade index f2d2fb0..8c58784 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,8 +16,8 @@ ynh_script_progression --message="Loading installation settings..." app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app="$app" --key=domain) -port=$(ynh_app_setting_get --app="$app" --key=port) +domain=$(ynh_app_setting_get --app=$app --key=domain) +port=$(ynh_app_setting_get --app=$app --key=port) #================================================= # CHECK VERSION @@ -43,7 +43,7 @@ ynh_abort_if_errors #================================================= ynh_script_progression --message="Stopping a systemd service..." -ynh_systemd_action --service_name="$app" --action=stop --log_path="/var/log/$app/$app.log" +ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" #================================================= # ENSURE DOWNWARD COMPATIBILITY @@ -51,59 +51,67 @@ ynh_systemd_action --service_name="$app" --action=stop --log_path="/var/log/$app ynh_script_progression --message="Ensuring downward compatibility..." # changes introduce in -if [ -z $(ynh_app_setting_get --app="$app" --key=final_path) ]; then +if [ -z $(ynh_app_setting_get --app=$app --key=final_path) ] +then final_path="/var/www/$app" data_path="/home/yunohost.app/$app" log_file="/var/log/$app/$app.log" path_url="/" - ynh_app_setting_set --app="$app" --key=final_path --value="$final_path" - ynh_app_setting_set --app="$app" --key=data_path --value="$data_path" - ynh_app_setting_set --app="$app" --key=log_file --value="$log_file" - ynh_app_setting_set --app="$app" --key=path_url --value="$path_url" + ynh_app_setting_set --app=$app --key=final_path --value="$final_path" + ynh_app_setting_set --app=$app --key=data_path --value="$data_path" + ynh_app_setting_set --app=$app --key=log_file --value="$log_file" + ynh_app_setting_set --app=$app --key=path_url --value="$path_url" else - final_path=$(ynh_app_setting_get --app="$app" --key=final_path) - data_path=$(ynh_app_setting_get --app="$app" --key=data_path) - log_file=$(ynh_app_setting_get --app="$app" --key=log_file) - path_url=$(ynh_app_setting_get --app="$app" --key=path_url) - python=$(ynh_app_setting_get --app="$app" --key=python) + final_path=$(ynh_app_setting_get --app=$app --key=final_path) + data_path=$(ynh_app_setting_get --app=$app --key=data_path) + log_file=$(ynh_app_setting_get --app=$app --key=log_file) + path_url=$(ynh_app_setting_get --app=$app --key=path_url) + python=$(ynh_app_setting_get --app=$app --key=python) fi # changes introduced in 2021.11.5~ynh1 -if [ -f "/etc/systemd/system/$app@$app.service" ]; then +if [ -f "/etc/systemd/system/$app@$app.service" ] +then # remove old systemd service - if ynh_exec_warn_less yunohost service status "$app@$app" >/dev/null ; then + if ynh_exec_warn_less yunohost service status "$app@$app" >/dev/null + then yunohost service remove "$app@$app" fi ynh_remove_systemd_config --service="$app@$app" fi -if [ ! -d "$final_path" ]; then +if [ ! -d "$final_path" ] +then # move $final_path to new directory mv "/opt/yunohost/$app" "$final_path" - chown -R "$app": "$final_path" + chown -R $app: "$final_path" fi -if [ ! -d "$data_path" ]; then +if [ ! -d "$data_path" ] +then # move $data_path to new directory mv "/""home""/$app" "$data_path" find "$data_path/.$app" -maxdepth 1 -mindepth 1 -exec mv {} "$data_path" \; rmdir "$data_path/.$app" ynh_replace_string --match_string="/home/homeassistant/.homeassistant" --replace_string="$data_path" --target_file="$data_path/configuration.yaml" - chown -R "$app": "$data_path" + chown -R $app: "$data_path" fi -if [ ! -f "$log_file" ]; then +if [ ! -f "$log_file" ] +then # create a directory with its log file myynh_create_dir "$(dirname "$log_file")" touch "$log_file" fi # changes introduced in 2021.12.8~ynh1 -if [ -z $(ynh_app_setting_get --app="$app" --key=db_name) ]; then +if [ -z $(ynh_app_setting_get --app=$app --key=db_name) ] +then # create a MySQL database - db_name=$(ynh_sanitize_dbid --db_name="$app") - db_user="$db_name" - ynh_app_setting_set --app=$app --key=db_name --value="$db_name" - ynh_mysql_setup_db --db_user="$db_user" --db_name="$db_name" - db_pwd=$(ynh_app_setting_get --app="$app" --key=mysqlpwd) - if [ -z $(sed -n "/recorder:/=" configuration.yaml) ]; then + db_name=$(ynh_sanitize_dbid --db_name=$app) + db_user=$db_name + ynh_app_setting_set --app=$app --key=db_name --value=$db_name + ynh_mysql_setup_db --db_user=$db_user --db_name=$db_name + db_pwd=$(ynh_app_setting_get --app=$app --key=mysqlpwd) + if [ -z $(sed -n "/recorder:/=" "$data_path/configuration.yaml") ] + then sed -i "$ a recorder:" "$data_path/configuration.yaml" sed -i "$ a \ db_url: mysql://$db_user:$db_pwd@127.0.0.1/$db_name?unix_socket=/var/run/mysqld/mysqld.sock&charset=utf8mb4" "$data_path/configuration.yaml" else @@ -124,8 +132,9 @@ mynh_system_user_create if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Installing Home Assistant in a virtual environment..." + ynh_script_progression --message="Upgrading source files..." + myynh_install_python --python="$py_required_version" ynh_exec_fully_quiet myynh_install_homeassistant fi @@ -141,7 +150,7 @@ ynh_add_nginx_config #================================================= ynh_script_progression --message="Upgrading dependencies..." -myynh_install_dependencies --python="$PY_REQUIRED_VERSION" +ynh_install_app_dependencies $pkg_dependencies #================================================= # UPDATE A CONFIG FILE @@ -180,7 +189,7 @@ myynh_set_permissions #================================================= ynh_script_progression --message="Integrating service in YunoHost..." -yunohost service add "$app" --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port +yunohost service add $app --description="Home Assistant server" --log="$log_file" --needs_exposed_ports=$port #================================================= # START SYSTEMD SERVICE @@ -188,13 +197,13 @@ yunohost service add "$app" --description="Home Assistant server" --log="$log_fi ynh_script_progression --message="Starting a systemd service..." # start systemd service with --verbose -ynh_systemd_action --service_name="$app" --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600 +ynh_systemd_action --service_name=$app --action=start --line_match="Home Assistant initialized" --log_path="$log_file" --timeout=3600 # remove --verbose from service ynh_replace_string --match_string=" --verbose" --replace_string="" --target_file="/etc/systemd/system/$app.service" ynh_store_file_checksum --file="/etc/systemd/system/$app.service" systemctl daemon-reload -ynh_systemd_action --service_name="$app" --action=restart +ynh_systemd_action --service_name=$app --action=restart #================================================= # RELOAD NGINX