From 31e13d1b97419ccda0d26617982fdfc0aab101e8 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Fri, 30 Aug 2024 23:31:44 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- manifest.toml | 3 +- scripts/_common.sh | 102 ++++++++++++++++++++++----------------------- scripts/backup | 36 ++++++---------- scripts/change_url | 46 ++++++++------------ scripts/install | 45 +++++++++----------- scripts/remove | 22 ++++------ scripts/restore | 58 +++++++++++--------------- scripts/upgrade | 50 ++++++++++------------ 8 files changed, 157 insertions(+), 205 deletions(-) diff --git a/manifest.toml b/manifest.toml index d8cb62a..ca7c243 100644 --- a/manifest.toml +++ b/manifest.toml @@ -18,7 +18,8 @@ code = "https://github.com/home-assistant/core" cpe = "cpe:2.3:a:home-assistant:home-assistant" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = ["amd64", "arm64"] multi_instance = false ldap = true diff --git a/scripts/_common.sh b/scripts/_common.sh index 3abbc2e..0fe683d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,7 +1,7 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= # App version @@ -24,10 +24,6 @@ py_required_version=$(curl -Ls https://www.python.org/ftp/python/ \ # Fail2ban failregex="^%(__prefix_line)s.*\[homeassistant.components.http.ban\] Login attempt or request with invalid authentication from.* \(\).* Requested URL: ./auth/.*" -#================================================= -# PERSONAL HELPERS -#================================================= - # Check if directory/file already exists (path in argument) myynh_check_path () { [ -z "$1" ] && ynh_die "No argument supplied" @@ -45,18 +41,18 @@ myynh_create_dir () { # | arg: -p, --python= - the python version to install myynh_install_python () { # Declare an array to define the options of this helper. - local legacy_args=u + #REMOVEME? local legacy_args=u local -A args_array=( [p]=python= ) local python # Manage arguments with getopts ynh_handle_getopts_args "$@" - + # Check python version from APT local py_apt_version=$(python3 --version | cut -d ' ' -f 2) - + # Usefull variables local python_major=${python%.*} - + # Check existing built version of python in /usr/local/bin if [ -e "/usr/local/bin/python$python_major" ] then @@ -65,107 +61,110 @@ myynh_install_python () { else local py_built_version=0 fi - + # Compare version if $(dpkg --compare-versions $py_apt_version ge $python) then # APT >= Required - ynh_print_info --message="Using provided python3..." - + ynh_print_info "Using provided python3..." + py_app_version="python3" - + else - # Either python already built or to build + # Either python already built or to build + if $(dpkg --compare-versions $py_built_version ge $python) then # Built >= Required - ynh_print_info --message="Using already used python3 built version..." - + ynh_print_info "Using already used python3 built version..." + py_app_version="/usr/local/bin/python${py_built_version%.*}" - + else # APT < Minimal & Actual < Minimal => Build & install Python into /usr/local/bin - ynh_print_info --message="Building python (may take a while)..." - - # Store current direcotry + ynh_print_info "Building python (may take a while)..." + + # Store current direcotry + local MY_DIR=$(pwd) - + # Create a temp direcotry tmpdir="$(mktemp --directory)" cd "$tmpdir" - + # Download wget --output-document="Python-$python.tar.xz" \ "https://www.python.org/ftp/python/$python/Python-$python.tar.xz" 2>&1 - + # Extract tar xf "Python-$python.tar.xz" - + # Install cd "Python-$python" ./configure --enable-optimizations - ynh_exec_warn_less make -j4 - ynh_exec_warn_less make altinstall - + ynh_hide_warnings make -j4 + ynh_hide_warnings make altinstall + # Go back to working directory cd "$MY_DIR" - + # Clean - ynh_secure_remove "$tmpdir" - + ynh_safe_rm "$tmpdir" + # Set version py_app_version="/usr/local/bin/python$python_major" fi fi - # Save python version in settings - ynh_app_setting_set --app=$app --key=python --value="$python" + # Save python version in settings + + ynh_app_setting_set --key=python --value="$python" } - + # Install/Upgrade Homeassistant in virtual environement myynh_install_homeassistant () { # Requirements pip_required=$(curl -Ls https://pypi.org/pypi/$app/$app_version/json | jq -r '.info.requires_dist[]' | grep 'pip') #pip (<23.1,>=21.0) # Create the virtual environment - ynh_exec_as $app $py_app_version -m venv --without-pip "$install_dir" - + ynh_exec_as_app $py_app_version -m venv --without-pip "$install_dir" + # Run source in a 'sub shell' ( # activate the virtual environment set +o nounset source "$install_dir/bin/activate" set -o nounset - + # add pip - ynh_exec_as $app "$install_dir/bin/python3" -m ensurepip - + ynh_exec_as_app "$install_dir/bin/python3" -m ensurepip + # install last version of pip - ynh_exec_warn_less ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade "$pip_required" + ynh_hide_warnings ynh_exec_as_app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade "$pip_required" # install last version of wheel - ynh_exec_warn_less ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel + ynh_hide_warnings ynh_exec_as_app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade wheel # install last version of setuptools - ynh_exec_warn_less ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade setuptools + ynh_hide_warnings ynh_exec_as_app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade setuptools # install last version of mysqlclient - ynh_exec_warn_less ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade mysqlclient - + ynh_hide_warnings ynh_exec_as_app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade mysqlclient + # install Home Assistant - ynh_exec_warn_less ynh_exec_as $app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade "$app==$app_version" + ynh_hide_warnings ynh_exec_as_app "$install_dir/bin/pip3" --cache-dir "$data_dir/.cache" install --upgrade "$app==$app_version" ) } # Upgrade the virtual environment directory myynh_upgrade_venv_directory () { - + # Remove old python links before recreating them if [ -e "$install_dir/bin/" ] then find "$install_dir/bin/" -type l -name 'python*' \ -exec bash -c 'rm --force "$1"' _ {} \; fi - + # Remove old python directories before recreating them if [ -e "$install_dir/lib/" ] then @@ -179,17 +178,16 @@ myynh_upgrade_venv_directory () { -not -path "*/python${py_required_version%.*}" \ -exec bash -c 'rm --force --recursive "$1"' _ {} \; fi - + # Upgrade the virtual environment directory - ynh_exec_as $app $py_app_version -m venv --upgrade "$install_dir" + ynh_exec_as_app $py_app_version -m venv --upgrade "$install_dir" } # Set permissions myynh_set_permissions () { - chown -R $app: "$install_dir" - chmod 750 "$install_dir" - chmod -R o-rwx "$install_dir" - + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app: "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R o-rwx "$install_dir" chown -R $app: "$data_dir" chmod 750 "$data_dir" chmod -R o-rwx "$data_dir" diff --git a/scripts/backup b/scripts/backup index 3f84707..1c12230 100644 --- a/scripts/backup +++ b/scripts/backup @@ -3,45 +3,35 @@ # yunohost backup create -n "homeassistant-test" --apps homeassistant # yunohost backup delete homeassistant-test -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= - -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # BACKUP THE DATA DIR #================================================= -ynh_backup --src_path="$data_dir" --is_big +ynh_backup "$data_dir" #================================================= # BACKUP THE NGINX CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP FAIL2BAN CONFIGURATION #================================================= -ynh_backup --src_path="/etc/fail2ban/jail.d/$app.conf" -ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" +ynh_backup "/etc/fail2ban/jail.d/$app.conf" +ynh_backup "/etc/fail2ban/filter.d/$app.conf" #================================================= # SPECIFIC BACKUP @@ -49,29 +39,29 @@ ynh_backup --src_path="/etc/fail2ban/filter.d/$app.conf" # BACKUP LOGROTATE #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/sudoers.d/$app" -ynh_backup --src_path="$(dirname "$log_file")" +ynh_backup "/etc/sudoers.d/$app" +ynh_backup "$(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_print_info "Backing up the MySQL database..." +ynh_mysql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/change_url b/scripts/change_url index d4cb65b..794c5fa 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -21,21 +15,21 @@ new_domain=$YNH_APP_NEW_DOMAIN #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." +ynh_script_progression "Loading installation settings..." -final_path=$(ynh_app_setting_get --app=$app --key=final_path) +final_path=$(ynh_app_setting_get --key=final_path) #================================================= # BACKUP BEFORE CHANGE URL THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before changing its URL (may take a while)..." +ynh_script_progression "Backing up the app before changing its URL (may take a while)..." -ynh_backup_before_upgrade -ynh_clean_setup () { - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - ynh_restore_upgradebackup +#REMOVEME? ynh_backup_before_upgrade +#REMOVEME? ynh_clean_setup () { + ynh_safe_rm "/etc/nginx/conf.d/$new_domain.d/$app.conf" + #REMOVEME? ynh_restore_upgradebackup } -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED @@ -47,19 +41,17 @@ then change_domain=1 fi -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action=stop #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating NGINX web server configuration..." +ynh_script_progression "Updating NGINX web server configuration..." nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -67,30 +59,28 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf if [ $change_domain -eq 1 ] then # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$nginx_conf_path" + ynh_delete_file_checksum "$nginx_conf_path" mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf # Store file checksum for the new config file location - ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi -#================================================= -# GENERIC FINALISATION #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name=$app --action=start --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action=start #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading NGINX web server..." +ynh_script_progression "Reloading NGINX web server..." -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --last +ynh_script_progression "Change of URL completed for $app" diff --git a/scripts/install b/scripts/install index b0810b1..cbe3bdb 100644 --- a/scripts/install +++ b/scripts/install @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -14,7 +8,7 @@ source /usr/share/yunohost/helpers #================================================= log_file="/var/log/$app/$app.log" -ynh_app_setting_set --app=$app --key=log_file --value="$log_file" +ynh_app_setting_set --key=log_file --value="$log_file" #================================================= # APP "BUILD" (DEPLOYING SOURCES, VENV, COMPILING ETC) @@ -22,14 +16,14 @@ ynh_app_setting_set --app=$app --key=log_file --value="$log_file" # CHECK PYTHON VERSION AND COMPILE IF NEEDED #================================================= -ynh_script_progression --message="Check Python version & compile the required one if needed..." --weight=1 +ynh_script_progression "Check Python version & compile the required one if needed..." myynh_install_python --python="$py_required_version" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." # create a directory for the installation of Home Assistant myynh_create_dir "$install_dir" @@ -43,33 +37,33 @@ mkdir -p "$(dirname "$log_file")" touch "$log_file" # installation in a virtual environment -ynh_script_progression --message="Installing Home Assistant in a virtual environment..." +ynh_script_progression "Installing Home Assistant in a virtual environment..." myynh_install_homeassistant #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Adding system configurations related to $app ..." --weight=1 +ynh_script_progression "Adding system configurations related to $app ..." # Create a dedicated NGINX config using the conf/nginx.conf template -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd # Create a dedicated service in YunoHost yunohost service add $app --description="Home Assistant server" --log="$log_file" # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="$log_file" +ynh_config_add_logrotate "$log_file" # Create a dedicated Fail2Ban config -ynh_add_fail2ban_config --logpath="$log_file" --failregex="$failregex" +ynh_config_add_fail2ban --logpath="$log_file" --failregex="$failregex" # Grant sudo permissions to the user to manage his own systemd service myynh_create_dir "/etc/sudoers.d" -ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" +ynh_config_add --template="sudoers" --destination="/etc/sudoers.d/$app" #================================================= # APP INITIAL CONFIGURATION @@ -77,10 +71,10 @@ ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=1 +ynh_script_progression "Adding $app's configuration..." cp -r "../conf/homeassistant_conf_files/." "$data_dir/" -ynh_add_config --template="../conf/homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml" +ynh_config_add --template="homeassistant_conf_files/configuration.yaml" --destination="$data_dir/configuration.yaml" #================================================= # SET FILE OWNERSHIP / PERMISSIONS @@ -92,19 +86,20 @@ myynh_set_permissions # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's 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 +# start systemd service with --verbose + +ynh_systemctl --service=$app --action=start --wait_until="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" +ynh_replace --match=" --verbose" --replace="" --file="/etc/systemd/system/$app.service" +ynh_store_file_checksum "/etc/systemd/system/$app.service" systemctl daemon-reload -ynh_systemd_action --service_name=$app --action=restart +ynh_systemctl --service=$app --action=restart #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index 3d9065c..cc8a18f 100644 --- a/scripts/remove +++ b/scripts/remove @@ -2,12 +2,6 @@ # to test the functionnality : # yunohost app remove homeassistant --purge -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -15,24 +9,24 @@ source /usr/share/yunohost/helpers # REMOVE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 +ynh_script_progression "Removing system configurations related to $app..." -if ynh_exec_warn_less yunohost service status $app >/dev/null ; then +if ynh_hide_warnings yunohost service status $app >/dev/null ; then yunohost service remove $app fi -ynh_remove_systemd_config +ynh_config_remove_systemd -ynh_remove_nginx_config +ynh_config_remove_nginx -ynh_remove_logrotate +ynh_config_remove_logrotate -ynh_remove_fail2ban_config +ynh_config_remove_fail2ban -ynh_secure_remove --file="/etc/sudoers.d/$app" +ynh_safe_rm "/etc/sudoers.d/$app" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 0239f74..932d451 100644 --- a/scripts/restore +++ b/scripts/restore @@ -5,12 +5,6 @@ # yunohost backup restore "homeassistant-test" # yunohost backup delete "homeassistant-test" -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -18,46 +12,46 @@ source /usr/share/yunohost/helpers # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" +ynh_script_progression "Restoring the app main directory..." +ynh_restore "$install_dir" #================================================= # RESTORE THE DATA DIRECTORY #================================================= -ynh_script_progression --message="Restoring the data directory..." -ynh_restore_file --origin_path="$data_dir" --not_mandatory +ynh_script_progression "Restoring the data directory..." +ynh_restore "$data_dir" mkdir -p $data_dir #================================================= # RESTORE THE MYSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the MySQL database..." --weight=1 -ynh_mysql_connect_as --user=$db_user --password="$db_pwd" --database=$db_name < ./db.sql +ynh_script_progression "Restoring the MySQL database..." +ynh_mysql_db_shell < ./db.sql #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" # add --verbose to track restart sed -i 's/ExecStart=.*/& --verbose/g' "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet yunohost service add $app --description="Home Assistant server" --log="$log_file" -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" -ynh_script_progression --message="Restoring the Fail2Ban configuration..." --weight=1 -ynh_restore_file --origin_path="/etc/fail2ban/jail.d/$app.conf" -ynh_restore_file --origin_path="/etc/fail2ban/filter.d/$app.conf" -ynh_systemd_action --action=restart --service_name=fail2ban +ynh_script_progression "Restoring the Fail2Ban configuration..." +ynh_restore "/etc/fail2ban/jail.d/$app.conf" +ynh_restore "/etc/fail2ban/filter.d/$app.conf" +ynh_systemctl --action=restart --service=fail2ban -ynh_restore_file --origin_path="/etc/sudoers.d/$app" -ynh_restore_file --origin_path="$(dirname "$log_file")" +ynh_restore "/etc/sudoers.d/$app" +ynh_restore "$(dirname "$log_file")" #================================================= # SPECIFIC RESTORATION @@ -65,14 +59,14 @@ ynh_restore_file --origin_path="$(dirname "$log_file")" # CHECK PYTHON VERSION AND COMPILE IF NEEDED #================================================= -ynh_script_progression --message="Restoring Python..." --weight=1 +ynh_script_progression "Restoring Python..." myynh_install_python --python="$python" #================================================= # IF NEEDED UPDATE THE PYHTON LINK IN THE VIRUTAL ENV. #================================================= -ynh_script_progression --message="Updating the pyhton link in the pyhton virtual environment..." +ynh_script_progression "Updating the pyhton link in the pyhton virtual environment..." hass_python_link=$(head -1 /var/www/homeassistant/bin/hass | sed 's/#!//') if [ ! -e "$hass_python_link" ] ; then hass_python_new_dest=$(which `basename "$hass_python_link"`) @@ -89,26 +83,24 @@ myynh_set_permissions # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's 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_systemctl --service=$app --action=start --wait_until="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" +ynh_replace --match=" --verbose" --replace="" --file="/etc/systemd/system/$app.service" +ynh_store_file_checksum "/etc/systemd/system/$app.service" systemctl daemon-reload -ynh_systemd_action --service_name=$app --action=restart +ynh_systemctl --service=$app --action=restart -#================================================= -# GENERIC FINALIZATION #================================================= # RELOAD NGINX AND PHP-FPM #================================================= -ynh_script_progression --message="Reloading NGINX web server and PHP-FPM..." -ynh_systemd_action --service_name=nginx --action=reload +ynh_script_progression "Reloading NGINX web server and PHP-FPM..." +ynh_systemctl --service=nginx --action=reload #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index d0527c2..bc9527e 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,24 +1,14 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." -ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$app.log" +ynh_script_progression "Stopping $app's systemd service..." +ynh_systemctl --service=$app --action=stop #================================================= # "REBUILD" THE APP (DEPLOY NEW SOURCES, RERUN NPM BUILD, ETC...) @@ -26,10 +16,11 @@ ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$ # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] +# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed +if ynh_app_upstream_version_changed then - ynh_script_progression --message="Upgrading source files..." - + ynh_script_progression "Upgrading source files..." + myynh_install_python --python="$py_required_version" myynh_upgrade_venv_directory myynh_install_homeassistant @@ -39,17 +30,17 @@ fi # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." -ynh_add_nginx_config +ynh_config_add_nginx -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add $app --description="Home Assistant server" --log="$log_file" -ynh_use_logrotate --logfile="$log_file" --non-append +ynh_config_add_logrotate "$log_file" -ynh_add_fail2ban_config --logpath="$log_file" --failregex="$failregex" +ynh_config_add_fail2ban --logpath="$log_file" --failregex="$failregex" #================================================= # RECONFIGURE THE APP (UPDATE CONF, APPLY MIGRATIONS, ...) @@ -57,9 +48,9 @@ ynh_add_fail2ban_config --logpath="$log_file" --failregex="$failregex" # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." +ynh_script_progression "Updating configuration..." cp -r "../conf/homeassistant_conf_files/bin/." "$data_dir/bin/" -ynh_add_config --template="../conf/sudoers" --destination="/etc/sudoers.d/$app" +ynh_config_add --template="sudoers" --destination="/etc/sudoers.d/$app" #================================================= # SET FILE OWNERSHIP / PERMISSIONS @@ -71,19 +62,20 @@ myynh_set_permissions # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." +ynh_script_progression "Starting $app's 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 +# start systemd service with --verbose + +ynh_systemctl --service=$app --action=start --wait_until="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" +ynh_replace --match=" --verbose" --replace="" --file="/etc/systemd/system/$app.service" +ynh_store_file_checksum "/etc/systemd/system/$app.service" systemctl daemon-reload -ynh_systemd_action --service_name=$app --action=restart +ynh_systemctl --service=$app --action=restart #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"