diff --git a/README.md b/README.md index cf3388b..b2d35f3 100644 --- a/README.md +++ b/README.md @@ -3,14 +3,14 @@ N.B.: This README was automatically generated by https://github.com/YunoHost/app It shall NOT be edited by hand. --> -# Matrix WhatsApp bridge for YunoHost +# Matrix-WhatsApp bridge for YunoHost [![Integration level](https://dash.yunohost.org/integration/mautrix_whatsapp.svg)](https://dash.yunohost.org/appci/app/mautrix_whatsapp) ![Working status](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.status.svg) ![Maintenance status](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.maintain.svg) -[![Install Matrix WhatsApp bridge with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp) +[![Install Matrix-WhatsApp bridge with YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp) *[Lire ce readme en français.](./README_fr.md)* -> *This package allows you to install Matrix WhatsApp bridge quickly and simply on a YunoHost server. +> *This package allows you to install Matrix-WhatsApp bridge quickly and simply on a YunoHost server. If you don't have YunoHost, please consult [the guide](https://yunohost.org/#/install) to learn how to install it.* ## Overview @@ -28,14 +28,14 @@ Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) ## Disclaimers / important information -### List of known public services +## List of known public services * Ask on one of the following rooms: #mautrix_yunohost:matrix.fdn.fr or #whatsapp:maunium.net -### Bridging usage +## Bridging usage ** Note that several WhatsApp and Matrix users can be bridged, each WhatsApp account has its own bot administration room. If they are in a same WhatsApp group, only one matrix room will be created. ** -#### Bridge a WhatsApp user and a Matrix user +### Bridge a WhatsApp user and a Matrix user * First your matrix user or server has to be authorized in the bridge configuration (see below) * Then, invite the bot (default @whatsappbot:yoursynapse.domain) * The room with the Mautrix-WhatsApp bot is called "administration room". @@ -44,7 +44,7 @@ Therefore, [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_ynh) * Send ``help`` to the bot in the created room to know how to control the bot. See also [upstream wiki Authentication page](https://docs.mau.fi/bridges/go/whatsapp/authentication.html) -#### Bridge an existing room | Bridge Whatsapp to Signal over Matrix +### Bridge an existing room | Bridge Whatsapp to Signal over Matrix By default, the bridge creates a portal room for each WA group that the WA user actively uses. Your can also create a portal for an existing Matrix room. **Note that this can be a room created by another bridge, e.g. a Signal portal room** 1. Invite the bridge bot to the room (with an authorized user) @@ -53,7 +53,7 @@ Your can also create a portal for an existing Matrix room. **Note that this can 4. Get the WA invite link `!wa invite-link` and share it with friends. Or invite Whatsapp puppets to room. 5. Optional: Activate relaybot, see next section. -#### Relaybot: Bridge a group for several Matrix and several WhatsApp users to chat together +### Relaybot: Bridge a group for several Matrix and several WhatsApp users to chat together **When upgrading from -# Matrix WhatsApp bridge pour YunoHost +# Matrix-WhatsApp bridge pour YunoHost [![Niveau d'intégration](https://dash.yunohost.org/integration/mautrix_whatsapp.svg)](https://dash.yunohost.org/appci/app/mautrix_whatsapp) ![Statut du fonctionnement](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.status.svg) ![Statut de maintenance](https://ci-apps.yunohost.org/ci/badges/mautrix_whatsapp.maintain.svg) -[![Installer Matrix WhatsApp bridge avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp) +[![Installer Matrix-WhatsApp bridge avec YunoHost](https://install-app.yunohost.org/install-with-yunohost.svg)](https://install-app.yunohost.org/?app=mautrix_whatsapp) *[Read this readme in english.](./README.md)* -> *Ce package vous permet d'installer Matrix WhatsApp bridge rapidement et simplement sur un serveur YunoHost. +> *Ce package vous permet d'installer Matrix-WhatsApp bridge rapidement et simplement sur un serveur YunoHost. Si vous n'avez pas YunoHost, regardez [ici](https://yunohost.org/#/install) pour savoir comment l'installer et en profiter.* ## Vue d'ensemble @@ -28,14 +28,14 @@ C'est pourquoi [Synapse for YunoHost](https://github.com/YunoHost-Apps/synapse_y ## Avertissements / informations importantes -### Liste de passerelles publiques +## Liste de passerelles publiques * Demandez sur un des salons suivants: #mautrix_yunohost:matrix.fdn.fr or #whatsapp:maunium.net -### Usages de la passerelle +## Usages de la passerelle ** Notez que plusieurs comptes WhatsApp et Matrix peuvent être relayés, chaque compte WhatsApp connecté a son propre Salon d'Administration. Si plusieurs utilisateur.ice.s du Robot sont dans un même groupe WhatsApp, seul un Salon Matrix sera créé par la passerelle. ** -#### Relayer TOUTES les conversations entre UN compte WhatsApp et UN compte Matrix +### Relayer TOUTES les conversations entre UN compte WhatsApp et UN compte Matrix * Prérequis : votre compte Matrix ou le serveur sur lequel il est hébergé doit être autorisé dans la configuration de la passerelle (voir ci-dessous) * Invitez le Robot (par défaut @whatsappbot:synapse.votredomaine) à une nouvelle conversation. * Ce nouveau salon d'administration du Robot Mautrix-WhatsApp est appelé "Administration Room". diff --git a/check_process b/check_process index 60e492a..8e8ca52 100644 --- a/check_process +++ b/check_process @@ -1,7 +1,7 @@ ;; 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_public=$is_public&jitsi_server=$jitsi_server" --force + 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" @@ -17,10 +17,15 @@ setup_private=0 setup_public=0 upgrade=1 + # 0.3.0 upgrade=1 from_commit=42df5b910927283241e185dcb8a62089adeb9c85 + # 0.2.4 upgrade=1 from_commit=23cd51919e2b09865256a21214865d798bd843f6 backup_restore=1 multi_instance=1 +;;; Options +Email= +Notification=none ;;; Upgrade options ; commit=42df5b910927283241e185dcb8a62089adeb9c85 name=0.3.0 diff --git a/conf/config.yaml b/conf/config.yaml index 71b538b..d28ee26 100644 --- a/conf/config.yaml +++ b/conf/config.yaml @@ -1,10 +1,8 @@ -# Homeserver details. +# Homeserver details homeserver: # The address that this appservice can use to connect to the homeserver. - #address: https://example.com address: https://__DOMAIN__ # The domain of the homeserver (for MXIDs, etc). - #domain: example.com domain: __SERVER_NAME__ # Is the homeserver actually mautrix-asmux? @@ -22,12 +20,10 @@ homeserver: # Changing these values requires regeneration of the registration. appservice: # The address that the homeserver can use to connect to this appservice. - #address: http://localhost:29318 address: http://localhost:__PORT__ # The hostname and port where this appservice should listen. hostname: 0.0.0.0 - #port: 29318 port: __PORT__ # Database config. @@ -392,7 +388,7 @@ bridge: # Whether relay mode should be allowed. If allowed, `!wa set-relay` can be used to turn any # authenticated user into a relaybot for that chat. #enabled: false - enabled: __ENABLE_RELAYBOT__ + enabled: true # Should only admins be allowed to set themselves as relay users? admin_only: true # The formats to use when sending messages to WhatsApp via the relaybot. @@ -423,4 +419,4 @@ logging: timestamp_format: "Jan _2, 2006 15:04:05" # Minimum severity for log messages printed to stdout/stderr. This doesn't affect the log file. # Options: debug, info, warn, error, fatal - print_level: __LOG_LEVEL__ + print_level: INFO diff --git a/conf/systemd.service b/conf/systemd.service index 90371cb..c16a18b 100644 --- a/conf/systemd.service +++ b/conf/systemd.service @@ -1,18 +1,18 @@ [Unit] -Description=Matrix-Whatsapp Bridge +Description=Matrix Whatsapp Bridge After=matrix-synapse.service [Service] Type=simple User=__APP__ Group=__APP__ -WorkingDirectory=/opt/yunohost/__APP__ -ExecStart=/opt/yunohost/__APP__/mautrix-whatsapp -c=/opt/yunohost/__APP__/config.yaml >> /var/log/__APP__/__APP__.log 2>&1 +WorkingDirectory=__FINALPATH__/ +ExecStart=__FINALPATH__/mautrix-whatsapp -c=__FINALPATH__/config.yaml >> /var/log/__APP__/__APP__.log 2>&1 Restart=always RestartSec=3 # Optional hardening to improve security -ReadWritePaths=/opt/yunohost/__APP__ +ReadWritePaths=__FINALPATH__/ NoNewPrivileges=yes MemoryDenyWriteExecute=true PrivateDevices=yes diff --git a/doc/DISCLAIMER.md b/doc/DISCLAIMER.md index 8e82a1b..c64e70e 100644 --- a/doc/DISCLAIMER.md +++ b/doc/DISCLAIMER.md @@ -1,11 +1,11 @@ -### List of known public services +## List of known public services * Ask on one of the following rooms: #mautrix_yunohost:matrix.fdn.fr or #whatsapp:maunium.net -### Bridging usage +## Bridging usage ** Note that several WhatsApp and Matrix users can be bridged, each WhatsApp account has its own bot administration room. If they are in a same WhatsApp group, only one matrix room will be created. ** -#### Bridge a WhatsApp user and a Matrix user +### Bridge a WhatsApp user and a Matrix user * First your matrix user or server has to be authorized in the bridge configuration (see below) * Then, invite the bot (default @whatsappbot:yoursynapse.domain) * The room with the Mautrix-WhatsApp bot is called "administration room". @@ -14,7 +14,7 @@ * Send ``help`` to the bot in the created room to know how to control the bot. See also [upstream wiki Authentication page](https://docs.mau.fi/bridges/go/whatsapp/authentication.html) -#### Bridge an existing room | Bridge Whatsapp to Signal over Matrix +### Bridge an existing room | Bridge Whatsapp to Signal over Matrix By default, the bridge creates a portal room for each WA group that the WA user actively uses. Your can also create a portal for an existing Matrix room. **Note that this can be a room created by another bridge, e.g. a Signal portal room** 1. Invite the bridge bot to the room (with an authorized user) @@ -23,7 +23,7 @@ Your can also create a portal for an existing Matrix room. **Note that this can 4. Get the WA invite link `!wa invite-link` and share it with friends. Or invite Whatsapp puppets to room. 5. Optional: Activate relaybot, see next section. -#### Relaybot: Bridge a group for several Matrix and several WhatsApp users to chat together +### Relaybot: Bridge a group for several Matrix and several WhatsApp users to chat together **When upgrading from /dev/null then - ynh_script_progression --message="Removing $app service..." --weight=3 + ynh_script_progression --message="Removing $app service integration..." --weight=3 yunohost service remove $app fi @@ -53,13 +46,21 @@ ynh_script_progression --message="Stopping and removing the systemd service..." # Remove the dedicated systemd config ynh_remove_systemd_config +#================================================= +# REMOVE LOGROTATE CONFIGURATION +#================================================= +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 + +# Remove the app-specific logrotate config +ynh_remove_logrotate + #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= ynh_script_progression --message="Removing the PostgreSQL database..." --weight=4 # Remove a database if it exists, along with the associated user -ynh_psql_remove_db --db_user=$db_name --db_name=$db_name +ynh_psql_remove_db --db_user=$db_user --db_name=$db_name ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$app"";" ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$bot_synapse_db_user"";" ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$botname"";" @@ -68,6 +69,14 @@ ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER ""$bot_syn ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER ""$botname"";" #yunohost app action run $synapse_instance drop_user -a username=$botname +#================================================= +# 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 #================================================= @@ -76,32 +85,16 @@ ynh_script_progression --message="Removing dependencies..." --weight=8 # 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" - -#================================================= -# REMOVE LOGROTATE CONFIGURATION -#================================================= -ynh_script_progression --message="Removing logrotate configuration..." --weight=1 - -# Remove the app-specific logrotate config -ynh_remove_logrotate - #================================================= # SPECIFIC REMOVE #================================================= -ynh_script_progression --message="Removing synapse app service..." --weight=6 +# REMOVE VARIOUS FILES +#================================================= +ynh_script_progression --message="Removing various files..." --weight=6 # Remove a directory securely ynh_secure_remove --file="/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" +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die --message="Synapse can't restart with the appservice configuration" # Remove the log files ynh_secure_remove --file="/var/log/$app" diff --git a/scripts/restore b/scripts/restore index 9bea70f..f492440 100755 --- a/scripts/restore +++ b/scripts/restore @@ -6,7 +6,7 @@ # IMPORT GENERIC HELPERS #================================================= -#Keep this path for calling _common.sh inside the execution's context of backup and restore scripts +# Keep this path for calling _common.sh inside the execution's context of backup and restore scripts source ../settings/scripts/_common.sh source /usr/share/yunohost/helpers @@ -15,7 +15,6 @@ source /usr/share/yunohost/helpers #================================================= ynh_clean_setup () { - #### Remove this function if there's nothing to clean before calling the remove script. true } # Exit if an error occurs during the execution of the script @@ -24,11 +23,13 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --weight=5 +ynh_script_progression --message="Loading installation settings..." --weight=5 app=$YNH_APP_INSTANCE_NAME 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 domain=$(ynh_app_setting_get --app=$app --key=domain) server_name=$(ynh_app_setting_get --app=$app --key=server_name) botname=$(ynh_app_setting_get --app=$app --key=botname) @@ -39,16 +40,6 @@ botusers=$(ynh_app_setting_get --app=$app --key=botusers) botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) previous_mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) port=$(ynh_app_setting_get --app=$app --key=port) - -db_name=$(ynh_app_setting_get --app=$app --key=db_name) -db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - -mautrix_version=$(ynh_app_upstream_version) - -#================================================= -# SET CONSTANTS -#================================================= - synapse_db_name="matrix_$synapse_instance" bot_synapse_db_user="@$botname:$server_name" @@ -57,7 +48,8 @@ bot_synapse_db_user="@$botname:$server_name" #================================================= ynh_script_progression --message="Validating restoration parameters..." --weight=1 -test ! -d $final_path || ynh_die --message="There is already a directory: $final_path " +test ! -d $final_path \ + || ynh_die --message="There is already a directory: $final_path " #================================================= # STANDARD RESTORATION STEPS @@ -66,9 +58,8 @@ test ! -d $final_path || ynh_die --message="There is already a directory: $final #================================================= ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 -# 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 -ynh_system_user_create --username=$app --home_dir=/opt/yunohost/$app +# Create the dedicated user (if not existing) +ynh_system_user_create --username=$app --home_dir="$final_path" #================================================= # RESTORE THE APP MAIN DIR @@ -77,21 +68,18 @@ ynh_script_progression --message="Restoring the app main directory..." --weight= ynh_restore_file --origin_path="$final_path" -#================================================= -# RESTORE USER RIGHTS -#================================================= - -# Restore permissions on app files chmod 750 "$final_path" -chown $app:$app "$final_path" chmod -R 750 "$final_path" chown -R $app:$app "$final_path" +#================================================= +# SPECIFIC RESTORATION #================================================= # REINSTALL DEPENDENCIES #================================================= ynh_script_progression --message="Reinstalling dependencies..." --weight=100 +# Define and install dependencies ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies #================================================= @@ -100,18 +88,17 @@ ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8 ynh_psql_test_if_first_run -ynh_psql_setup_db --db_user=$db_name --db_name=$db_name --db_pwd=$db_pwd -ynh_psql_execute_file_as_root --file="./db.sql" --database="$db_name" +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 -#================================================= -# SPECIFIC RESTORATION #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= +ynh_script_progression --message="Registering Synapse app-service" --weight=1 $final_path/mautrix-whatsapp -g -c $final_path/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" +/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh || ynh_die "Synapse can't restart with the appservice configuration" #================================================= # RESTORE SYSTEMD @@ -124,24 +111,23 @@ systemctl enable $app.service --quiet #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= +ynh_script_progression --message="Restoring the logrotate configuration..." --weight=1 -ynh_use_logrotate --logfile "/var/log/$app/$app.log" --nonappend --specific_user $app/$app -chmod -R 600 "/var/log/$app" -chmod 700 "/var/log/$app" -chown -R $app:$app /var/log/$app +ynh_restore_file --origin_path="/etc/logrotate.d/$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" +yunohost service add $app --description="$app daemon for bridging Whatsapp and Matrix messages" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=30 +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" # Wait until the synapse user is created sleep 30 diff --git a/scripts/upgrade b/scripts/upgrade index aac2b86..129c270 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -16,41 +16,51 @@ ynh_script_progression --message="Loading installation settings..." --weight=5 app=$YNH_APP_INSTANCE_NAME -domain=$(ynh_app_setting_get --app=$app --key=domain) -server_name=$(ynh_app_setting_get --app=$app --key=server_name) -port=$(ynh_app_setting_get --app=$app --key=port) botname=$(ynh_app_setting_get --app=$app --key=botname) -synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) encryption=$(ynh_app_setting_get --app=$app --key=encryption) -botusers=$(ynh_app_setting_get --app=$app --key=botusers) botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) +botusers=$(ynh_app_setting_get --app=$app --key=botusers) +domain=$(ynh_app_setting_get --app=$app --key=domain) final_path=$(ynh_app_setting_get --app=$app --key=final_path) -previous_mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) - -#db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - -mautrix_version=$(ynh_app_upstream_version) -architecture=$YNH_ARCH - -#================================================= -# SET CONSTANTS -#================================================= - -enable_relaybot="true" -# Options: debug, info, warn, error, fatal -log_level="error" -#log_format="$app.log" - +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$db_name +db_pwd=$(ynh_app_setting_get --app=$app --key=psqlpwd) +port=$(ynh_app_setting_get --app=$app --key=port) +synapse_instance=$(ynh_app_setting_get --app=$app --key=synapse_instance) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) synapse_db_name="matrix_$synapse_instance" bot_synapse_db_user="@$botname:$server_name" #================================================= # 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=10 + +# 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 + +#================================================= +# STANDARD UPGRADE STEPS +#================================================= +# STOP SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Stopping a systemd service..." --weight=1 + +ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" + #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= @@ -99,36 +109,6 @@ fi # ynh_app_setting_set --app=$app --key=final_path --value=$final_path #fi -#================================================= -# BACKUP BEFORE UPGRADE THEN ACTIVE TRAP -#================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --weight=10 - -# 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 - -#================================================= -# STANDARD UPGRADE STEPS -#================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" - -#================================================= -# UPGRADE DEPENDENCIES -#================================================= -ynh_script_progression --message="Upgrading dependencies..." --weight=100 - -ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies - #================================================= # CREATE DEDICATED USER #================================================= @@ -137,9 +117,9 @@ ynh_script_progression --message="Making sure dedicated system user exists..." - # 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 /opt/yunohost/$app $app + usermod --home "$final_path" $app else - ynh_system_user_create --username=$app --home_dir=/opt/yunohost/$app + ynh_system_user_create --username=$app --home_dir="$final_path" fi #================================================= @@ -151,29 +131,45 @@ then ynh_script_progression --message="Upgrading source files..." --weight=2 # Download, check integrity, uncompress and patch the source from app.src - ynh_setup_source --dest_dir="$final_path" --source_id=$architecture - chmod 750 $final_path - chown $app:$app $final_path + ynh_setup_source --dest_dir="$final_path" --source_id=$YNH_ARCH fi -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -### Verify the checksum of a file, stored by `ynh_store_file_checksum` in the install script. -### And create a backup of this file if the checksum is different. So the file will be backed up if the admin had modified it. -ynh_backup_if_checksum_is_different --file="$final_path/config.yaml" -ynh_backup_if_checksum_is_different --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" - -#================================================= -# UPDATE CONFIGURATION -#================================================= -ynh_script_progression --message="Configuring Mautrix Bridge..." --weight=2 - -ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml" +chmod 750 "$final_path" chmod -R 750 "$final_path" chown -R $app:$app "$final_path" +#================================================= +# UPGRADE DEPENDENCIES +#================================================= +ynh_script_progression --message="Upgrading dependencies..." --weight=100 + +ynh_exec_warn_less ynh_install_app_dependencies $pkg_dependencies + +#================================================= +# SPECIFIC UPGRADE +#================================================= +# UPDATE A CONFIG FILE +#================================================= +ynh_script_progression --message="Updating a configuration file..." --weight=2 + +ynh_add_config --template="../conf/config.yaml" --destination="$final_path/config.yaml" + +chmod 400 "$final_path/config.yaml" +chown $app:$app "$final_path/config.yaml" + +#================================================= +# REGISTER SYNAPSE APP-SERVICE +#================================================= +ynh_script_progression --message="Registering Synapse app-service" --weight=1 + +$final_path/mautrix-whatsapp -g -c $final_path/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" + +# Set permissions on app files +chown -R $app:$app "$final_path" +ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" +ynh_store_file_checksum --file="$final_path/config.yaml" + #================================================= # SETUP SYSTEMD #================================================= @@ -182,23 +178,6 @@ ynh_script_progression --message="Upgrading systemd configuration..." --weight=4 # Create a dedicated systemd config ynh_add_systemd_config -#================================================= -# REGISTER SYNAPSE APP-SERVICE -#================================================= -$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r /etc/matrix-$synapse_instance/app-service/$app.yaml - -#Add the path to the registration file (registration.yaml by default) to your synapse homeserver.yaml under app_service_config_files. -/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh \ - || ynh_die "Synapse can't restart with the appservice configuration" - -#================================================= -# STORE THE CONFIG FILE CHECKSUM -#================================================= - -# Recalculate and store the checksum of the file for the next upgrade. -ynh_store_file_checksum --file="$final_path/config.yaml" -ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" - #================================================= # GENERIC FINALIZATION #================================================= @@ -217,14 +196,14 @@ chown -R $app:$app /var/log/$app #================================================= 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" +yunohost service add $app --description="$app daemon for bridging Whatsapp and Matrix messages" --log="/var/log/$app/$app.log" #================================================= # START SYSTEMD SERVICE #================================================= ynh_script_progression --message="Starting a systemd service..." --weight=1 -chown -R $app:$app "$final_path" +# Start a systemd service ynh_systemd_action --service_name=$app --action="start" #================================================= 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] diff --git a/sources/patches/.gitignore b/sources/patches/.gitignore deleted file mode 100644 index 783a4ae..0000000 --- a/sources/patches/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -*.sw[op]