From 92d64f7b9d7bb6a9bc1279de938a0b9d5d7f327c Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 02:55:33 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 3 +++ manifest.toml | 2 ++ scripts/_common.sh | 13 +++++------ scripts/backup | 25 +++++++------------- scripts/change_url | 26 +++++++-------------- scripts/install | 58 ++++++++++++++++++++++------------------------ scripts/remove | 28 +++++++++------------- scripts/restore | 50 ++++++++++++++++----------------------- scripts/upgrade | 52 ++++++++++++++++++----------------------- 9 files changed, 110 insertions(+), 147 deletions(-) diff --git a/.gitignore b/.gitignore index 08659e8..8fd2a00 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,6 @@ __pycache__ secret.txt /local_test/ +*~ +*.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 8836d2d..1f02a40 100644 --- a/manifest.toml +++ b/manifest.toml @@ -20,6 +20,7 @@ code = "https://github.com/jedie/PyInventory/" [integration] # https://yunohost.org/en/packaging_manifest#integration-section yunohost = ">=11.2.12" +helpers_version = "2.1" architectures = "all" multi_instance = true ldap = true @@ -78,6 +79,7 @@ ram.runtime = "50M" # **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, # This will provision/deprovision a unix system user [resources.install_dir] + group = "www-data:r-x" # https://yunohost.org/en/packaging_apps_resources#install-dir # This will create/remove the install dir as /var/www/$app/ # and store the corresponding setting $install_dir and template variable __INSTALL_DIR__ diff --git a/scripts/_common.sh b/scripts/_common.sh index 0c73c1b..6ded1b3 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -40,7 +40,7 @@ log_file="${log_path}/${app}.log" myynh_setup_python_venv() { # Always recreate everything fresh with current python version - ynh_secure_remove "$data_dir/venv" + ynh_safe_rm "$data_dir/venv" # Skip pip because of: https://github.com/YunoHost/issues/issues/1960 python3 -m venv --without-pip "$data_dir/venv" @@ -53,9 +53,9 @@ myynh_setup_python_venv() { source "$data_dir/venv/bin/activate" set -o nounset set -x - ynh_exec_as $app $data_dir/venv/bin/python3 -m ensurepip - ynh_exec_as $app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools - ynh_exec_as $app $data_dir/venv/bin/pip3 install --no-deps -r "$data_dir/requirements.txt" + ynh_exec_as_app $data_dir/venv/bin/python3 -m ensurepip + ynh_exec_as_app $data_dir/venv/bin/pip3 install --upgrade wheel pip setuptools + ynh_exec_as_app $data_dir/venv/bin/pip3 install --no-deps -r "$data_dir/requirements.txt" ) } @@ -76,9 +76,8 @@ myynh_fix_file_permissions() { set -x # /var/www/$app/ - chown -c -R "$app:www-data" "$install_dir" - chmod -c 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 -c -R "$app:www-data" "$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 -c o-rwx "$install_dir" # /home/yunohost.app/$app/ chown -c -R "$app:" "$data_dir" chmod -c o-rwx "$data_dir" diff --git a/scripts/backup b/scripts/backup index 97a5793..610e272 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,40 +1,31 @@ #!/bin/bash -#================================================= -# 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 #================================================= # /var/www/$app/ -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" # /home/yunohost.app/$app/ -ynh_backup --src_path="$data_dir" +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 THE PostgreSQL DATABASE #================================================= -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # SPECIFIC BACKUP @@ -42,16 +33,16 @@ ynh_psql_dump_db --database="$db_name" > db.sql # 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" #================================================= # 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 b0f3603..767330f 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -1,49 +1,41 @@ #!/bin/bash -#================================================= -# GENERIC STARTING -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -#================================================= -# STANDARD MODIFICATIONS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping systemd service '$app'..." +ynh_script_progression "Stopping systemd service '$app'..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="$log_file" +ynh_systemctl --service=$app --action="stop" --log_path="$log_file" #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." +ynh_script_progression "Updating nginx web server configuration..." -ynh_change_url_nginx_config +ynh_config_change_url_nginx #================================================= # UPDATE DJANGO SETTINGS #================================================= -ynh_script_progression --message="Update $app settings file..." --weight=1 +ynh_script_progression "Update $app settings file..." path=$new_path domain=$new_domain -ynh_add_config --template="settings.py" --destination="$data_dir/settings.py" +ynh_config_add --template="settings.py" --destination="$data_dir/settings.py" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 +ynh_script_progression "Starting systemd service '$app'..." -ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" +ynh_systemctl --service=$app --action="start" --log_path="$log_file" #================================================= # 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 ebbd375..f593a20 100755 --- a/scripts/install +++ b/scripts/install @@ -31,67 +31,67 @@ source /usr/share/yunohost/helpers #================================================= # SETTINGS #================================================= -ynh_script_progression --message="Storing installation settings..." +ynh_script_progression "Storing installation settings..." # Logging: 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" # Redis: redis_db=$(ynh_redis_get_free_db) -ynh_app_setting_set --app=$app --key=redis_db --value="$redis_db" +ynh_app_setting_set --key=redis_db --value="$redis_db" # App settings: -ynh_app_setting_set --app=$app --key=default_from_email --value="$default_from_email" -ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email" -ynh_app_setting_set --app=$app --key=debug_enabled --value="$debug_enabled" -ynh_app_setting_set --app=$app --key=log_level --value="$log_level" +ynh_app_setting_set --key=default_from_email --value="$default_from_email" +ynh_app_setting_set --key=admin_email --value="$admin_email" +ynh_app_setting_set --key=debug_enabled --value="$debug_enabled" +ynh_app_setting_set --key=log_level --value="$log_level" #================================================= # CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS #================================================= -ynh_script_progression --message="Validating installation parameters..." +ynh_script_progression "Validating installation parameters..." mkdir -p "$install_dir/media" "$install_dir/static" #================================================= # SETUP LOG FILE #================================================= -ynh_script_progression --message="Setup logging..." +ynh_script_progression "Setup logging..." myynh_setup_log_file # Use logrotate to manage application logfile(s) -ynh_use_logrotate --logfile="$log_file" --specific_user=$app +ynh_config_add_logrotate "$log_file" #================================================= # PYTHON VIRTUALENV #================================================= -ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 +ynh_script_progression "Create and setup Python virtualenv..." cp ../conf/requirements.txt "$data_dir/requirements.txt" myynh_setup_python_venv #================================================= # copy config files # ================================================ -ynh_script_progression --message="Create $app configuration files..." +ynh_script_progression "Create $app configuration files..." -ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" +ynh_config_add --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" -ynh_add_config --template="manage.py" --destination="$data_dir/manage.py" +ynh_config_add --template="manage.py" --destination="$data_dir/manage.py" chmod -c +x "$data_dir/manage.py" -ynh_add_config --template="settings.py" --destination="$data_dir/settings.py" -ynh_add_config --template="setup_user.py" --destination="$data_dir/setup_user.py" -ynh_add_config --template="urls.py" --destination="$data_dir/urls.py" -ynh_add_config --template="wsgi.py" --destination="$data_dir/wsgi.py" +ynh_config_add --template="settings.py" --destination="$data_dir/settings.py" +ynh_config_add --template="setup_user.py" --destination="$data_dir/setup_user.py" +ynh_config_add --template="urls.py" --destination="$data_dir/urls.py" +ynh_config_add --template="wsgi.py" --destination="$data_dir/wsgi.py" touch "$data_dir/local_settings.py" #================================================= # MIGRATE / COLLECTSTATIC / CREATEADMIN #================================================= -ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10 +ynh_script_progression "migrate/collectstatic/createadmin..." cd "$data_dir" || exit @@ -111,46 +111,44 @@ cd "$data_dir" || exit #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Set file permissions..." +ynh_script_progression "Set file permissions..." myynh_fix_file_permissions #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5 +ynh_script_progression "Configuring systemd service '$app'..." # https://yunohost.org/en/packaging_apps_helpers#ynh-add-systemd-config # https://github.com/YunoHost/yunohost/blob/dev/helpers/systemd -ynh_add_systemd_config --service=$app --template="systemd.service" +ynh_config_add_systemd #================================================= # Start the app server via systemd #================================================= -ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 +ynh_script_progression "Starting systemd service '$app'..." -ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" +ynh_systemctl --service=$app --action="start" --log_path="$log_file" #================================================= # NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring nginx web server..." +ynh_script_progression "Configuring nginx web server..." # Create a dedicated nginx config # https://yunohost.org/en/contribute/packaging_apps/helpers # https://github.com/YunoHost/yunohost/blob/dev/helpers/nginx -ynh_add_nginx_config "public_path" "port" +ynh_config_add_nginx "public_path" "port" #================================================= # 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 56f7a77..026149a 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers @@ -18,16 +12,16 @@ source /usr/share/yunohost/helpers # Remove a service from the admin panel, added by `yunohost service add` if yunohost service status $app >/dev/null 2>&1 then - ynh_script_progression --message="Removing $app service integration..." + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi #================================================= # STOP PYINVENTORY'S SERVICES #================================================= -ynh_script_progression --message="Stopping and removing systemd service '$app'..." --weight=5 +ynh_script_progression "Stopping and removing systemd service '$app'..." -ynh_remove_systemd_config --service=$app +ynh_config_remove_systemd ##================================================= ## REMOVE REDIS DB @@ -38,31 +32,31 @@ ynh_redis_remove_db #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." +ynh_script_progression "Removing app main directory..." # /var/www/$app/ -ynh_secure_remove --file="$install_dir" +ynh_safe_rm "$install_dir" # /home/yunohost.app/$app/ -ynh_secure_remove --file="$data_dir" +ynh_safe_rm "$data_dir" #================================================= # REMOVE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Removing nginx web server configuration..." +ynh_script_progression "Removing nginx web server configuration..." # Remove the dedicated nginx config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration..." +ynh_script_progression "Removing logrotate configuration..." # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate #================================================= # 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 77cb45c..fc50d48 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,11 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -14,84 +8,80 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE NGINX CONFIGURATION #================================================= -ynh_script_progression --message="Restoring the NGINX web server configuration..." --weight=1 +ynh_script_progression "Restoring the NGINX web server configuration..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring $app main directory..." +ynh_script_progression "Restoring $app main directory..." -ynh_restore_file --origin_path="$install_dir" -ynh_restore_file --origin_path="$data_dir" +ynh_restore "$install_dir" +ynh_restore "$data_dir" -ynh_script_progression --message="Set file permissions..." +ynh_script_progression "Set file permissions..." myynh_fix_file_permissions #================================================= # PYTHON VIRTUALENV # Maybe the backup contains a other Python version #================================================= -ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 +ynh_script_progression "Create and setup Python virtualenv..." myynh_setup_python_venv #================================================= # RESTORE THE PostgreSQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=5 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_psql_db_shell < ./db.sql #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd $app configuration..." +ynh_script_progression "Restoring the systemd $app configuration..." -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." +ynh_script_progression "Integrating service in YunoHost..." yunohost service add $app #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Setup logging..." +ynh_script_progression "Setup logging..." myynh_setup_log_file -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/etc/logrotate.d/$app" -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Set file permissions..." +ynh_script_progression "Set file permissions..." myynh_fix_file_permissions -#================================================= -# GENERIC FINALIZATION #================================================= # START PYINVENTORY #================================================= -ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 +ynh_script_progression "Starting systemd service '$app'..." -ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" +ynh_systemctl --service=$app --action="start" --log_path="$log_file" #================================================= # 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="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index 36de96b..d450cee 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,67 +12,64 @@ source /usr/share/yunohost/helpers if [ -z "$debug_enabled" ]; then debug_enabled="0" - ynh_app_setting_set --app=$app --key=debug_enabled --value="$debug_enabled" + ynh_app_setting_set --key=debug_enabled --value="$debug_enabled" fi if [ -z "$log_level" ]; then log_level="WARNING" - ynh_app_setting_set --app=$app --key=log_level --value="$log_level" + ynh_app_setting_set --key=log_level --value="$log_level" fi if [ -z "$admin_email" ]; then admin_email="${admin}@${domain}" - ynh_app_setting_set --app=$app --key=admin_email --value="$admin_email" + ynh_app_setting_set --key=admin_email --value="$admin_email" fi if [ -z "$default_from_email" ]; then default_from_email="${app}@${domain}" - ynh_app_setting_set --app=$app --key=default_from_email --value="$default_from_email" + ynh_app_setting_set --key=default_from_email --value="$default_from_email" fi -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping systemd service '$app'..." --weight=5 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="$log_file" +ynh_script_progression "Stopping systemd service '$app'..." +ynh_systemctl --service=$app --action="stop" --log_path="$log_file" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring systemd service '$app'..." --weight=5 +ynh_script_progression "Configuring systemd service '$app'..." -ynh_add_systemd_config --service=$app --template="systemd.service" +ynh_config_add_systemd #================================================= # PYTHON VIRTUALENV #================================================= -ynh_script_progression --message="Create and setup Python virtualenv..." --weight=45 +ynh_script_progression "Create and setup Python virtualenv..." cp ../conf/requirements.txt "$data_dir/requirements.txt" myynh_setup_python_venv #================================================= # copy config files # ================================================ -ynh_script_progression --message="Create project configuration files..." +ynh_script_progression "Create project configuration files..." -ynh_add_config --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" +ynh_config_add --template="gunicorn.conf.py" --destination="$data_dir/gunicorn.conf.py" -ynh_add_config --template="manage.py" --destination="$data_dir/manage.py" +ynh_config_add --template="manage.py" --destination="$data_dir/manage.py" chmod -c +x "$data_dir/manage.py" -ynh_add_config --template="settings.py" --destination="$data_dir/settings.py" -ynh_add_config --template="setup_user.py" --destination="$data_dir/setup_user.py" -ynh_add_config --template="urls.py" --destination="$data_dir/urls.py" -ynh_add_config --template="wsgi.py" --destination="$data_dir/wsgi.py" +ynh_config_add --template="settings.py" --destination="$data_dir/settings.py" +ynh_config_add --template="setup_user.py" --destination="$data_dir/setup_user.py" +ynh_config_add --template="urls.py" --destination="$data_dir/urls.py" +ynh_config_add --template="wsgi.py" --destination="$data_dir/wsgi.py" #================================================= # MIGRATE PYINVENTORY #================================================= -ynh_script_progression --message="migrate/collectstatic/createadmin..." --weight=10 +ynh_script_progression "migrate/collectstatic/createadmin..." cd "$data_dir" || exit @@ -89,33 +86,30 @@ cd "$data_dir" || exit # This may fail in some cases with errors, etc., but the app works and the user can fix issues later. ./manage.py check --deploy || true - #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." +ynh_script_progression "Upgrading logrotate configuration..." # Use logrotate to manage app-specific logfile(s) -ynh_use_logrotate --logfile="$log_file" --specific_user=$app --non-append +ynh_config_add_logrotate "$log_file" -#================================================= -# GENERIC FINALIZATION #================================================= # SECURE FILES AND DIRECTORIES #================================================= -ynh_script_progression --message="Set file permissions..." +ynh_script_progression "Set file permissions..." myynh_fix_file_permissions #================================================= # Start the app server via systemd #================================================= -ynh_script_progression --message="Starting systemd service '$app'..." --weight=5 +ynh_script_progression "Starting systemd service '$app'..." yunohost service add $app -ynh_systemd_action --service_name=$app --action="start" --log_path="$log_file" +ynh_systemctl --service=$app --action="start" --log_path="$log_file" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"