diff --git a/check_process b/check_process index c19342e..c78054a 100644 --- a/check_process +++ b/check_process @@ -1,8 +1,3 @@ -# See here for more information -# https://github.com/YunoHost/package_check#syntax-check_process-file - -# Move this file from check_process.default to check_process when you have filled it. - ;; Test complet ; pre-install sudo yunohost tools update apps @@ -26,3 +21,6 @@ change_url=0 actions=0 config_panel=0 +;;; Options +Email= +Notification=none diff --git a/conf/app.src b/conf/app.src index 841eef9..3b2ad45 100644 --- a/conf/app.src +++ b/conf/app.src @@ -3,5 +3,5 @@ SOURCE_SUM=df351ace3788ad9c2d932bcdfc0ba691cd071575d7bd0f9180fbe6976dca5c42 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=tar.gz SOURCE_IN_SUBDIR=true -# SOURCE_FILENAME= -# SOURCE_EXTRACT=true +SOURCE_FILENAME= +SOURCE_EXTRACT=true diff --git a/sources/extra_files/app/run.sh b/conf/run.sh similarity index 100% rename from sources/extra_files/app/run.sh rename to conf/run.sh diff --git a/manifest.json b/manifest.json index b460d01..1aa8766 100644 --- a/manifest.json +++ b/manifest.json @@ -6,7 +6,7 @@ "en": "A Discord puppeting bridge for Matrix/Synapse.", "fr": "Passerelle Discord pour Matrix/Synapse." }, - "version": "0.1.7~ynh1", + "version": "0.1.7~ynh2", "url": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord", "upstream": { "license": " Apache-2.0", @@ -27,7 +27,7 @@ "postgresql" ], "arguments": { - "install" : [ + "install": [ { "name": "synapsenumber", "type": "string", diff --git a/scripts/backup b/scripts/backup index e6d9fca..0a2ec9c 100755 --- a/scripts/backup +++ b/scripts/backup @@ -14,6 +14,7 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +# Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= @@ -34,11 +35,6 @@ etc_path=$(ynh_app_setting_get --app=$app --key=etc_path) #================================================= ynh_print_info --message="Declaring files to be backed up..." -### N.B. : the following 'ynh_backup' calls are only a *declaration* of what needs -### to be backuped and not an actual copy of any file. The actual backup that -### creates and fill the archive with the files happens in the core after this -### script is called. Hence ynh_backups calls takes basically 0 seconds to run. - #================================================= # BACKUP THE APP MAIN DIR #================================================= @@ -63,9 +59,6 @@ ynh_backup --src_path="$etc_path" #================================================= ynh_print_info --message="Backing up the PostgreSql database..." -### (However, things like PostgreSql dumps *do* take some time to run, though the -### copy of the generated dump to the archive still happens later) - ynh_psql_dump_db --database="$db_name" > db.sql #================================================= diff --git a/scripts/install b/scripts/install index 781286f..161c6cf 100755 --- a/scripts/install +++ b/scripts/install @@ -13,29 +13,34 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors #================================================= -# SET CONSTANTS +# RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -app=$YNH_APP_INSTANCE_NAME -final_path=/opt/yunohost/$app synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER +app=$YNH_APP_INSTANCE_NAME + +final_path=/opt/yunohost/$app + if [ $synapsenumber -eq "1" ] then - synapse_instance="synapse" + synapse_instance="synapse" else - synapse_instance="synapse__$synapsenumber" + synapse_instance="synapse__$synapsenumber" fi synapse_config_path="/etc/matrix-$synapse_instance" # Check Synapse is installed or die early if [ ! -d $synapse_config_path ] then - ynh_die --message="Could not find $synapse_config_path config directory. Ensure that you installed Matrix Synapse first and that you entered a correct \"synapse instance number\"" + ynh_die --message="Could not find $synapse_config_path config directory. Ensure that you installed Matrix Synapse first and that you entered a correct \"synapse instance number\"" fi server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name) @@ -69,11 +74,6 @@ ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance #================================================= ynh_script_progression --message="Finding an available port..." --weight=1 -### Use these lines if you have to open a port for the application -### `ynh_find_port` will find the first available port starting from the given port. -### If you're not using these lines: -### - Remove the section "CLOSE A PORT" in the remove script - # Find an available port port=$(ynh_find_port --port=8434) ynh_app_setting_set --app=$app --key=port --value=$port @@ -110,6 +110,7 @@ ynh_psql_setup_db --db_user=$db_user --db_name=$db_name ynh_script_progression --message="Setting up source files..." --weight=1 ynh_app_setting_set --app=$app --key=final_path --value=$final_path +# Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$final_path" chmod 750 "$final_path" @@ -122,15 +123,15 @@ chown -R $app:$app "$final_path" ynh_script_progression --message="Building Node dependencies..." --weight=30 pushd "$final_path" - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new' npm install + ynh_use_nodejs + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new' npm install popd #================================================= # SETUP PIP (FOR YQ) #================================================= - ynh_script_progression --message="Install yq..." --weight=1 + pip_path=$final_path/.pip python3 -m venv $pip_path $pip_path/bin/pip3 install yq @@ -163,7 +164,7 @@ chown $app:$app "$user_config_path" ynh_script_progression --message="Configuring a systemd service..." --weight=1 # Create startup script -ynh_add_config --template="../sources/extra_files/app/run.sh" --destination="$final_path/run.sh" +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" @@ -171,47 +172,36 @@ chown "$app:$app" "$final_path/run.sh" # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -yunohost service add $app --description "$app daemon for bridging Discord and Matrix messages" - #================================================= # CREATE LOG DIR #================================================= + mkdir -p -m 700 "$log_path" chown $app:$app "$log_path" - #================================================= # REGISTER MODULE IN SYNAPSE #================================================= ynh_script_progression --message="Register module in Synapse" --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" + 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" + || ynh_die --message="Synapse can't restart with the appservice configuration" -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" - #================================================= -# SEND A README FOR THE ADMIN +# GENERIC FINALIZATION #================================================= -ynh_script_progression --message="Sending a readme for the admin..." +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 -# ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients=$admin_email --type='install' +yunohost service add $app --description "$app daemon for bridging Discord and Matrix messages" #================================================= # START SYSTEMD SERVICE @@ -221,6 +211,13 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" +#================================================= +# SEND A README FOR THE ADMIN +#================================================= +ynh_script_progression --message="Sending a readme for the admin..." + +# ynh_send_readme_to_admin --app_message="../conf/msg_install" --recipients=$admin_email --type='install' + #================================================= # END OF SCRIPT #================================================= diff --git a/scripts/remove b/scripts/remove index 5f50d04..4610249 100755 --- a/scripts/remove +++ b/scripts/remove @@ -53,6 +53,14 @@ ynh_script_progression --message="Removing the PostgresSql database..." --weight # Remove a database if it exists, along with the associated user ynh_psql_remove_db --db_user=$db_user --db_name=$db_name +#================================================= +# REMOVE APP MAIN DIR +#================================================= +ynh_script_progression --message="Removing app main directory..." --weight=1 + +# Remove the app directory securely +ynh_secure_remove --file="$final_path" + #================================================= # REMOVE DEPENDENCIES #================================================= @@ -63,14 +71,6 @@ ynh_remove_nodejs # Remove metapackage and its dependencies ynh_remove_app_dependencies -#================================================= -# REMOVE APP MAIN DIR -#================================================= -ynh_script_progression --message="Removing app main directory..." --weight=1 - -# Remove the app directory securely -ynh_secure_remove --file="$final_path" - #================================================= # SPECIFIC REMOVE #================================================= diff --git a/scripts/restore b/scripts/restore index 6f2e6fc..89791e3 100755 --- a/scripts/restore +++ b/scripts/restore @@ -14,6 +14,9 @@ source /usr/share/yunohost/helpers # MANAGE SCRIPT FAILURE #================================================= +ynh_clean_setup () { + ynh_clean_check_starting +} # Exit if an error occurs during the execution of the script ynh_abort_if_errors @@ -105,7 +108,7 @@ chown $app:$app "$etc_path/user.config.yaml" #================================================= 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" + || ynh_die --message="Synapse can't restart with the appservice configuration" #================================================= # RESTORE SYSTEMD diff --git a/scripts/upgrade b/scripts/upgrade index f49b530..bb7e72a 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -18,11 +18,11 @@ app=$YNH_APP_INSTANCE_NAME domain=$(ynh_app_setting_get --app=$app --key=domain) path_url=$(ynh_app_setting_get --app=$app --key=path) -port=$(ynh_app_setting_get --app=$app --key=port) +language=$(ynh_app_setting_get --app=$app --key=language) admin=$(ynh_app_setting_get --app=$app --key=admin) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -language=$(ynh_app_setting_get --app=$app --key=language) db_name=$(ynh_app_setting_get --app=$app --key=db_name) +port=$(ynh_app_setting_get --app=$app --key=port) db_user=$db_name db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) @@ -35,13 +35,8 @@ app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service #================================================= # CHECK VERSION #================================================= +ynh_script_progression --message="Checking version..." -### This helper will compare the version of the currently installed app and the version of the upstream package. -### $upgrade_type can have 2 different values -### - UPGRADE_APP if the upstream app version has changed -### - UPGRADE_PACKAGE if only the YunoHost package has changed -### ynh_check_app_version_changed will stop the upgrade if the app is up to date. -### UPGRADE_APP should be used to upgrade the core app only if there's an upgrade to do. upgrade_type=$(ynh_check_app_version_changed) #================================================= @@ -52,6 +47,7 @@ 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 } @@ -72,27 +68,6 @@ ynh_systemd_action --service_name=$app --action="stop" #================================================= ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 -# -# N.B. : the followings setting migrations snippets are provided as *EXAMPLES* -# of what you may want to do in some cases (e.g. a setting was not defined on -# some legacy installs and you therefore want to initiaze stuff during upgrade) -# - -# If db_name doesn't exist, create it -#if [ -z "$db_name" ]; then -# db_name=$(ynh_sanitize_dbid --db_name=$app) -# ynh_app_setting_set --app=$app --key=db_name --value=$db_name -#fi - -# If final_path doesn't exist, create it -#if [ -z "$final_path" ]; then -# final_path=/var/www/$app -# ynh_app_setting_set --app=$app --key=final_path --value=$final_path -#fi - -### If nobody installed your app before 4.1, -### then you may safely remove these lines - #================================================= # CREATE DEDICATED USER #================================================= @@ -107,10 +82,10 @@ ynh_system_user_create --username=$app --home_dir="$final_path" if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --weight=1 + ynh_script_progression --message="Upgrading source files..." --weight=1 - # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" --keep="run.sh" + # Download, check integrity, uncompress and patch the source from app.src + ynh_setup_source --dest_dir="$final_path" --keep="run.sh" fi chmod 750 "$final_path" @@ -128,12 +103,11 @@ ynh_install_nodejs --nodejs_version=$NODEJS_VERSION #================================================= # INSTALL NODE DEPENDENCIES #================================================= - ynh_script_progression --message="Building Node dependencies..." --weight=3 pushd "$final_path" - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new' npm install + ynh_use_nodejs + ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH GIT_SSH_COMMAND='ssh -o StrictHostKeyChecking=accept-new' npm install popd #================================================= @@ -143,16 +117,23 @@ popd #================================================= ynh_script_progression --message="Updating configuration files..." --weight=1 -### Same as during install -### -### The file will automatically be backed-up if it's found to be manually modified (because -### ynh_add_config keeps track of the file's checksum) - base_config_path="$final_path/base.config.yaml" ynh_add_config --template="base.config.yaml" --destination="$base_config_path" chmod 400 "$base_config_path" chown $app:$app "$base_config_path" +#================================================= +# REGISTER MODULE IN SYNAPSE +#================================================= + +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" + #================================================= # SETUP SYSTEMD #================================================= @@ -169,7 +150,7 @@ ynh_add_systemd_config ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 # Create startup script -ynh_add_config --template="../sources/extra_files/app/run.sh" --destination="$final_path/run.sh" +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" @@ -183,18 +164,6 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 ynh_systemd_action --service_name=$app --action="start" -#================================================= -# REGISTER MODULE IN SYNAPSE -#================================================= - -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" - #================================================= # END OF SCRIPT #================================================= diff --git a/sources/extra_files/app/.gitignore b/sources/extra_files/app/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/sources/extra_files/app/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op]