From db5f73debfd111e539138eea188f1907d995cabc Mon Sep 17 00:00:00 2001 From: Dante Date: Sun, 16 Jul 2023 11:40:28 +0100 Subject: [PATCH] Refactor restore, add tests and refactor upgrade --- check_process | 33 -------------------------------- manifest.toml | 5 +++++ scripts/restore | 24 +++++++++++++++++++++++ scripts/upgrade | 51 ++----------------------------------------------- tests.toml | 51 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 82 insertions(+), 82 deletions(-) delete mode 100644 check_process create mode 100644 tests.toml diff --git a/check_process b/check_process deleted file mode 100644 index a30309e..0000000 --- a/check_process +++ /dev/null @@ -1,33 +0,0 @@ -;; Default test serie - ; 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 - synapsenumber="1" - whatsappbot="whatsappbot" - bot_synapse_adm=0 - encryption=0 - botadmin="@johndoe:synapsedomain.tld" - botusers="@johndoe:synapsedomain.tld" - ; Checks - pkg_linter=1 - setup_sub_dir=0 - setup_root=0 - setup_nourl=1 - setup_private=0 - setup_public=0 - upgrade=1 - # 0.4.0 - upgrade=1 from_commit=717b32f454819c1bb936152c69d9693d34434741 - # 0.6.1 - upgrade=1 from_commit=fdd1e0ff652ae47b5e3c62477eea678c465659cf - backup_restore=1 - multi_instance=1 -;;; Options -Email= -Notification=none -;;; Upgrade options - ; commit=717b32f454819c1bb936152c69d9693d34434741 - name=0.4.0 - ; commit=fdd1e0ff652ae47b5e3c62477eea678c465659cf - name=0.6.1 diff --git a/manifest.toml b/manifest.toml index 29872df..5170831 100644 --- a/manifest.toml +++ b/manifest.toml @@ -32,6 +32,7 @@ pattern.regexp = "synapse(__)*[0-9]*" pattern.error = "Invalid app selected. Please select a Synapse instance." help.en = "Usually the Synapse instances contain a number after it is installed more than one time. E.g. synapse__1 will be the second instance." help.fr = "En général, les instances de Synapse contiennent un numéro après avoir été installées plus d'une fois. Par exemple, synapse__1 sera la deuxième instance." +default = "synapse" [install.botname] ask.en = "Choose a local Synapse user name for the WhatsApp bot" @@ -87,6 +88,10 @@ packages = "g++, postgresql, ffmpeg" [resources.database] type = "postgresql" +[resources.permissions] +main.allowed = "all_users" +main.auth_header = false + [resources.system_user] home = "/opt/yunohost/__APP__" diff --git a/scripts/restore b/scripts/restore index 65e19f2..5eb36d5 100755 --- a/scripts/restore +++ b/scripts/restore @@ -18,6 +18,8 @@ ynh_clean_setup () { true } +server_name=$(ynh_app_setting_get --app=$app --key=server_name) + synapse_db_name="matrix_$synapse_instance" bot_synapse_db_user="@$botname:$server_name" @@ -51,12 +53,34 @@ ynh_script_progression --message="Registering Synapse app-service" --weight=1 $install_dir/mautrix-whatsapp -g -c $install_dir/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml /opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration" +chmod 400 "$install_dir/config.yaml" +chown $app:$app "$install_dir/config.yaml" + +#================================================= +# RESTORE SYSTEMD +#================================================= +ynh_script_progression --message="Restoring the systemd configuration..." --weight=3 + +ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +systemctl enable $app.service --quiet + #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 ynh_restore_file --origin_path="/etc/logrotate.d/$app" +mkdir --parents "/var/log/$app" +chmod -R 600 "/var/log/$app" +chmod 700 "/var/log/$app" +chown -R $app:$app /var/log/$app + +#================================================= +# INTEGRATE SERVICE IN YUNOHOST +#================================================= +ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 + +yunohost service add $app --description="$app daemon for bridging Whatsapp and Matrix messages" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE diff --git a/scripts/upgrade b/scripts/upgrade index 7da3f10..8e731b8 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -9,35 +9,11 @@ source _common.sh source /usr/share/yunohost/helpers +server_name=$(ynh_app_setting_get --app=$app --key=server_name) + synapse_db_name="matrix_$synapse_instance" bot_synapse_db_user="@$botname:$server_name" -#================================================= -# GET CONFIG PANEL SETTINGS -#================================================= -async_media=$(ynh_app_setting_get --app=$app --key=async_media) -displayname=$(ynh_app_setting_get --app=$app --key=displayname) -avatar=$(ynh_app_setting_get --app=$app --key=avatar) -ephemeral_events=$(ynh_app_setting_get --app=$app --key=ephemeral_events) -enable_metrics=$(ynh_app_setting_get --app=$app --key=enable_metrics) -listen_port=$(ynh_app_setting_get --app=$app --key=listen_port) -os_name=$(ynh_app_setting_get --app=$app --key=os_name) -browser_name=$(ynh_app_setting_get --app=$app --key=browser_name) -username_template=$(ynh_app_setting_get --app=$app --key=username_template) -personal_filtering_spaces=$(ynh_app_setting_get --app=$app --key=personal_filtering_spaces) -delivery_receipts=$(ynh_app_setting_get --app=$app --key=delivery_receipts) -send_presence_on_typing=$(ynh_app_setting_get --app=$app --key=send_presence_on_typing) -url_previews=$(ynh_app_setting_get --app=$app --key=url_previews) -encryption_default=$(ynh_app_setting_get --app=$app --key=encryption_default) -encryption_require=$(ynh_app_setting_get --app=$app --key=encryption_require) -enable_relaybot=$(ynh_app_setting_get --app=$app --key=enable_relaybot) -admin_only=$(ynh_app_setting_get --app=$app --key=admin_only) -print_level=$(ynh_app_setting_get --app=$app --key=print_level) - -listrelay=$(ynh_app_setting_get --app=$app --key=listrelay) -listuser=$(ynh_app_setting_get --app=$app --key=listuser) -listadmin=$(ynh_app_setting_get --app=$app --key=listadmin) - #================================================= # CHECK VERSION #================================================= @@ -45,16 +21,6 @@ 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=10 - -ynh_clean_setup () { - # Restore it if the upgrade fails - ynh_restore_upgradebackup -} - #================================================= # STANDARD UPGRADE STEPS #================================================= @@ -206,19 +172,6 @@ then ynh_app_setting_delete --app=$app --key=botadmin fi -#================================================= -# CREATE DEDICATED USER -#================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --weight=8 - -# Create a dedicated user (if not existing) and set home dir to /opt/yunohost/$app so systemd hardening works -# See more: https://docs.mau.fi/bridges/go/setup.html?bridge=whatsapp#systemd-service -if ynh_system_user_exists -u "$app"; then - usermod --home "$install_dir" $app -else - ynh_system_user_create --username=$app --home_dir="$install_dir" -fi - #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= diff --git a/tests.toml b/tests.toml new file mode 100644 index 0000000..2f8243c --- /dev/null +++ b/tests.toml @@ -0,0 +1,51 @@ +test_format = 1.0 + +[default] + +# ------------ +# Tests to run +# ------------ + +# For special usecases, sometimes you need to setup other things on the machine +# prior to installing the app (such as installing another app) +# (Remove this key entirely if not needed) +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 + """ + +# ------------------------------- +# Default args to use for install +# ------------------------------- + +# By default, the CI will automagically fill the 'standard' args +# such as domain, path, admin, is_public and password with relevant values +# and also install args with a "default" provided in the manifest.. +# It should only make sense to declare custom args here for args with no default values + +args.botadmin = "@johndoe:server.name" +args.botusers = "server.name" + +# ------------------------------- +# Commits to test upgrade from +# ------------------------------- + +test_upgrade_from.717b32f4.name = "Upgrade from 0.4.0" + +test_upgrade_from.fdd1e0ff.name = "Upgrade from 0.6.1" + + +# This is an additional test suite +[multiple_botusers] + +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 + """ + +# On additional tests suites, you can decide to run only specific tests + +only = ["install.subdir"] + +args.botadmin = "@johndoe:server.name" +args.botusers = "@john:server.name,@jdoe:server.name,@janedoe:server.name" \ No newline at end of file