From cebe7c23d85ce2b27c35e445631c7493c310d889 Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Fri, 30 Aug 2024 22:44:49 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- conf/nginx.conf | 6 ++--- manifest.toml | 4 ++- scripts/_common.sh | 1 - scripts/backup | 17 +++++------- scripts/change_url | 14 +++++----- scripts/install | 56 +++++++++++++++++++--------------------- scripts/remove | 10 ++++---- scripts/restore | 35 ++++++++++++------------- scripts/upgrade | 64 ++++++++++++++++++++-------------------------- 9 files changed, 97 insertions(+), 110 deletions(-) diff --git a/conf/nginx.conf b/conf/nginx.conf index 2ee1541..89c0777 100644 --- a/conf/nginx.conf +++ b/conf/nginx.conf @@ -1,11 +1,11 @@ #sub_path_only rewrite ^__PATH__$ __PATH__/ permanent; location __PATH__/ { - try_files $uri @__NAME__; + try_files $uri @__APP__; } location __PATH__/protected/ { internal; - alias __INSTALL_DIR__/__NAME__/smedia/; + alias __INSTALL_DIR__/__APP__/smedia/; } location __PATH__/media/ { @@ -20,7 +20,7 @@ location __PATH__/assets/ { alias __INSTALL_DIR__/static/; } -location @__NAME__ { +location @__APP__ { proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; diff --git a/manifest.toml b/manifest.toml index a9b1ce9..a6772e6 100644 --- a/manifest.toml +++ b/manifest.toml @@ -17,7 +17,8 @@ website = "https://code.ffdn.org/FFDN/coin" code = "https://code.ffdn.org/ffdn/coin" [integration] -yunohost = ">= 11.2.20" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = "all" multi_instance = false ldap = false @@ -61,6 +62,7 @@ ram.runtime = "50M" allow_email = true [resources.install_dir] + group = "www-data:r-x" [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index 05a7907..a9bf588 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,2 +1 @@ #!/bin/bash - diff --git a/scripts/backup b/scripts/backup index b89e87d..c1b32c1 100644 --- a/scripts/backup +++ b/scripts/backup @@ -4,32 +4,29 @@ 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" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP THE DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_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 f990470..caff202 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -3,15 +3,15 @@ source _common.sh source /usr/share/yunohost/helpers -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="stop" -ynh_change_url_nginx_config +ynh_config_change_url_nginx -ynh_add_config --jinja --template=local.py.j2 --destination="$install_dir/coin/settings_local.py" +ynh_config_add --jinja --template=local.py.j2 --destination="$install_dir/coin/settings_local.py" -chmod 400 "$install_dir/coin/settings_local.py" -chown $app "$install_dir/coin/settings_local.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/coin/settings_local.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app "$install_dir/coin/settings_local.py" -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="start" -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 3133d5b..cf82dda 100644 --- a/scripts/install +++ b/scripts/install @@ -3,26 +3,25 @@ source _common.sh source /usr/share/yunohost/helpers -secret=$(ynh_string_random 24) -ynh_app_setting_set --app=$app --key=secret --value=$secret +secret=$(ynh_string_random --length=24) +ynh_app_setting_set --key=secret --value=$secret #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." +ynh_script_progression "Setting up source files..." ynh_setup_source --dest_dir="$install_dir" -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -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 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" +#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:www-data "$install_dir" #================================================= # SPECIFIC SETUP #================================================= # PYTHON DEPENDENCIES #================================================= -ynh_script_progression --message="Installing more dependencies..." +ynh_script_progression "Installing more dependencies..." pushd "$install_dir" python3 -m venv venv @@ -35,49 +34,48 @@ popd #================================================= # CONFIGURATION DJANGO #================================================= -ynh_script_progression --message="Configuring application..." +ynh_script_progression "Configuring application..." -ynh_add_config --jinja --template=local.py.j2 --destination="$install_dir/coin/settings_local.py" -chmod 400 "$install_dir/coin/settings_local.py" -chown $app "$install_dir/coin/settings_local.py" +ynh_config_add --jinja --template=local.py.j2 --destination="$install_dir/coin/settings_local.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/coin/settings_local.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app "$install_dir/coin/settings_local.py" # SERVE STATIC FILES IN PRODUCTION MODE ln -s $install_dir/$app/static $install_dir/static pushd $install_dir - ynh_exec_warn_less venv/bin/python3 manage.py migrate --noinput - ynh_exec_warn_less venv/bin/python3 manage.py collectstatic --noinput + ynh_hide_warnings venv/bin/python3 manage.py migrate --noinput + ynh_hide_warnings venv/bin/python3 manage.py collectstatic --noinput popd # Set permissions to directory -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -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 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" +#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:www-data "$install_dir" # Setup log permissions mkdir -p /var/log/$app -chown -R $app /var/log/$app -chown -R $app:www-data "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app /var/log/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data "/var/log/$app" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." +ynh_script_progression "Adding $app's configuration..." -ynh_add_config --template="gunicorn_config.py" --destination="$install_dir/gunicorn_config.py" +ynh_config_add --template="gunicorn_config.py" --destination="$install_dir/gunicorn_config.py" -chown $app:www-data "$install_dir/gunicorn_config.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:www-data "$install_dir/gunicorn_config.py" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring system..." +ynh_script_progression "Configuring system..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd # Integrating service in YunoHost yunohost service add $app --description "$app daemon" --log="/var/log/$app/$app.log" @@ -85,13 +83,13 @@ yunohost service add $app --description "$app daemon" --log="/var/log/$app/$app. #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting systemd service..." +ynh_script_progression "Starting systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="start" #================================================= # 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 da3d304..39f34c7 100644 --- a/scripts/remove +++ b/scripts/remove @@ -6,22 +6,22 @@ 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..." # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_hide_warnings yunohost service status $app >/dev/null then yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # 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 5a0b820..aadd972 100644 --- a/scripts/restore +++ b/scripts/restore @@ -7,29 +7,28 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" +ynh_restore "$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" +#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:www-data "$install_dir" #================================================= # 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" -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_db_shell < "./db.sql"" #================================================= # PYTHON DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling venv..." --weight=1 +ynh_script_progression "Reinstalling venv..." -ynh_secure_remove --file="${install_dir}/venv" +ynh_safe_rm "${install_dir}/venv" pushd "$install_dir" python3 -m venv venv venv/bin/pip install --upgrade pip @@ -43,14 +42,14 @@ popd #================================================= mkdir -p /var/log/$app -chown -R $app:www-data /var/log/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:www-data /var/log/$app #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 +ynh_script_progression "Restoring $app's systemd service..." -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/etc/systemd/system/$app.service" systemctl enable $app.service --quiet yunohost service add $app --description "$app daemon" --log="/var/log/$app/$app.log" @@ -58,14 +57,14 @@ yunohost service add $app --description "$app daemon" --log="/var/log/$app/$app. #================================================= # RELOAD NGINX AND PHP-FPM OR THE APP SERVICE #================================================= -ynh_script_progression --message="Reloading NGINX web server and $app's service..." --weight=1 +ynh_script_progression "Reloading NGINX web server and $app's service..." -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="start" -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 d97a29d..948d494 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -3,31 +3,27 @@ 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..." --weight=1 +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" #================================================= # 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..." --weight=1 + ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$install_dir" --full_replace=1 --keep=coin/settings_local.py + ynh_setup_source --dest_dir="$install_dir" --full_replace --keep=coin/settings_local.py fi - -ynh_secure_remove --file="${install_dir}/venv" +ynh_safe_rm "${install_dir}/venv" pushd "$install_dir" python3 -m venv venv venv/bin/pip install --upgrade pip @@ -36,69 +32,65 @@ pushd "$install_dir" venv/bin/pip install -r requirements.txt popd -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -R $app:www-data "$install_dir" - -#================================================= -# SPECIFIC UPGRADE +#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" +#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:www-data "$install_dir" #================================================= # CONFIGURE DJANGO #================================================= -ynh_script_progression --message="Configuring Django..." --weight=1 +ynh_script_progression "Configuring Django..." # NB: We do NOT regen the settings_local.py using the template # because we absolutely don't want to overwrite it -chmod 400 "$install_dir/coin/settings_local.py" -chown $app "$install_dir/coin/settings_local.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/coin/settings_local.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app "$install_dir/coin/settings_local.py" -ynh_add_config --template="../conf/gunicorn_config.py" --destination="$install_dir/gunicorn_config.py" -chown $app:www-data "$install_dir/gunicorn_config.py" +ynh_config_add --template="gunicorn_config.py" --destination="$install_dir/gunicorn_config.py" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:www-data "$install_dir/gunicorn_config.py" #================================================= # MIGRATE DB #================================================= -ynh_script_progression --message="Migrating database..." --weight=1 +ynh_script_progression "Migrating database..." pushd "$install_dir" - ynh_exec_warn_less venv/bin/python3 manage.py migrate --noinput + ynh_hide_warnings venv/bin/python3 manage.py migrate --noinput popd #================================================= # COLLECT FILES #================================================= -ynh_script_progression --message="Collecting files..." --weight=1 +ynh_script_progression "Collecting files..." pushd "$install_dir" - ynh_exec_warn_less venv/bin/python3 manage.py collectstatic --noinput + ynh_hide_warnings venv/bin/python3 manage.py collectstatic --noinput popd -chmod 750 "$install_dir" -chmod -R o-rwx "$install_dir" -chown -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 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" +#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:www-data "$install_dir" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading system configurations..." --weight=1 +ynh_script_progression "Upgrading system configurations..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd yunohost service add $app --description "$app daemon" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --weight=1 +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" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"