From 358878e708eda6fbb6deefd9f21f660a2fcc64ea Mon Sep 17 00:00:00 2001 From: Sylvain Date: Mon, 16 Sep 2024 09:49:25 +0200 Subject: [PATCH 1/2] Move to helpers 2.1 --- manifest.toml | 3 +- scripts/_common.sh | 99 +++++++++++++++++++++++----------------------- scripts/backup | 36 ++++++----------- scripts/change_url | 79 ++++-------------------------------- scripts/install | 46 ++++++++++----------- scripts/remove | 24 +++++------ scripts/restore | 65 ++++++++++++++---------------- scripts/upgrade | 58 +++++++++++---------------- 8 files changed, 153 insertions(+), 257 deletions(-) diff --git a/manifest.toml b/manifest.toml index 84d5445..bc0d644 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..521d638 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,14 +1,14 @@ #!/bin/bash #================================================= -# COMMON VARIABLES +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= # App version ## yq is not a dependencie of yunohost package so tomlq command is not available ## (see https://github.com/YunoHost/yunohost/blob/dev/debian/control) app_version=$(cat ../manifest.toml 2>/dev/null \ - | grep 'version = ' | cut -d '=' -f 2 \ + | grep '^version = ' | cut -d '=' -f 2 \ | cut -d '~' -f 1 | tr -d ' "') #2024.2.5 # Python required 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" @@ -50,13 +46,13 @@ myynh_install_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,19 +178,19 @@ 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 u=rwX,g=rX,o= "$install_dir" chmod -R o-rwx "$install_dir" chown -R $app: "$data_dir" - chmod 750 "$data_dir" + chmod u=rwX,g=rX,o= "$data_dir" chmod -R o-rwx "$data_dir" [ -e "$data_dir/bin/" ] && chmod -R +x "$data_dir/bin/" 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..0769376 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,96 +1,33 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# RETRIEVE ARGUMENTS -#================================================= - -app=$YNH_APP_INSTANCE_NAME - -old_domain=$YNH_APP_OLD_DOMAIN -new_domain=$YNH_APP_NEW_DOMAIN - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." - -final_path=$(ynh_app_setting_get --app=$app --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_backup_before_upgrade -ynh_clean_setup () { - ynh_secure_remove --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" - ynh_restore_upgradebackup -} -ynh_abort_if_errors - -#================================================= -# CHECK WHICH PARTS SHOULD BE CHANGED -#================================================= - -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -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..." - -nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf +ynh_script_progression "Updating NGINX web server configuration..." -# Change the domain for NGINX -if [ $change_domain -eq 1 ] -then - # Delete file checksum for the old conf file location - ynh_delete_file_checksum --file="$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" -fi +ynh_config_change_url_nginx -#================================================= -# 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" - -#================================================= -# RELOAD NGINX -#================================================= -ynh_script_progression --message="Reloading NGINX web server..." +systemctl daemon-reload -ynh_systemd_action --service_name=nginx --action=reload +ynh_systemctl --service="$app" --action="start" #================================================= # 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..6c6b33a 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" +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,19 @@ 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..da5779e 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 - yunohost service remove $app +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..efa9a45 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 -mkdir -p $data_dir +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 +ynh_systemctl --service="$app" --action="enable" -yunohost service add $app --description="Home Assistant server" --log="$log_file" +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 --service="fail2ban" --action="restart" -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,25 @@ 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..493ac02 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,30 +16,27 @@ ynh_systemd_action --service_name=$app --action=stop --log_path="/var/log/$app/$ # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - ynh_script_progression --message="Upgrading source files..." - - myynh_install_python --python="$py_required_version" - myynh_upgrade_venv_directory - myynh_install_homeassistant -fi +ynh_script_progression "Upgrading source files..." + +myynh_install_python --python="$py_required_version" +myynh_upgrade_venv_directory +myynh_install_homeassistant #================================================= # 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" +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 +44,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 +58,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 -# 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" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed" From cbe92abd44dd5950ad04b5eb7eca71aca2bf81b1 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Mon, 16 Sep 2024 07:48:31 +0000 Subject: [PATCH 2/2] Auto-update READMEs --- ALL_README.md | 1 + README_es.md | 2 +- README_nl.md | 59 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 README_nl.md diff --git a/ALL_README.md b/ALL_README.md index e3c80d2..df3708b 100644 --- a/ALL_README.md +++ b/ALL_README.md @@ -6,5 +6,6 @@ - [Lire le README en français](README_fr.md) - [Le o README en galego](README_gl.md) - [Baca README dalam bahasa bahasa Indonesia](README_id.md) +- [Lees de README in het Nederlands](README_nl.md) - [Прочитать README на русский](README_ru.md) - [阅读中文(简体)的 README](README_zh_Hans.md) diff --git a/README_es.md b/README_es.md index 088229d..078abe0 100644 --- a/README_es.md +++ b/README_es.md @@ -46,7 +46,7 @@ Home Assistant is an open source home automation that puts local control and pri ## Información para desarrolladores -Por favor enviar sus correcciones a la [`branch testing`](https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing +Por favor enviar sus correcciones a la [rama `testing`](https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing). Para probar la rama `testing`, sigue asÍ: diff --git a/README_nl.md b/README_nl.md new file mode 100644 index 0000000..66c280d --- /dev/null +++ b/README_nl.md @@ -0,0 +1,59 @@ + + +# Home Assistant voor Yunohost + +[![Integratieniveau](https://dash.yunohost.org/integration/homeassistant.svg)](https://ci-apps.yunohost.org/ci/apps/homeassistant/) ![Mate van functioneren](https://ci-apps.yunohost.org/ci/badges/homeassistant.status.svg) ![Onderhoudsstatus](https://ci-apps.yunohost.org/ci/badges/homeassistant.maintain.svg) + +[![Home Assistant met Yunohost installeren](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=homeassistant) + +*[Deze README in een andere taal lezen.](./ALL_README.md)* + +> *Met dit pakket kun je Home Assistant snel en eenvoudig op een YunoHost-server installeren.* +> *Als je nog geen YunoHost hebt, lees dan [de installatiehandleiding](https://yunohost.org/install), om te zien hoe je 'm installeert.* + +## Overzicht + +Home Assistant is an open source home automation that puts local control and privacy first. Powered by a worldwide community of tinkerers and DIY enthusiasts. Perfect to run on a Raspberry Pi or a local server. + +### Features + +- Works with over 1000 brands ; +- Powerful automations ; +- Extend your system with add-ons ; +- All your smart home data stays local ; +- Companion Mobile Apps ; +- Home Energy Management." + + +**Geleverde versie:** 2024.9.1~ynh1 + +**Demo:** + +## Schermafdrukken + +![Schermafdrukken van Home Assistant](./doc/screenshots/screenshot1.png) + +## Documentatie en bronnen + +- Officiele website van de app: +- Officiele beheerdersdocumentatie: +- Upstream app codedepot: +- YunoHost-store: +- Meld een bug: + +## Ontwikkelaarsinformatie + +Stuur je pull request alsjeblieft naar de [`testing`-branch](https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing). + +Om de `testing`-branch uit te proberen, ga als volgt te werk: + +```bash +sudo yunohost app install https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug +of +sudo yunohost app upgrade homeassistant -u https://github.com/YunoHost-Apps/homeassistant_ynh/tree/testing --debug +``` + +**Verdere informatie over app-packaging:**