From 71407f825b5a3fb1021747475e4b0a9147009b74 Mon Sep 17 00:00:00 2001 From: yalh76 Date: Mon, 5 Sep 2022 21:45:47 +0200 Subject: [PATCH] Apply last example_ynh --- check_process | 1 - manifest.json | 4 ++-- scripts/_common.sh | 13 +++++++++++-- scripts/backup | 5 ++++- scripts/install | 10 +++++++--- scripts/remove | 2 +- scripts/restore | 14 +++++++------- scripts/upgrade | 16 ++++++++-------- 8 files changed, 40 insertions(+), 25 deletions(-) diff --git a/check_process b/check_process index 5eb242a..a95f90a 100644 --- a/check_process +++ b/check_process @@ -2,7 +2,6 @@ ; pre-install sudo yunohost tools update apps sudo yunohost app install https://github.com/YunoHost-Apps/synapse_ynh/ -a "domain=$domain&server_name=$server_name&is_free_registration=$is_free_registration&jitsi_server=$jitsi_server" --force - ; Manifest domain="domain.tld" port="8343" diff --git a/manifest.json b/manifest.json index 1aa8766..1213876 100644 --- a/manifest.json +++ b/manifest.json @@ -3,13 +3,13 @@ "id": "matrix-puppet-discord", "packaging_format": 1, "description": { - "en": "A Discord puppeting bridge for Matrix/Synapse.", + "en": "Discord puppeting bridge for Matrix/Synapse.", "fr": "Passerelle Discord pour Matrix/Synapse." }, "version": "0.1.7~ynh2", "url": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord", "upstream": { - "license": " Apache-2.0", + "license": "Apache-2.0", "website": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord", "admindoc": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord", "code": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord" diff --git a/scripts/_common.sh b/scripts/_common.sh index 4a28303..c60db3d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,11 +4,20 @@ # COMMON VARIABLES #================================================= -# dependencies used by the app -pkg_dependencies="postgresql" # Node version NODEJS_VERSION=16 +# dependencies used by the app (must be on a single line) +pkg_dependencies="postgresql" + #================================================= # PERSONAL HELPERS #================================================= + +#================================================= +# EXPERIMENTAL HELPERS +#================================================= + +#================================================= +# FUTURE OFFICIAL HELPERS +#================================================= diff --git a/scripts/backup b/scripts/backup index 0a2ec9c..76e3ea0 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,6 +14,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + true +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -57,7 +60,7 @@ ynh_backup --src_path="$etc_path" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSql database..." +ynh_print_info --message="Backing up the PostgreSQL database..." ynh_psql_dump_db --database="$db_name" > db.sql diff --git a/scripts/install b/scripts/install index 161c6cf..4b0f3dc 100755 --- a/scripts/install +++ b/scripts/install @@ -14,7 +14,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -97,12 +97,14 @@ ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # CREATE A POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Creating a PostgresSql database..." --weight=10 +ynh_script_progression --message="Creating a PostgreSQL database..." --weight=10 db_name=$(ynh_sanitize_dbid --db_name=$app) db_user=$db_name ynh_app_setting_set --app=$app --key=db_name --value=$db_name +ynh_psql_test_if_first_run ynh_psql_setup_db --db_user=$db_user --db_name=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -117,6 +119,8 @@ chmod 750 "$final_path" chmod -R o-rwx "$final_path" chown -R $app:$app "$final_path" +#================================================= +# SPECIFIC SETUP #================================================= # INSTALL NODE DEPENDENCIES #================================================= @@ -201,7 +205,7 @@ ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "$app daemon for bridging Discord and Matrix messages" +yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/remove b/scripts/remove index 4610249..44f0e8f 100755 --- a/scripts/remove +++ b/scripts/remove @@ -48,7 +48,7 @@ ynh_remove_systemd_config #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgresSql database..." --weight=1 +ynh_script_progression --message="Removing the PostgreSQL database..." --weight=1 # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name diff --git a/scripts/restore b/scripts/restore index 89791e3..eef7b48 100755 --- a/scripts/restore +++ b/scripts/restore @@ -15,7 +15,7 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - ynh_clean_check_starting + true } # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -80,13 +80,12 @@ ynh_use_nodejs #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgresSql database..." --weight=20 +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=20 ynh_psql_test_if_first_run db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) -# TODO: should I let these operation be logged? ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_connect_as --user=$db_user --password=$db_pwd --database=$db_name < ./db.sql +ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name #================================================= # RESTORE VARIOUS FILES @@ -106,9 +105,10 @@ chown $app:$app "$etc_path/user.config.yaml" #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= +ynh_script_progression --message="Registering Synapse app-service" --weight=1 + cp "$final_path/$app.yaml" $app_service_registration_path/$app.yaml -/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ - || ynh_die --message="Synapse can't restart with the appservice configuration" +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration" #================================================= # RESTORE SYSTEMD @@ -126,7 +126,7 @@ chown "$app:$app" "$final_path/run.sh" #================================================= ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -yunohost service add $app --description "$app daemon for bridging Discord and Matrix messages" +yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index bb7e72a..876bd2c 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -35,7 +35,7 @@ app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service #================================================= # CHECK VERSION #================================================= -ynh_script_progression --message="Checking version..." +ynh_script_progression --message="Checking version..." --weight=1 upgrade_type=$(ynh_check_app_version_changed) @@ -47,7 +47,6 @@ ynh_script_progression --message="Backing up the app before upgrading (may take # Backup the current version of the app ynh_backup_before_upgrade ynh_clean_setup () { - ynh_clean_check_starting # Restore it if the upgrade fails ynh_restore_upgradebackup } @@ -100,6 +99,8 @@ ynh_script_progression --message="Upgrading dependencies..." --weight=9 ynh_install_app_dependencies $pkg_dependencies ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +#================================================= +# SPECIFIC UPGRADE #================================================= # INSTALL NODE DEPENDENCIES #================================================= @@ -110,8 +111,6 @@ pushd "$final_path" ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new' npm install popd -#================================================= -# SPECIFIC UPGRADE #================================================= # UPDATE A CONFIG FILE #================================================= @@ -123,16 +122,16 @@ chmod 400 "$base_config_path" chown $app:$app "$base_config_path" #================================================= -# REGISTER MODULE IN SYNAPSE +# REGISTER SYNAPSE APP-SERVICE #================================================= +ynh_script_progression --message="Registering Synapse app-service" --weight=1 pushd "$final_path" ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH NODE_ENV=production $final_path/run.sh -r -f "$app.yaml" popd cp "$final_path/$app.yaml" $app_service_registration_path/$app.yaml -/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ - || ynh_die --message="Synapse can't restart with the appservice configuration" +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration" #================================================= # SETUP SYSTEMD @@ -155,13 +154,14 @@ ynh_add_config --template="../conf/run.sh" --destination="$final_path/run.sh" chmod 750 "$final_path/run.sh" chown "$app:$app" "$final_path/run.sh" -yunohost service add $app --description "$app daemon for bridging Discord and Matrix messages" +yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" #=================================================