From eaae26410311ef18437e33f7f2fcf23924462b31 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Pi=C3=A9dallu?= Date: Fri, 29 Mar 2024 15:26:17 +0100 Subject: [PATCH 1/2] Manifestv2 --- check_process | 25 --- conf/app.src | 7 - conf/base.config.yaml | 2 +- conf/run.sh | 6 +- conf/systemd.service | 4 +- conf/user.config.yaml | 4 +- doc/{DISCLAIMER.md => POST_INSTALL.md} | 0 doc/{DISCLAIMER_fr.md => POST_INSTALL_fr.md} | 0 manifest.json | 47 ----- manifest.toml | 65 +++++++ scripts/_common.sh | 13 +- scripts/backup | 31 +-- scripts/install | 188 +++++-------------- scripts/remove | 73 +------ scripts/restore | 107 +++-------- scripts/upgrade | 159 ++++++---------- tests.toml | 19 ++ 17 files changed, 241 insertions(+), 509 deletions(-) delete mode 100644 check_process delete mode 100644 conf/app.src rename doc/{DISCLAIMER.md => POST_INSTALL.md} (100%) rename doc/{DISCLAIMER_fr.md => POST_INSTALL_fr.md} (100%) delete mode 100644 manifest.json create mode 100644 manifest.toml create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index a95f90a..0000000 --- a/check_process +++ /dev/null @@ -1,25 +0,0 @@ -;; Test complet - ; 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" - synapsenumber=1 - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=0 - setup_nourl=1 - setup_private=0 - setup_public=0 - upgrade=1 - backup_restore=1 - multi_instance=1 - port_already_use=1 - change_url=0 - actions=0 - config_panel=0 -;;; Options -Email= -Notification=none diff --git a/conf/app.src b/conf/app.src deleted file mode 100644 index 00efad8..0000000 --- a/conf/app.src +++ /dev/null @@ -1,7 +0,0 @@ -SOURCE_URL=https://gitlab.com/mx-puppet/discord/mx-puppet-discord/-/archive/fd4402268e9a8b942ca632f3337702862e06d24f/mx-puppet-discord-master.tar.gz -SOURCE_SUM=b0edc4dfe9d3670eb8b53dc229a8fd7fb794ada5fe1f3d3ba4c38b54ce5ca176 -SOURCE_SUM_PRG=sha256sum -SOURCE_FORMAT=tar.gz -SOURCE_IN_SUBDIR=true -SOURCE_FILENAME= -SOURCE_EXTRACT=true diff --git a/conf/base.config.yaml b/conf/base.config.yaml index 4ce0bef..e674a6b 100644 --- a/conf/base.config.yaml +++ b/conf/base.config.yaml @@ -142,7 +142,7 @@ logging: # Log files are rotated daily by default files: # Log file path - - file: "__LOG_PATH__/bridge.log" # Will capture logs from DiscordBot + - file: "/var/log/__APP__/bridge.log" # Will capture logs from DiscordBot # Log level for this file # # Allowed values starting with most verbose: diff --git a/conf/run.sh b/conf/run.sh index d62b480..fee3198 100644 --- a/conf/run.sh +++ b/conf/run.sh @@ -3,11 +3,11 @@ set -o errexit set -o nounset -echo < __FINALPATH__/config.yaml +echo < __INSTALL_DIR__/config.yaml # /!\ FILE GENERATED AUTOMATICALLY BEFORE EACH SERVICE RESTART # CONSIDER EDITING /etc/__APP__/user.config.yaml EOF -__PIP_PATH__/bin/yq -y -s '.[0] * .[1]' __FINALPATH__/base.config.yaml /etc/__APP__/user.config.yaml > __FINALPATH__/config.yaml +__INSTALL_DIR__/venv/bin/yq -y -s '.[0] * .[1]' __INSTALL_DIR__/base.config.yaml /etc/__APP__/user.config.yaml > __INSTALL_DIR__/config.yaml -__YNH_NPM__ start -- -c config.yaml $@ +__YNH_NPM__ start -- -c config.yaml "$@" diff --git a/conf/systemd.service b/conf/systemd.service index b4ec910..aa59ee5 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -8,8 +8,8 @@ Environment=NODE_ENV=production Environment="__YNH_NODE_LOAD_PATH__" User=__APP__ Group=__APP__ -WorkingDirectory=__FINALPATH__/ -ExecStart=__FINALPATH__/run.sh -f __APP__.yaml +WorkingDirectory=__INSTALL_DIR__/ +ExecStart=__INSTALL_DIR__/run.sh -f __APP__.yaml StandardOutput=syslog StandardError=syslog diff --git a/conf/user.config.yaml b/conf/user.config.yaml index 4fd49ed..1c868fd 100644 --- a/conf/user.config.yaml +++ b/conf/user.config.yaml @@ -1,6 +1,6 @@ # You can edit this file. -# This will override the configuration contained in the __FINALPATH__/base.config.yaml file. -# Don't hesitate to take a look at __FINALPATH__/sample.config.yaml to see all the available options. +# This will override the configuration contained in the __INSTALL_DIR__/base.config.yaml file. +# Don't hesitate to take a look at __INSTALL_DIR__/sample.config.yaml to see all the available options. # Then, in order to take into account the changes, run: systemctl restart __APP__ provisioning: diff --git a/doc/DISCLAIMER.md b/doc/POST_INSTALL.md similarity index 100% rename from doc/DISCLAIMER.md rename to doc/POST_INSTALL.md diff --git a/doc/DISCLAIMER_fr.md b/doc/POST_INSTALL_fr.md similarity index 100% rename from doc/DISCLAIMER_fr.md rename to doc/POST_INSTALL_fr.md diff --git a/manifest.json b/manifest.json deleted file mode 100644 index 74e11a7..0000000 --- a/manifest.json +++ /dev/null @@ -1,47 +0,0 @@ -{ - "name": "Matrix-Discord bridge", - "id": "matrix-puppet-discord", - "packaging_format": 1, - "description": { - "en": "Discord puppeting bridge for Matrix/Synapse.", - "fr": "Passerelle Discord pour Matrix/Synapse." - }, - "version": "0.1.7~ynh4", - "url": "https://gitlab.com/mx-puppet/discord/mx-puppet-discord", - "upstream": { - "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" - }, - "license": "Apache-2.0", - "maintainer": { - "name": "fflorent", - "email": "florent.git@zeteo.me" - }, - "requirements": { - "yunohost": ">= 11.1" - }, - "multi_instance": true, - "services": [ - "postgresql" - ], - "arguments": { - "install": [ - { - "name": "synapsenumber", - "type": "string", - "ask": { - "en": "Choose the local synapse instance number to communicate with the Discord-Matrix bridge", - "fr": "Choisissez le numéro de l'instance synapse qui doit communiquer avec la passerelle Discord-Matrix" - }, - "example": "2 (for instance synapse__2)", - "help": { - "en": "If you installed synapse only once time, then leave default value 1.", - "fr": "Si vous n'avez installé qu'une fois synapse, gardez la valeur par défaut 1." - }, - "default": "1" - } - ] - } -} diff --git a/manifest.toml b/manifest.toml new file mode 100644 index 0000000..d373caa --- /dev/null +++ b/manifest.toml @@ -0,0 +1,65 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/manifest.v2.schema.json + +packaging_format = 2 + +id = "matrix-puppet-discord" +name = "Matrix-Discord bridge" +description.en = "Discord puppeting bridge for Matrix/Synapse." +description.fr = "Passerelle Discord pour Matrix/Synapse." + +version = "0.1.7~ynh5" + +maintainers = ["fflorent"] + +[upstream] +license = "Apache-2.0" +admindoc = "https://gitlab.com/mx-puppet/discord/mx-puppet-discord" +code = "https://gitlab.com/mx-puppet/discord/mx-puppet-discord" +fund = "https://liberapay.com/Sorunome/donate" + +[integration] +yunohost = ">= 11.2" +architectures = "all" +multi_instance = true +ldap = "not_releant" +sso = "not_releant" +disk = "50M" # FIXME: replace with an **estimate** minimum disk requirement. e.g. 20M, 400M, 1G, ... +ram.build = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... +ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requirement. e.g. 50M, 400M, 1G, ... + + [install.synapsenumber] + ask.en = "Choose the local synapse instance number to communicate with the Discord-Matrix bridge" + ask.fr = "Choisissez le numéro de l'instance synapse qui doit communiquer avec la passerelle Discord-Matrix" + help.en = "If you installed synapse only once time, then leave default value 1." + help.fr = "Si vous n'avez installé qu'une fois synapse, gardez la valeur par défaut 1." + type = "string" + example = "2 (for instance synapse__2)" + default = "1" + +[resources] + [resources.sources.main] + url = "https://gitlab.com/mx-puppet/discord/mx-puppet-discord/-/archive/fd4402268e9a8b942ca632f3337702862e06d24f/mx-puppet-discord-master.tar.gz" + sha256 = "b0edc4dfe9d3670eb8b53dc229a8fd7fb794ada5fe1f3d3ba4c38b54ce5ca176" + + autoupdate.strategy = "latest_gitlab_tag" + + [resources.system_user] + + [resources.install_dir] + + [resources.permissions] + + [resources.ports] + + [resources.apt] + packages = [ + "postgresql", + "libcairo2-dev", + "libpango1.0-dev", + "libjpeg-dev", + "libgif-dev", + "librsvg2-dev", + ] + + [resources.database] + type = "postgresql" diff --git a/scripts/_common.sh b/scripts/_common.sh index c8e896e..d10db49 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -4,16 +4,21 @@ # COMMON VARIABLES #================================================= -# Node version NODEJS_VERSION=12 -# dependencies used by the app (must be on a single line) -pkg_dependencies="postgresql libcairo2-dev libpango1.0-dev libjpeg-dev libgif-dev librsvg2-dev" - #================================================= # PERSONAL HELPERS #================================================= +_venv_install() { + ynh_exec_as "$app" python3 -m venv --upgrade "$install_dir/venv" + venvpy="$install_dir/venv/bin/python3" + + ynh_exec_as "$app" "$venvpy" -m pip install --upgrade --no-cache-dir pip + + ynh_exec_as "$app" "$venvpy" -m pip install setuptools wheel pyyaml +} + #================================================= # EXPERIMENTAL HELPERS #================================================= diff --git a/scripts/backup b/scripts/backup index 76e3ea0..6005da7 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,29 +8,6 @@ source ../settings/scripts/_common.sh 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 - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_print_info --message="Loading installation settings..." - -app=$YNH_APP_INSTANCE_NAME - -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -domain=$(ynh_app_setting_get --app=$app --key=domain) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -log_path=$(ynh_app_setting_get --app=$app --key=log_path) -etc_path=$(ynh_app_setting_get --app=$app --key=etc_path) - #================================================= # DECLARE DATA AND CONF FILES TO BACKUP #================================================= @@ -42,10 +17,10 @@ ynh_print_info --message="Declaring files to be backed up..." # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$final_path" +ynh_backup --src_path="$install_dir" #================================================= -# BACKUP SYSTEMD +# BACKUP SYSTEM FILES #================================================= ynh_backup --src_path="/etc/systemd/system/$app.service" @@ -54,7 +29,7 @@ ynh_backup --src_path="/etc/systemd/system/$app.service" # BACKUP VARIOUS FILES #================================================= -ynh_backup --src_path="$log_path" +ynh_backup --src_path="/var/log/$app" ynh_backup --src_path="$etc_path" #================================================= diff --git a/scripts/install b/scripts/install index 5ebea9e..1060e98 100755 --- a/scripts/install +++ b/scripts/install @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,141 +8,62 @@ source _common.sh 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 - -#================================================= -# RETRIEVE ARGUMENTS FROM THE MANIFEST +# INITIALIZE AND STORE SETTINGS #================================================= -synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER - -app=$YNH_APP_INSTANCE_NAME - -final_path=/opt/yunohost/$app - -if [ $synapsenumber -eq "1" ] -then - synapse_instance="synapse" +if [ $synapsenumber -eq "1" ]; then + 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\"" +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\"" fi server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name) domain=$(ynh_app_setting_get --app $synapse_instance --key domain) + app_service_registration_path="/etc/matrix-$synapse_instance/app-service" log_path="/var/log/$app" -base_config_path="$final_path/base.config.yaml" +base_config_path="$install_dir/base.config.yaml" user_config_path="/etc/$app/user.config.yaml" -#================================================= -# CHECK IF THE APP CAN BE INSTALLED WITH THESE ARGS -#================================================= -ynh_script_progression --message="Validating installation parameters..." --weight=1 - -test ! -e "$final_path" || ynh_die --message="This path already contains a folder" - -#================================================= -# STORE SETTINGS FROM MANIFEST -#================================================= -ynh_script_progression --message="Storing installation settings..." --weight=1 - -ynh_app_setting_set --app=$app --key=domain --value=$domain -ynh_app_setting_set --app=$app --key=log_path --value=$log_path -ynh_app_setting_set --app=$app --key=app_service_registration_path --value=$app_service_registration_path -ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance - -#================================================= -# STANDARD MODIFICATIONS -#================================================= -# FIND AND OPEN A PORT -#================================================= -ynh_script_progression --message="Finding an available port..." --weight=1 - -# Find an available port -port=$(ynh_find_port --port=8434) -ynh_app_setting_set --app=$app --key=port --value=$port - #================================================= # INSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Installing dependencies..." --weight=4 +ynh_script_progression --message="Installing NodeJS..." --weight=4 -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_install_app_dependencies $pkg_dependencies - -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Configuring system user..." --weight=1 - -# Create a system user -ynh_system_user_create --username=$app --home_dir="$final_path" - -#================================================= -# CREATE A POSTGRESQL DATABASE -#================================================= -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) +ynh_install_nodejs --nodejs_version="$NODEJS_VERSION" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= 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" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# SPECIFIC SETUP -#================================================= -# INSTALL NODE DEPENDENCIES -#================================================= -ynh_script_progression --message="Building Node dependencies..." --weight=30 +ynh_setup_source --dest_dir="$install_dir/source" -pushd "$final_path" - ynh_use_nodejs - ynh_exec_warn_less sudo -u $app env $ynh_node_load_PATH npx yarn 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 +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= # ADD CONFIGURATION FILES #================================================= ynh_script_progression --message="Adding configuration files..." --weight=1 +# Create startup script +ynh_add_config --template="run.sh" --destination="$install_dir/run.sh" +chmod 750 "$install_dir/run.sh" + +# TODO Add a way to override the config.yaml file +ynh_add_config --template="base.config.yaml" --destination="$install_dir/base.config.yaml" +chmod 400 "$install_dir/base.config.yaml" +chown "$app:$app" "$install_dir/base.config.yaml" + etc_path=$(dirname $user_config_path) ynh_app_setting_set --app=$app --key=etc_path --value=$etc_path @@ -153,74 +72,67 @@ chown "$app:$app" "$etc_path" any_account_of_domain="@.*:${domain//\./\\\.}" -# TODO Add a way to override the config.yaml file -ynh_add_config --template="base.config.yaml" --destination="$base_config_path" ynh_add_config --template="user.config.yaml" --destination="$user_config_path" - -chmod 400 "$base_config_path" -chown $app:$app "$base_config_path" chmod 600 "$user_config_path" -chown $app:$app "$user_config_path" +chown "$app:$app" "$user_config_path" #================================================= -# SETUP SYSTEMD +# INSTALL NODE DEPENDENCIES #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=1 +ynh_script_progression --message="Building Node dependencies..." --weight=30 -# Create startup script -ynh_add_config --template="../conf/run.sh" --destination="$final_path/run.sh" +pushd "$install_dir/source" + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" npx yarn install +popd -chmod 750 "$final_path/run.sh" -chown "$app:$app" "$final_path/run.sh" +#================================================= +# SETUP PIP (FOR YQ) +#================================================= +ynh_script_progression --message="Install yq..." --weight=1 -# Create a dedicated systemd config -ynh_add_systemd_config +_venv_install +"$venvpy" -m pip install yq #================================================= # CREATE LOG DIR #================================================= mkdir -p -m 700 "$log_path" -chown $app:$app "$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" +pushd "$install_dir/source" + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" NODE_ENV=production \ + "$install_dir/run.sh" -r -f "$install_dir/$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" +cp "$install_dir/$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_store_file_checksum --file="$app_service_registration_path/$app.yaml" #================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST +# SYSTEM CONFIGURATION #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression --message="Adding system configurations related to $app..." --weight=1 -yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages" +# Create a dedicated systemd config +ynh_add_systemd_config +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 +ynh_script_progression --message="Starting $app's 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' +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/remove b/scripts/remove index 44f0e8f..9495a03 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -10,87 +8,34 @@ source _common.sh source /usr/share/yunohost/helpers #================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -port=$(ynh_app_setting_get --app=$app --key=port) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -log_path=$(ynh_app_setting_get --app=$app --key=log_path) -etc_path=$(ynh_app_setting_get --app=$app --key=etc_path) - -#================================================= -# STANDARD REMOVE -#================================================= -# REMOVE SERVICE INTEGRATION IN YUNOHOST +# REMOVE SYSTEM CONFIGURATIONS #================================================= +ynh_script_progression --message="Removing system configurations related to $app..." --weight=1 # 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 - ynh_script_progression --message="Removing $app service integration..." --weight=1 - yunohost service remove $app +if ynh_exec_warn_less yunohost service status "$app" >/dev/null; then + yunohost service remove "$app" fi -#================================================= -# STOP AND REMOVE SERVICE -#================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 - # Remove the dedicated systemd config ynh_remove_systemd_config -#================================================= -# REMOVE THE POSTGRESQL DATABASE -#================================================= -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 - -#================================================= -# 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 -#================================================= -ynh_script_progression --message="Removing dependencies..." --weight=1 - -# Remove nodejs version if not used by another app -ynh_remove_nodejs -# Remove metapackage and its dependencies -ynh_remove_app_dependencies - -#================================================= -# SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= ynh_script_progression --message="Removing various files..." --weight=1 # Remove the log files -ynh_secure_remove --file="$log_path" +ynh_secure_remove --file="/var/log/$app" ynh_secure_remove --file="$etc_path" #================================================= -# GENERIC FINALIZATION -#================================================= -# REMOVE DEDICATED USER +# REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --weight=1 +ynh_script_progression --message="Uninstalling NodeJS..." --weight=1 -# Delete a system user -ynh_system_user_delete --username=$app +# Remove nodejs version if not used by another app +ynh_remove_nodejs #================================================= # END OF SCRIPT diff --git a/scripts/restore b/scripts/restore index eef7b48..7b1f9ac 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -11,129 +9,68 @@ source ../settings/scripts/_common.sh 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 - -#================================================= -# LOAD SETTINGS -#================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -final_path=$(ynh_app_setting_get --app=$app --key=final_path) -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_user=$db_name -synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) -app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) -port=$(ynh_app_setting_get --app=$app --key=port) - -#================================================= -# CHECK IF THE APP CAN BE RESTORED -#================================================= -ynh_script_progression --message="Validating restoration parameters..." --weight=1 - -test ! -d $final_path \ - || ynh_die --message="There is already a directory: $final_path " - -#================================================= -# STANDARD RESTORATION STEPS -#================================================= -# RECREATE THE DEDICATED USER +# REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 +ynh_script_progression --message="Reinstalling NodeJS..." --weight=4 -# Create the dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_install_nodejs --nodejs_version="$NODEJS_VERSION" +ynh_use_nodejs #================================================= # RESTORE THE APP MAIN DIR #================================================= ynh_script_progression --message="Restoring the app main directory..." --weight=1 -ynh_restore_file --origin_path="$final_path" - -chmod 750 "$final_path" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" - -#================================================= -# SPECIFIC RESTORATION -#================================================= -# REINSTALL DEPENDENCIES -#================================================= -ynh_script_progression --message="Reinstalling dependencies..." --weight=4 +ynh_restore_file --origin_path="$install_dir" -# Define and install dependencies -ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION -ynh_use_nodejs +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= 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) -ynh_psql_setup_db --db_user=$db_user --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_connect_as --user="$db_user" --password="$db_pwd" --database="$db_name" < ./db.sql #================================================= # RESTORE VARIOUS FILES #================================================= ynh_script_progression --message="Restoring various files..." --weight=1 -log_path=$(ynh_app_setting_get --app=$app --key=log_path) -ynh_restore_file --origin_path="$log_path" -chown $app:$app "$log_path" +ynh_restore_file --origin_path="/var/log/$app" +chown "$app:$app" "/var/log/$app" -etc_path=$(ynh_app_setting_get --app=$app --key=etc_path) ynh_restore_file --origin_path="$etc_path" -chown $app:$app "$etc_path" + +chown "$app:$app" "$etc_path" chmod 600 "$etc_path/user.config.yaml" -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" +cp "$install_dir/$app.yaml" "$app_service_registration_path/$app.yaml" -#================================================= -# RESTORE SYSTEMD -#================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=1 - -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" -systemctl enable $app.service --quiet - -chmod 750 "$final_path/run.sh" -chown "$app:$app" "$final_path/run.sh" +"/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" \ + || ynh_die --message="Synapse can't restart with the appservice configuration" #================================================= -# INTEGRATE SERVICE IN YUNOHOST +# RESTORE SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression --message="Restoring system configurations related to $app..." --weight=1 -yunohost service add $app --description="$app daemon for bridging Discord and Matrix messages" +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable "$app.service" --quiet +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 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/scripts/upgrade b/scripts/upgrade index 0df0ba7..fc134f0 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,7 +1,5 @@ #!/bin/bash -#================================================= -# GENERIC START #================================================= # IMPORT GENERIC HELPERS #================================================= @@ -12,157 +10,112 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=1 - -app=$YNH_APP_INSTANCE_NAME - -domain=$(ynh_app_setting_get --app=$app --key=domain) -path_url=$(ynh_app_setting_get --app=$app --key=path) -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) -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) -log_path=$(ynh_app_setting_get --app=$app --key=log_path) -etc_path=$(ynh_app_setting_get --app=$app --key=etc_path) +#REMOVEME? ynh_script_progression --message="Loading installation settings..." --weight=1 + +#REMOVEME? app=$YNH_APP_INSTANCE_NAME + +#REMOVEME? domain=$(ynh_app_setting_get --app=$app --key=domain) +#REMOVEME? path=$(ynh_app_setting_get --app=$app --key=path) +#REMOVEME? language=$(ynh_app_setting_get --app=$app --key=language) +#REMOVEME? admin=$(ynh_app_setting_get --app=$app --key=admin) +#REMOVEME? #REMOVEME? install_dir=$(ynh_app_setting_get --app=$app --key=install_dir) +#REMOVEME? db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#REMOVEME? port=$(ynh_app_setting_get --app=$app --key=port) +#REMOVEME? db_user=$db_name +#REMOVEME? db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +#REMOVEME? synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) +#REMOVEME? log_path=$(ynh_app_setting_get --app=$app --key=log_path) +#REMOVEME? etc_path=$(ynh_app_setting_get --app=$app --key=etc_path) user_config_path="$etc_path/user.config.yaml" -pip_path="$final_path/.pip" -app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) - -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." --weight=1 - -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=1 - -# Backup the current version of the app -ynh_backup_before_upgrade -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors +pip_path="$install_dir/.pip" +#REMOVEME? app_service_registration_path=$(ynh_app_setting_get --app=$app --key=app_service_registration_path) -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression --message="Stopping $app's systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" +ynh_systemd_action --service_name="$app" --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +# ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 #================================================= -# CREATE DEDICATED USER +# UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=1 +ynh_script_progression --message="Upgrading NodeJS..." --weight=9 -# Create a dedicated user (if not existing) -ynh_system_user_create --username=$app --home_dir="$final_path" +ynh_install_nodejs --nodejs_version="$NODEJS_VERSION" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= +ynh_script_progression --message="Upgrading source files..." --weight=1 -if [ "$upgrade_type" == "UPGRADE_APP" ] -then - 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="$install_dir/source" --full_replace=1 - # 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" -chmod -R o-rwx "$final_path" -chown -R $app:$app "$final_path" +chmod -R o-rwx "$install_dir" +chown -R "$app:$app" "$install_dir" #================================================= -# UPGRADE DEPENDENCIES +# UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=9 +ynh_script_progression --message="Updating configuration files..." --weight=1 -ynh_install_app_dependencies $pkg_dependencies -ynh_install_nodejs --nodejs_version=$NODEJS_VERSION +# Create startup script +ynh_add_config --template="run.sh" --destination="$install_dir/run.sh" +chmod 750 "$install_dir/run.sh" +chown "$app:$app" "$install_dir/run.sh" + +ynh_add_config --template="base.config.yaml" --destination="$install_dir/base.config.yaml" +chmod 400 "$install_dir/base.config.yaml" +chown "$app:$app" "$install_dir/base.config.yaml" -#================================================= -# SPECIFIC UPGRADE #================================================= # INSTALL NODE DEPENDENCIES #================================================= -ynh_script_progression --message="Building Node dependencies..." --weight=3 +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 npx yarn install +pushd "$install_dir/source" + ynh_use_nodejs + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" npx yarn install popd -#================================================= -# UPDATE A CONFIG FILE -#================================================= -ynh_script_progression --message="Updating configuration files..." --weight=1 - -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 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" +pushd "$install_dir/source" + ynh_exec_warn_less ynh_exec_as "$app" env "$ynh_node_load_PATH" NODE_ENV=production \ + "$install_dir/run.sh "-r -f "$install_dir/$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" +cp "$install_dir/$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_store_file_checksum --file="$app_service_registration_path/$app.yaml" #================================================= -# SETUP SYSTEMD +# REAPPLY SYSTEM CONFIGURATIONS #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=1 +ynh_script_progression --message="Upgrading system configurations related to $app..." --weight=1 # Create a dedicated systemd config ynh_add_systemd_config - -#================================================= -# GENERIC FINALIZATION -#================================================= -# INTEGRATE SERVICE IN YUNOHOST -#================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 - -# Create startup script -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 +ynh_script_progression --message="Starting $app's systemd service..." --weight=1 # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" +ynh_systemd_action --service_name="$app" --action="start" #================================================= # END OF SCRIPT diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..d19bb11 --- /dev/null +++ b/tests.toml @@ -0,0 +1,19 @@ +#:schema https://raw.githubusercontent.com/YunoHost/apps/master/schemas/tests.v1.schema.json + +test_format = 1.0 + +[default] + + preinstall = """ + 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 + """ + + # ------------ + # Tests to run + # ------------ + + # domain="domain.tld" + # port="8343" + # synapsenumber=1 From 3c736e5483fa1a406f273b061c2f8cf53ea28296 Mon Sep 17 00:00:00 2001 From: yunohost-bot Date: Fri, 29 Mar 2024 14:42:05 +0000 Subject: [PATCH 2/2] Auto-update READMEs --- README.md | 9 +-------- README_fr.md | 9 +-------- README_gl.md | 9 +-------- README_it.md | 9 +-------- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index d7f5d68..cce1ad1 100644 --- a/README.md +++ b/README.md @@ -41,25 +41,18 @@ This is a discord puppeting bridge for matrix. It handles bridging private and g See for documentation. -**Shipped version:** 0.1.7~ynh4 +**Shipped version:** 0.1.7~ynh5 ## Screenshots ![Screenshot of Matrix-Discord bridge](./doc/screenshots/example.jpg) -## Disclaimers / important information - -After the install is complete, start a chat with `@_discordpuppet_bot:yourserver.com`. When it joins, type `help` in the chat to see instructions. - -You also may modify the `/etc/matrix-puppet-discord/user.config.yaml` file to customize some configuration (like permissions to use the bridge). Ensure then to restart the bridge (`systemctl restart matrix-puppet-discord`). - ## :red_circle: Antifeatures - **Upstream not maintained**: This software is not maintained anymore. Expect it to break down over time, be exposed to unfixed security breaches, etc. ## Documentation and resources -- Official app website: - Official admin documentation: - Upstream app code repository: - YunoHost Store: diff --git a/README_fr.md b/README_fr.md index 7838dbf..a3071b9 100644 --- a/README_fr.md +++ b/README_fr.md @@ -41,25 +41,18 @@ Ceci est une passerelle vers Discord pour Matrix. Il gère la messagerie privée Voir la documentation sur (en anglais). -**Version incluse :** 0.1.7~ynh4 +**Version incluse :** 0.1.7~ynh5 ## Captures d’écran ![Capture d’écran de Matrix-Discord bridge](./doc/screenshots/example.jpg) -## Avertissements / informations importantes - -Après l'installation, lancer une conversation privée avec `@_discordpuppet_bot:yourserver.com`. Ensuite, entrer `help` dans le chat pour lire les instructions. - -Vous pouvez par ailleurs modifier le fichier `/etc/matrix-puppet-discord/user.config.yaml` pour personnaliser la configuration (notamment les permissions pour utiliser la passerelle). Redémarrez bien ensuite la passerelle pour que les modifications soient effectives (`systemctl restart matrix-puppet-discord`). - ## :red_circle: Anti-fonctionnalités - **Application non maintenue**: Ce logiciel n'est plus maintenu. Attendez-vous à ce qu'il ne fonctionne plus avec le temps, et que l'on découvre des failles de sécurité qui ne seront pas corrigées, etc. ## Documentations et ressources -- Site officiel de l’app : - Documentation officielle de l’admin : - Dépôt de code officiel de l’app : - YunoHost Store : diff --git a/README_gl.md b/README_gl.md index 6b5fc7a..93a3c7a 100644 --- a/README_gl.md +++ b/README_gl.md @@ -41,25 +41,18 @@ This is a discord puppeting bridge for matrix. It handles bridging private and g See for documentation. -**Versión proporcionada:** 0.1.7~ynh4 +**Versión proporcionada:** 0.1.7~ynh5 ## Capturas de pantalla ![Captura de pantalla de Matrix-Discord bridge](./doc/screenshots/example.jpg) -## Avisos / información importante - -After the install is complete, start a chat with `@_discordpuppet_bot:yourserver.com`. When it joins, type `help` in the chat to see instructions. - -You also may modify the `/etc/matrix-puppet-discord/user.config.yaml` file to customize some configuration (like permissions to use the bridge). Ensure then to restart the bridge (`systemctl restart matrix-puppet-discord`). - ## :red_circle: Caraterísticas cuestionables - **Upstream not maintained**: This software is not maintained anymore. Expect it to break down over time, be exposed to unfixed security breaches, etc. ## Documentación e recursos -- Web oficial da app: - Documentación oficial para admin: - Repositorio de orixe do código: - Tenda YunoHost: diff --git a/README_it.md b/README_it.md index 5ca441c..15c5dbf 100644 --- a/README_it.md +++ b/README_it.md @@ -41,25 +41,18 @@ This is a discord puppeting bridge for matrix. It handles bridging private and g See for documentation. -**Versione pubblicata:** 0.1.7~ynh4 +**Versione pubblicata:** 0.1.7~ynh5 ## Screenshot ![Screenshot di Matrix-Discord bridge](./doc/screenshots/example.jpg) -## Attenzione/informazioni importanti - -After the install is complete, start a chat with `@_discordpuppet_bot:yourserver.com`. When it joins, type `help` in the chat to see instructions. - -You also may modify the `/etc/matrix-puppet-discord/user.config.yaml` file to customize some configuration (like permissions to use the bridge). Ensure then to restart the bridge (`systemctl restart matrix-puppet-discord`). - ## :red_circle: Anti-funzionalità - **Applicazione non mantenuta**: Questo software non è più mantenuto. Ci si può aspettare che con il passare del tempo smetta di funzionare, sia esposto a falle di sicurezza, ecc. ## Documentazione e risorse -- Sito web ufficiale dell’app: - Documentazione ufficiale per gli amministratori: - Repository upstream del codice dell’app: - Store di YunoHost: