diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 462d70b..e0a920c 100644 --- a/manifest.toml +++ b/manifest.toml @@ -23,6 +23,7 @@ fund = "https://my.fsf.org/civicrm/contribute/transact?reset=1&id=22" [integration] yunohost = ">=11.2" +helpers_version = "2.1" architectures = "all" multi_instance = false ldap = false @@ -49,6 +50,7 @@ ram.runtime = "800M" [resources.system_user] [resources.install_dir] + group = "www-data:r-x" [resources.permissions] main.url = "/" diff --git a/scripts/_common.sh b/scripts/_common.sh index 944a65e..3d7f008 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,17 +1,5 @@ #!/bin/bash #================================================= -# COMMON VARIABLES -#================================================= - -#================================================= -# PERSONAL HELPERS -#================================================= - -#================================================= -# EXPERIMENTAL HELPERS -#================================================= - -#================================================= -# FUTURE OFFICIAL HELPERS +# COMMON VARIABLES AND CUSTOM HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 3883acc..a86a6c4 100755 --- a/scripts/backup +++ b/scripts/backup @@ -8,37 +8,34 @@ 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..." #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_backup "/etc/nginx/conf.d/$domain.d/$app.conf" #================================================= # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="/etc/$app/mailman.cfg" -ynh_backup --src_path="/etc/$app/mailman-hyperkitty.cfg" -ynh_backup --src_path="/etc/$app/mailman-web.py" +ynh_backup "/etc/$app/mailman.cfg" +ynh_backup "/etc/$app/mailman-hyperkitty.cfg" +ynh_backup "/etc/$app/mailman-web.py" -ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3" +ynh_backup "/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3" #================================================= # BACKUP THE POSTGRESQL 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_app" > db_app.sql -ynh_psql_dump_db --database="$db_name_web" > db_web.sql +ynh_psql_dump_db _app" > db_app.sql +ynh_psql_dump_db _web" > db_web.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/install b/scripts/install index 2cbb984..72204f8 100755 --- a/scripts/install +++ b/scripts/install @@ -18,75 +18,75 @@ email="admin@$domain" db_name_app=$(ynh_sanitize_dbid --db_name="${app}_app") db_user_app=$db_name_app db_pwd_app=$(ynh_string_random --length=30) -ynh_app_setting_set --app="$app" --key="db_name_app" --value="$db_name_app" -ynh_app_setting_set --app="$app" --key="db_user_app" --value="$db_user_app" -ynh_app_setting_set --app="$app" --key="db_pwd_app" --value="$db_pwd_app" +ynh_app_setting_set --key="db_name_app" --value="$db_name_app" +ynh_app_setting_set --key="db_user_app" --value="$db_user_app" +ynh_app_setting_set --key="db_pwd_app" --value="$db_pwd_app" # mailman3-web database db_name_web=$(ynh_sanitize_dbid --db_name="${app}_web") db_user_web=$db_name_web db_pwd_web=$(ynh_string_random --length=30) -ynh_app_setting_set --app="$app" --key="db_name_web" --value="$db_name_web" -ynh_app_setting_set --app="$app" --key="db_user_web" --value="$db_user_web" -ynh_app_setting_set --app="$app" --key="db_pwd_web" --value="$db_pwd_web" +ynh_app_setting_set --key="db_name_web" --value="$db_name_web" +ynh_app_setting_set --key="db_user_web" --value="$db_user_web" +ynh_app_setting_set --key="db_pwd_web" --value="$db_pwd_web" # mailman3 core configuration rest_api_admin_user="rest_admin" rest_api_admin_pwd=$(head -n15 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c15) -ynh_app_setting_set --app="$app" --key="rest_api_admin_user" --value="$rest_api_admin_user" -ynh_app_setting_set --app="$app" --key="rest_api_admin_pwd" --value="$rest_api_admin_pwd" +ynh_app_setting_set --key="rest_api_admin_user" --value="$rest_api_admin_user" +ynh_app_setting_set --key="rest_api_admin_pwd" --value="$rest_api_admin_pwd" # hyperkitty configuration archiver_key=$(head -n32 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c32) -ynh_app_setting_set --app="$app" --key=archiver_key --value="$archiver_key" +ynh_app_setting_set --key=archiver_key --value="$archiver_key" # mailman3-web configuration secret_key=$(head -n64 /dev/urandom | tail -n +1 | tr -dc -d 'a-z0-9' | head -c64) -ynh_app_setting_set --app="$app" --key=secret_key --value="$secret_key" +ynh_app_setting_set --key=secret_key --value="$secret_key" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgreSQL database..." +ynh_script_progression "Creating a PostgreSQL database..." # Can' use resource helper because we need 2 dbs with specific names… -ynh_psql_test_if_first_run +#REMOVEME? ynh_psql_test_if_first_run # mailman3-app database -ynh_psql_setup_db --db_user="$db_user_app" --db_name="$db_name_app" --db_pwd="$db_pwd_app" +# FIXMEhelpers2.1 ynh_psql_create_db --db_user="$db_user_app" --db_name="$db_name_app" --db_pwd="$db_pwd_app" # mailman3-web database -ynh_psql_setup_db --db_user="$db_user_web" --db_name="$db_name_web" --db_pwd="$db_pwd_web" +# FIXMEhelpers2.1 ynh_psql_create_db --db_user="$db_user_web" --db_name="$db_name_web" --db_pwd="$db_pwd_web" #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding $app's configuration files..." +ynh_script_progression "Adding $app's configuration files..." -ynh_add_config --template="mailman.cfg" --destination="/etc/mailman3/mailman.cfg" +ynh_config_add --template="mailman.cfg" --destination="/etc/mailman3/mailman.cfg" chmod 400 "/etc/mailman3/mailman.cfg" chown list:list "/etc/mailman3/mailman.cfg" -ynh_add_config --template="mailman-hyperkitty.cfg" --destination="/etc/mailman3/mailman-hyperkitty.cfg" +ynh_config_add --template="mailman-hyperkitty.cfg" --destination="/etc/mailman3/mailman-hyperkitty.cfg" chmod 400 "/etc/mailman3/mailman-hyperkitty.cfg" chown list:list "/etc/mailman3/mailman-hyperkitty.cfg" -ynh_add_config --template="mailman-web.py" --destination="/etc/mailman3/mailman-web.py" +ynh_config_add --template="mailman-web.py" --destination="/etc/mailman3/mailman-web.py" chmod 440 "/etc/mailman3/mailman-web.py" chown list:www-data "/etc/mailman3/mailman-web.py" #================================================= # RUN DATABASE MIGRATIONS #================================================= -ynh_script_progression --message="Running database migrations..." +ynh_script_progression "Running database migrations..." pushd /usr/share/mailman3-web - python3 manage.py migrate || ynh_die --message="Mailman3 migrations failed!" + python3 manage.py migrate || ynh_die "Mailman3 migrations failed!" popd #================================================= # CREATE SUPERUSER #================================================= -ynh_script_progression --message="Creating superuser..." +ynh_script_progression "Creating superuser..." pushd /usr/share/mailman3-web echo "from django.contrib.auth import get_user_model; User = get_user_model(); User.objects.create_superuser('$admin', '$email', '$password')" | python manage.py shell popd @@ -94,7 +94,7 @@ popd #================================================= # CONFIGURE MAINDOMAIN #================================================= -ynh_script_progression --message="Configuring maindomain..." +ynh_script_progression "Configuring maindomain..." pushd /usr/share/mailman3-web echo "UPDATE django_site SET domain='$domain',name='$domain' WHERE domain='example.com';" | python3 manage.py dbshell popd @@ -102,21 +102,21 @@ popd #================================================= # POSTFIX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring postfix mail server..." +ynh_script_progression "Configuring postfix mail server..." # Add postfix configuration hook and regen postfix conf cp -R ../sources/hooks/conf_regen/98-postfix_mailman3 /usr/share/yunohost/hooks/conf_regen/ yunohost tools regen-conf postfix sudo -su list mailman aliases -ynh_systemd_action --service_name=postfix --action="restart" +ynh_systemctl --service=postfix --action="restart" #================================================= # 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 -ynh_add_nginx_config +ynh_config_add_nginx # Create a dedicated systemd config systemctl enable "$app.service" --quiet @@ -128,14 +128,14 @@ yunohost service add "$app-web" --description="Mailman3 web daemon" --log="/var/ #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd services..." --weight=1 +ynh_script_progression "Starting $app's systemd services..." # Start a systemd service -ynh_systemd_action --service_name="$app" --action="restart" -ynh_systemd_action --service_name="$app-web" --action="restart" +ynh_systemctl --service="$app" --action="restart" +ynh_systemctl --service="$app-web" --action="restart" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index ddb8ff8..ba1a375 100755 --- a/scripts/remove +++ b/scripts/remove @@ -10,51 +10,51 @@ 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; then +if ynh_hide_warnings yunohost service status "$app" >/dev/null; then yunohost service remove "$app" fi -if ynh_exec_warn_less yunohost service status "$app-web" >/dev/null; then +if ynh_hide_warnings yunohost service status "$app-web" >/dev/null; then yunohost service remove "$app-web" fi # Remove the dedicated systemd config -ynh_systemd_action --service_name="$app" --action="stop" -ynh_systemd_action --service_name="$app-web" --action="stop" +ynh_systemctl --service="$app" --action="stop" +ynh_systemctl --service="$app-web" --action="stop" systemctl disable "$app.service" --quiet systemctl disable "$app-web.service" --quiet # Remove the dedicated NGINX config -ynh_remove_nginx_config +ynh_config_remove_nginx #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." +ynh_script_progression "Removing various files..." -ynh_secure_remove --file="/usr/share/mailman3-web" +ynh_safe_rm "/usr/share/mailman3-web" # Remove a directory securely -ynh_secure_remove --file="/etc/$app" +ynh_safe_rm "/etc/$app" # Remove hook for postfix conf -ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3" +ynh_safe_rm "/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3" yunohost tools regen-conf postfix -ynh_systemd_action --service_name="postfix" --action="restart" +ynh_systemctl --service="postfix" --action="restart" #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." +ynh_script_progression "Removing the PostgreSQL database..." # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user="$db_user_app" --db_name="$db_name_app" -ynh_psql_remove_db --db_user="$db_user_web" --db_name="$db_name_web" +# FIXMEhelpers2.1 ynh_psql_drop_db && ynh_psql_drop_user --db_user="$db_user_app" --db_name="$db_name_app" +# FIXMEhelpers2.1 ynh_psql_drop_db && ynh_psql_drop_user --db_user="$db_user_web" --db_name="$db_name_web" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index 185f2c8..1c1a835 100755 --- a/scripts/restore +++ b/scripts/restore @@ -11,40 +11,40 @@ source /usr/share/yunohost/helpers #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_test_if_first_run +#REMOVEME? ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user="$db_user_app" --db_name="$db_name_app" --db_pwd="$db_pwd_app" -ynh_psql_execute_file_as_root --file="./db_app.sql" --database="$db_name_app" +# FIXMEhelpers2.1 ynh_psql_create_db --db_user="$db_user_app" --db_name="$db_name_app" --db_pwd="$db_pwd_app" +ynh_psql_db_shell _app"" < "./db_app.sql"" -ynh_psql_setup_db --db_user="$db_user_web" --db_name="$db_name_web" --db_pwd="$db_pwd_web" -ynh_psql_execute_file_as_root --file="./db_web.sql" --database="$db_name_web" +# FIXMEhelpers2.1 ynh_psql_create_db --db_user="$db_user_web" --db_name="$db_name_web" --db_pwd="$db_pwd_web" +ynh_psql_db_shell _web"" < "./db_web.sql"" #================================================= # RESTORE VARIOUS FILES #================================================= -ynh_script_progression --message="Restoring $app's configuration files..." +ynh_script_progression "Restoring $app's configuration files..." -ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3" +ynh_restore "/usr/share/yunohost/hooks/conf_regen/98-postfix_mailman3" yunohost tools regen-conf postfix -ynh_systemd_action --service_name=postfix --action="restart" +ynh_systemctl --service=postfix --action="restart" -ynh_secure_remove --file="/etc/$app/mailman.cfg" -ynh_restore_file --origin_path="/etc/$app/mailman.cfg" +ynh_safe_rm "/etc/$app/mailman.cfg" +ynh_restore "/etc/$app/mailman.cfg" -ynh_secure_remove --file="/etc/$app/mailman-hyperkitty.cfg" -ynh_restore_file --origin_path="/etc/$app/mailman-hyperkitty.cfg" +ynh_safe_rm "/etc/$app/mailman-hyperkitty.cfg" +ynh_restore "/etc/$app/mailman-hyperkitty.cfg" -ynh_secure_remove --file="/etc/$app/mailman-web.py" -ynh_restore_file --origin_path="/etc/$app/mailman-web.py" +ynh_safe_rm "/etc/$app/mailman-web.py" +ynh_restore "/etc/$app/mailman-web.py" #================================================= # RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 +ynh_script_progression "Restoring system configurations related to $app..." -ynh_restore_file --origin_path="/etc/nginx/conf.d/$domain.d/$app.conf" +ynh_restore "/etc/nginx/conf.d/$domain.d/$app.conf" systemctl enable "$app.service" --quiet systemctl enable "$app-web.service" --quiet @@ -55,15 +55,15 @@ yunohost service add "$app-web" --description="Mailman3 web daemon" --log="/var/ #================================================= # 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=restart -ynh_systemd_action --service_name="$app-web" --action=restart +ynh_systemctl --service="$app" --action=restart +ynh_systemctl --service="$app-web" --action=restart -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" +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index af812ff..ed13d2f 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -10,72 +10,74 @@ source /usr/share/yunohost/helpers #================================================= # 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" -ynh_systemd_action --service_name="$app-web" --action="stop" +ynh_systemctl --service="$app" --action="stop" +ynh_systemctl --service="$app-web" --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." # Create missing db_user_* as copy of db_name_* +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=db_user_app --value="$db_name_app" if [ -z "${db_user_app:-}" ]; then db_user_app="$db_name_app" - ynh_app_setting_set --app="$app" --key="db_user_app" --value="$db_user_app" + ynh_app_setting_set --key="db_user_app" --value="$db_user_app" fi +# FIXMEhelpers2.1: maybe replace with: ynh_app_setting_set_default --key=db_user_web --value="$db_name_web" if [ -z "${db_user_web:-}" ]; then db_user_web="$db_name_web" - ynh_app_setting_set --app="$app" --key="db_user_web" --value="$db_user_web" + ynh_app_setting_set --key="db_user_web" --value="$db_user_web" fi # Migrate rest_admin_* -> rest_api_admin_* if [ -z "${rest_api_admin_user:-}" ]; then rest_api_admin_user="$rest_admin_user" - ynh_app_setting_set --app="$app" --key="rest_api_admin_user" --value="$rest_api_admin_user" - ynh_app_setting_delete --app="$app" --key="rest_admin_user" + ynh_app_setting_set --key="rest_api_admin_user" --value="$rest_api_admin_user" + ynh_app_setting_delete --key="rest_admin_user" fi if [ -z "${rest_api_admin_pwd:-}" ]; then rest_api_admin_pwd="$rest_admin_pwd" - ynh_app_setting_set --app="$app" --key="rest_api_admin_pwd" --value="$rest_api_admin_pwd" - ynh_app_setting_delete --app="$app" --key="rest_admin_pwd" + ynh_app_setting_set --key="rest_api_admin_pwd" --value="$rest_api_admin_pwd" + ynh_app_setting_delete --key="rest_admin_pwd" fi #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Updating $app's configuration files..." +ynh_script_progression "Updating $app's configuration files..." -ynh_add_config --template="mailman.cfg" --destination="/etc/mailman3/mailman.cfg" +ynh_config_add --template="mailman.cfg" --destination="/etc/mailman3/mailman.cfg" chmod 400 "/etc/mailman3/mailman.cfg" chown list:list "/etc/mailman3/mailman.cfg" -ynh_add_config --template="mailman-hyperkitty.cfg" --destination="/etc/mailman3/mailman-hyperkitty.cfg" +ynh_config_add --template="mailman-hyperkitty.cfg" --destination="/etc/mailman3/mailman-hyperkitty.cfg" chmod 400 "/etc/mailman3/mailman-hyperkitty.cfg" chown list:list "/etc/mailman3/mailman-hyperkitty.cfg" -ynh_add_config --template="mailman-web.py" --destination="/etc/mailman3/mailman-web.py" +ynh_config_add --template="mailman-web.py" --destination="/etc/mailman3/mailman-web.py" chmod 440 "/etc/mailman3/mailman-web.py" chown list:www-data "/etc/mailman3/mailman-web.py" #================================================= # POSTFIX CONFIGURATION #================================================= -ynh_script_progression --message="Configuring postfix mail server..." +ynh_script_progression "Configuring postfix mail server..." # Add postfix configuration hook and regen postfix conf cp -R ../sources/hooks/conf_regen/98-postfix_mailman3 /usr/share/yunohost/hooks/conf_regen/ yunohost tools regen-conf postfix -ynh_systemd_action --service_name="postfix" --action="reload" +ynh_systemctl --service="postfix" --action="reload" #================================================= # REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 +ynh_script_progression "Upgrading system configurations related to $app..." # Create a dedicated NGINX config -ynh_add_nginx_config +ynh_config_add_nginx systemctl enable "$app.service" --quiet systemctl enable "$app-web.service" --quiet @@ -86,13 +88,13 @@ yunohost service add "$app-web" --description="Mailman3 web daemon" --log="/var/ #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting $app's systemd service..." --weight=1 +ynh_script_progression "Starting $app's systemd service..." -ynh_systemd_action --service_name="$app" --action=start -ynh_systemd_action --service_name="$app-web" --action=start +ynh_systemctl --service="$app" --action=start +ynh_systemctl --service="$app-web" --action=start #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" +ynh_script_progression "Upgrade of $app completed"