From ffc4b04d07f68a64dcd9a928b41de81196f0f4cb Mon Sep 17 00:00:00 2001 From: Gredin67 <35761345+Gredin67@users.noreply.github.com> Date: Tue, 5 Jan 2021 23:30:04 +0100 Subject: [PATCH] Upgrade to 0.1.5 and improve package (#22) * upgrade to upstream 0.1.5 * Update upgrade * add weights upgrade * Update manifest.json * Update remove * actually erase whatsappbot data in synapse_db * Update restore * use stored password in restore * Update backup * do not restart service in backup * add ffmpeg * Update install * syntax sql query * Create config.yaml * use __PARAM__ for mautrix config * advertise service in upgrade --- conf/app.src | 4 +- conf/config.yaml | 275 +++++++++++++++++++++++++++++++++++++++++++++ manifest.json | 32 ++---- scripts/_common.sh | 2 +- scripts/backup | 24 +--- scripts/install | 183 ++++++++---------------------- scripts/remove | 24 ++-- scripts/restore | 86 +++++++------- scripts/upgrade | 47 +++++--- 9 files changed, 422 insertions(+), 255 deletions(-) create mode 100644 conf/config.yaml diff --git a/conf/app.src b/conf/app.src index f82591e..afeb50e 100644 --- a/conf/app.src +++ b/conf/app.src @@ -1,5 +1,5 @@ - SOURCE_URL=https://github.com/tulir/mautrix-whatsapp/archive/v0.1.4.zip -SOURCE_SUM=341e7d39dc5bcfb257e7a3793a5b2a00fed3f9a0a9c3695e0bd987ef3da2ffbd + SOURCE_URL=https://github.com/tulir/mautrix-whatsapp/archive/v0.1.5.zip +SOURCE_SUM=5e05d1a21e6766912f72391232e852e953f8fdcabc8d569fba2b84d3636abe32 SOURCE_SUM_PRG=sha256sum SOURCE_FORMAT=zip SOURCE_IN_SUBDIR=true diff --git a/conf/config.yaml b/conf/config.yaml new file mode 100644 index 0000000..4153d38 --- /dev/null +++ b/conf/config.yaml @@ -0,0 +1,275 @@ +# From v0.1.5 https://github.com/tulir/mautrix-whatsapp/blob/master/example-config.yaml +# Homeserver details. +homeserver: + # The address that this appservice can use to connect to the homeserver. + #address: https://example.com + address: __DOMAIN__ + # The domain of the homeserver (for MXIDs, etc). + #domain: example.com + domain: __SERVER_NAME__ + +# Application service host/registration related details. +# 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. + database: + # The database type. "sqlite3" and "postgres" are supported. + #type: sqlite3 + type: postgres + # The database URI. + # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string + # Postgres: Connection string. For example, postgres://user:password@host/database?sslmode=disable + #uri: mautrix-whatsapp.db + uri: postgres://__MAUTRIX_WHATSAPP_USER__:__MAUTRIX_WHATSAPP_DB_PWD__@localhost:5432/__MAUTRIX_WHATSAPP_DB_NAME__ + # Maximum number of connections. Mostly relevant for Postgres. + max_open_conns: 20 + max_idle_conns: 2 + + # Settings for provisioning API + provisioning: + # Prefix for the provisioning API paths. + prefix: /_matrix/provision/v1 + # Shared secret for authentication. If set to "disable", the provisioning API will be disabled. + shared_secret: disable + + # The unique ID of this appservice. + #id: whatsapp + id: __WHATSAPPBOT__ + # Appservice bot details. + bot: + # Username of the appservice bot. + #username: whatsappbot + username: __WHATSAPPBOT__ + # Display name and avatar for bot. Set to "remove" to remove display name/avatar, leave empty + # to leave display name/avatar as-is. + displayname: WhatsApp bridge bot + avatar: mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr + + # Authentication tokens for AS <-> HS communication. Autogenerated; do not modify. + as_token: "This value is generated when generating the registration" + hs_token: "This value is generated when generating the registration" + +metrics: + # Whether or not to enable prometheus metrics + enabled: false + # IP and port where the metrics listener should be. The path is always /metrics + listen: 127.0.0.1:8001 + +whatsapp: + # Device name that's shown in the "WhatsApp Web" section in the mobile app. + os_name: Mautrix-WhatsApp bridge + # Browser name that determines the logo shown in the mobile app. If the name is unrecognized, a generic icon is shown. + # Use the name of an actual browser (Chrome, Firefox, Safari, IE, Edge, Opera) if you want a specific icon. + browser_name: mx-wa + +# Bridge config +bridge: + # Localpart template of MXIDs for WhatsApp users. + # {{.}} is replaced with the phone number of the WhatsApp user. + username_template: whatsapp_{{.}} + # Displayname template for WhatsApp users. + # {{.Notify}} - nickname set by the WhatsApp user + # {{.Jid}} - phone number (international format) + # The following variables are also available, but will cause problems on multi-user instances: + # {{.Name}} - display name from contact list + # {{.Short}} - short display name from contact list + # To use multiple if's, you need to use: {{else if .Name}}, for example: + # "{{if .Notify}}{{.Notify}}{{else if .Name}}{{.Name}}{{else}}{{.Jid}}{{end}} (WA)" + displayname_template: "{{if .Notify}}{{.Notify}}{{else}}{{.Jid}}{{end}} (WA)" + # Localpart template for per-user room grouping community IDs. + # On startup, the bridge will try to create these communities, add all of the specific user's + # portals to the community, and invite the Matrix user to it. + # (Note that, by default, non-admins might not have your homeserver's permission to create + # communities.) + # {{.Localpart}} is the MXID localpart and {{.Server}} is the MXID server part of the user. + community_template: whatsapp_{{.Localpart}}={{.Server}} + + # WhatsApp connection timeout in seconds. + connection_timeout: 20 + # If WhatsApp doesn't respond within connection_timeout, should the bridge try to fetch the message + # to see if it was actually bridged? Use this if you have problems with sends timing out but actually + # succeeding. + fetch_message_on_timeout: false + # Whether or not the bridge should send a read receipt from the bridge bot when a message has been + # sent to WhatsApp. If fetch_message_on_timeout is enabled, a successful post-timeout fetch will + # trigger a read receipt too. + delivery_receipts: false + # Number of times to regenerate QR code when logging in. + # The regenerated QR code is sent as an edit and essentially multiplies the login timeout (20 seconds) + login_qr_regen_count: 2 + # Maximum number of times to retry connecting on connection error. + max_connection_attempts: 3 + # Number of seconds to wait between connection attempts. + # Negative numbers are exponential backoff: -connection_retry_delay + 1 + 2^attempts + connection_retry_delay: -1 + # Whether or not the bridge should send a notice to the user's management room when it retries connecting. + # If false, it will only report when it stops retrying. + report_connection_retry: true + # Maximum number of seconds to wait for chats to be sent at startup. + # If this is too low and you have lots of chats, it could cause backfilling to fail. + chat_list_wait: 30 + # Maximum number of seconds to wait to sync portals before force unlocking message processing. + # If this is too low and you have lots of chats, it could cause backfilling to fail. + portal_sync_wait: 600 + user_message_buffer: 1024 + portal_message_buffer: 128 + + # Whether or not to send call start/end notices to Matrix. + call_notices: + start: true + end: true + + # Number of chats to sync for new users. + initial_chat_sync_count: 10 + # Number of old messages to fill when creating new portal rooms. + initial_history_fill_count: 20 + # Whether or not notifications should be turned off while filling initial history. + # Only applicable when using double puppeting. + initial_history_disable_notifications: false + # Maximum number of chats to sync when recovering from downtime. + # Set to -1 to sync all new chats during downtime. + recovery_chat_sync_limit: -1 + # Whether or not to sync history when recovering from downtime. + recovery_history_backfill: true + # Maximum number of seconds since last message in chat to skip + # syncing the chat in any case. This setting will take priority + # over both recovery_chat_sync_limit and initial_chat_sync_count. + # Default is 3 days = 259200 seconds + sync_max_chat_age: 259200 + + # Whether or not to sync with custom puppets to receive EDUs that + # are not normally sent to appservices. + sync_with_custom_puppets: true + # Whether or not to update the m.direct account data event when double puppeting is enabled. + # Note that updating the m.direct event is not atomic (except with mautrix-asmux) + # and is therefore prone to race conditions. + sync_direct_chat_list: false + # When double puppeting is enabled, users can use `!wa toggle` to change whether or not + # presence and read receipts are bridged. These settings set the default values. + # Existing users won't be affected when these are changed. + default_bridge_receipts: true + default_bridge_presence: true + # Shared secret for https://github.com/devture/matrix-synapse-shared-secret-auth + # + # If set, custom puppets will be enabled automatically for local users + # instead of users having to find an access token and run `login-matrix` + # manually. + login_shared_secret: null + + # Whether or not to invite own WhatsApp user's Matrix puppet into private + # chat portals when backfilling if needed. + # This always uses the default puppet instead of custom puppets due to + # rate limits and timestamp massaging. + invite_own_puppet_for_backfilling: true + # Whether or not to explicitly set the avatar and room name for private + # chat portal rooms. This can be useful if the previous field works fine, + # but causes room avatar/name bugs. + private_chat_portal_meta: false + # Set this to true to tell the bridge to re-send m.bridge events to all rooms on the next run. + # This field will automatically be changed back to false after it, + # except if the config file is not writable. + resend_bridge_info: false + + # Whether or not thumbnails from WhatsApp should be sent. + # They're disabled by default due to very low resolution. + whatsapp_thumbnail: false + + # Allow invite permission for user. User can invite any bots to room with whatsapp + # users (private chat and groups) + allow_user_invite: false + + # The prefix for commands. Only required in non-management rooms. + command_prefix: "!wa" + + # End-to-bridge encryption support options. This requires login_shared_secret to be configured + # in order to get a device for the bridge bot. + # + # Additionally, https://github.com/matrix-org/synapse/pull/5758 is required if using a normal + # application service. + encryption: + # Allow encryption, work in group chat rooms with e2ee enabled + allow: false + # Default to encryption, force-enable encryption in all portals the bridge creates + # This will cause the bridge bot to be in private chats for the encryption to work properly. + # It is recommended to also set private_chat_portal_meta to true when using this. + default: false + # Options for automatic key sharing. + key_sharing: + # Enable key sharing? If enabled, key requests for rooms where users are in will be fulfilled. + # You must use a client that supports requesting keys from other users to use this feature. + allow: false + # Require the requesting device to have a valid cross-signing signature? + # This doesn't require that the bridge has verified the device, only that the user has verified it. + # Not yet implemented. + require_cross_signing: false + # Require devices to be verified by the bridge? + # Verification by the bridge is not yet implemented. + require_verification: true + + # Permissions for using the bridge. + # Permitted values: + # relaybot - Talk through the relaybot (if enabled), no access otherwise + # user - Access to use the bridge to chat with a WhatsApp account. + # admin - User level and some additional administration tools + # Permitted keys: + # * - All Matrix users + # domain - All users on that homeserver + # mxid - Specific user + permissions: + "*": relaybot + #"example.com": user + "__BOTUSERS__": user + #"@admin:example.com": admin + "__BOTADMIN__": admin + + relaybot: + # Whether or not relaybot support is enabled. + #enabled: false + enabled: __ENABLE_RELAYBOT__ + # The management room for the bot. This is where all status notifications are posted and + # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting + # the command prefix completely like in user management rooms is not possible. + #management: "!foo:example.com" + management: "!__RELAYBOT_MANAGEMENT_ROOM__:__SERVER_NAME__" + # List of users to invite to all created rooms that include the relaybot. + #invites: [] + invites: + - "__RELAYBOT_INVITE__" + # The formats to use when sending messages to WhatsApp via the relaybot. + message_formats: + m.text: "{{ .Sender.Displayname }}: {{ .Message }}" + m.notice: "{{ .Sender.Displayname }}: {{ .Message }}" + m.emote: "* {{ .Sender.Displayname }} {{ .Message }}" + m.file: "{{ .Sender.Displayname }} sent a file" + m.image: "{{ .Sender.Displayname }} sent an image" + m.audio: "{{ .Sender.Displayname }} sent an audio file" + m.video: "{{ .Sender.Displayname }} sent a video" + m.location: "{{ .Sender.Displayname }} sent a location" + +# Logging config. +logging: + # The directory for log files. Will be created if not found. + #directory: ./logs + directory: /var/log/__APP__ + # Available variables: .Date for the file date and .Index for different log files on the same day. + #file_name_format: "{{.Date}}-{{.Index}}.log" + file_name_format: "__LOG_FORMAT__" + # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants + #file_date_format: 2006-01-02 + # Log file permissions. + file_mode: 0600 + # Timestamp format for log entries in the Go time format. + timestamp_format: Jan _2, 2006 15:04:05 + # Minimum severity for log messages. + # Options: debug, info, warn, error, fatal + #print_level: debug + print_level: __LOG_LEVEL__ diff --git a/manifest.json b/manifest.json index e470d09..95ffe39 100644 --- a/manifest.json +++ b/manifest.json @@ -6,13 +6,13 @@ "en": "A WhatsApp puppeting bridge for Matrix/Synapse.", "fr": "Passerelle WhatsApp pour Matrix/Synapse." }, - "version": "0.1.4~ynh1", + "version": "0.1.5~ynh1", "url": "https://github.com/tulir/mautrix-whatsapp", "license": "AGPL-3.0-or-later", "maintainer": { "name": "Gredin67", - "email": "mautrix_whatsapp@neutralite.org", - "url": "https://github.com/Gredin67/mautrix_whatsapp_ynh" + "email": "mautrix_whatsapp_ynh@sans-nuage.fr", + "url": "https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh" }, "requirements": { "yunohost": ">= 4.0" @@ -23,20 +23,6 @@ ], "arguments": { "install": [ - { - "name": "port", - "type": "string", - "ask": { - "en": "Choose a port for the app service mautrix_whatsapp", - "fr": "Choisissez un port pour le service d'application mautrix_whatsapp" - }, - "example": "29318", - "help": { - "en": "Choose a port for communication between your local synapse instance (home server) and its app service mautrix_whatsapp.", - "fr": "Choisissez un port pour la communication entre votre instance synapse locale (home server) et son service d'application mautrix_whatsapp." - }, - "default": "8449" - }, { "name": "synapsenumber", "type": "string", @@ -67,25 +53,25 @@ }, { "name": "bot_is_synapse_admin", - "type": "string", + "type": "boolean", "ask": { "en": "Give the WhatsApp bot administrator rights to the synapse instance?", "fr": "Donner au robot WhatsApp des droits administrateur à l'instance synapse ?" }, "help": { - "en": "If Yes, the bot can group WhatsApp chats in a Matrix community. Not required if you set up synapse so that non-admins are authorized to create communities.", - "fr": "Si Yes, le robot grouppera les conversations WhatsApp dans une communauté Matrix. Pas nécessaire si vous avez réglé synapse pour qu'il autorise les non-admin à créer des communautés." + "en": "If true, the bot can group WhatsApp chats in a Matrix community. Not required if you set up synapse so that non-admins are authorized to create communities.", + "fr": "Si true, le robot groupera les conversations WhatsApp dans une communauté Matrix. Pas nécessaire si vous avez réglé synapse pour qu'il autorise les non-admin à créer des communautés." }, - "default": "Yes" + "default": true }, { "name": "encryption", - "type": "bool", + "type": "boolean", "ask": { "en": "Enable end-to-bridge encryption ?", "fr": "Activer le chiffrement entre synapse et le bridge ?" }, - "default": "false" + "default": false }, { "name": "botadmin", diff --git a/scripts/_common.sh b/scripts/_common.sh index 8551544..cb43ea2 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -5,7 +5,7 @@ #================================================= # dependencies used by the app -pkg_dependencies="g++ postgresql" +pkg_dependencies="g++ postgresql ffmpeg" GO_VERSION="1.14" GO_PATH="/usr/lib/go-$GO_VERSION/bin" diff --git a/scripts/backup b/scripts/backup index 5070d20..0eeb9c5 100755 --- a/scripts/backup +++ b/scripts/backup @@ -24,7 +24,7 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=1 app=$YNH_APP_INSTANCE_NAME @@ -35,23 +35,18 @@ mautrix_whatsapp_db_name=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp #================================================= # STANDARD BACKUP STEPS #================================================= -# STOP SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/log.log" #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_script_progression --message="Backing up the main app directory..." --time --weight=1 +ynh_script_progression --message="Backing up the main app directory..." --weight=1 ynh_backup --src_path="$final_path" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Backing up the PostgreSQL database..." --time --weight=1 +ynh_script_progression --message="Backing up the PostgreSQL database..." --weight=1 ynh_psql_dump_db --database="$mautrix_whatsapp_db_name" > ${YNH_CWD}/dump.sql @@ -60,27 +55,20 @@ ynh_psql_dump_db --database="$mautrix_whatsapp_db_name" > ${YNH_CWD}/dump.sql #================================================= # BACKUP LOGROTATE #================================================= -ynh_script_progression --message="Backing up logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Backing up logrotate configuration..." --weight=1 ynh_backup --src_path="/var/log/$app" #================================================= # BACKUP SYSTEMD #================================================= -ynh_script_progression --message="Backing up systemd configuration..." --time --weight=1 +ynh_script_progression --message="Backing up systemd configuration..." --weight=1 #ynh_backup --src_path="/etc/default/$app" ynh_backup --src_path="/etc/systemd/system/$app.service" -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/log.log" - #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --time --last +ynh_script_progression --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." --last diff --git a/scripts/install b/scripts/install index 7ba7a3d..002468c 100755 --- a/scripts/install +++ b/scripts/install @@ -24,7 +24,6 @@ ynh_abort_if_errors # RETRIEVE ARGUMENTS FROM THE MANIFEST #================================================= -port=$YNH_APP_ARG_PORT synapsenumber=$YNH_APP_ARG_SYNAPSENUMBER whatsappbot=$YNH_APP_ARG_WHATSAPPBOT bot_is_synapse_admin=$YNH_APP_ARG_BOT_IS_SYNAPSE_ADMIN @@ -33,6 +32,7 @@ botadmin=$YNH_APP_ARG_BOTADMIN botusers=$YNH_APP_ARG_BOTUSERS app=$YNH_APP_INSTANCE_NAME +final_path=/opt/yunohost/$app # ToDo check (in manifest?) if the selected synapse instance is not already connected to a mautrix_whatsapp bridge if [ $synapsenumber -eq "1" ] @@ -54,6 +54,7 @@ synapse_db_user="matrix_$synapse_instance" # SET CONSTANTS #================================================= +whatsappbot_synapse_db_user="@$whatsappbot:$server_name" mautrix_whatsapp_user=$app mautrix_whatsapp_db_name=$app mautrix_whatsapp_db_user=$app @@ -64,9 +65,18 @@ upstream_version=$(ynh_app_upstream_version) #================================================= ynh_script_progression --message="Validating installation parameters..." --weight=1 -final_path=/opt/yunohost/$app test ! -e "$final_path" || ynh_die --message="This path already contains a folder" +#================================================= +# STANDARD MODIFICATIONS +#================================================= +# FIND AND OPEN A PORT +#================================================= +ynh_script_progression --message="Configuring firewall..." --weight=1 + +# Find a free port for communication between your local synapse instance (home server) and its app service mautrix_whatsapp. +port=$(ynh_find_port --port=8449) + #================================================= # STORE SETTINGS FROM MANIFEST #================================================= @@ -148,7 +158,7 @@ ynh_setup_source --dest_dir="$final_path" #================================================= # BUILD GO #================================================= -ynh_script_progression --message="Build with golang..." --time --weight=194 +ynh_script_progression --message="Build with golang..." --weight=194 # Build mautrix-whatsapp base_directory=$PWD @@ -172,7 +182,7 @@ cd $base_directory #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Configuring system user..." --time --weight=1 +ynh_script_progression --message="Configuring system user..." --weight=1 # Create a system user ynh_system_user_create --username=$mautrix_whatsapp_user @@ -180,7 +190,7 @@ ynh_system_user_create --username=$mautrix_whatsapp_user #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --time --weight=20 +ynh_script_progression --message="Configuring a systemd service..." --weight=20 # Create systemd config for mautrix-whatsapp #cp ../conf/default_mautrix-whatsapp /etc/default/$app @@ -189,145 +199,50 @@ ynh_add_systemd_config --service=$app #================================================= #================================================= -# MODIFY A CONFIG FILE +# SET MAUTRIX-WHATSAPP CONFIG #================================================= +ynh_script_progression --message="Configuring Mautrix-WhatsApp..." --weight=2 + +# Configure Mautrix-WhatsApp + +# WARNING : theses command are used in INSTALL, UPGRADE, CONFIG, CHANGE-URL (4 times) +# For any update do it in all files + +mautrix_config_path="$final_path/config.yaml" #Copy example-config.yaml to config.yaml -cp $final_path/example-config.yaml $final_path/config.yaml +cp ../conf/config.yaml "$mautrix_config_path" -#Update the config to your liking. - #You need to make sure that the address and domain field point to your homeserver. - -# Homeserver details. -#homeserver: - # The address that this appservice can use to connect to the homeserver. - #"address: https://example.com" -ynh_replace_string --match_string="address: https://example.com" --replace_string="address: https://$domain" --target_file="$final_path/config.yaml" - # The domain of the homeserver (for MXIDs, etc). - #"domain: example.com" -ynh_replace_string --match_string="domain: example.com" --replace_string="domain: $server_name" --target_file="$final_path/config.yaml" - -# Application service host/registration related details. -# Changing these values requires regeneration of the registration. -#appservice: - # The address that the homeserver can use to connect to this appservice. -ynh_replace_string --match_string="address: http://localhost:29318" --replace_string="address: http://localhost:$port" --target_file="$final_path/config.yaml" - - # The hostname and port where this appservice should listen. -#ynh_replace_string --match_string="hostname: 0.0.0.0" --replace_string="hostname: 0.0.0.0" --target_file="$final_path/config.yaml" -ynh_replace_string --match_string="port: 29318" --replace_string="port: $port" --target_file="$final_path/config.yaml" - - # Database config. - #database: - # The database type. "sqlite3" and "postgres" are supported. -ynh_replace_string --match_string="type: sqlite3" --replace_string="type: postgres" --target_file="$final_path/config.yaml" - # The database URI. - # SQLite: File name is enough. https://github.com/mattn/go-sqlite3#connection-string - # Postgres: Connection string. For example, postgres://user:password@host/database -ynh_replace_string --match_string="uri: mautrix-whatsapp.db" --replace_string="uri: postgres://$mautrix_whatsapp_user:$mautrix_whatsapp_db_pwd@localhost:5432/$mautrix_whatsapp_db_name" --target_file="$final_path/config.yaml" - - # The unique ID of this appservice. - #id: whatsapp - ynh_replace_string --match_string="id: whatsapp" --replace_string="id: $whatsappbot" --target_file="$final_path/config.yaml" - # Appservice bot details. - #bot: - # Username of the appservice bot. - #username: whatsappbot - ynh_replace_string --match_string="username: whatsappbot" --replace_string="username: $whatsappbot" --target_file="$final_path/config.yaml" -# Bridge config -#bridge: - # Localpart template of MXIDs for WhatsApp users. - # {{.}} is replaced with the phone number of the WhatsApp user. - #username_template: whatsapp_{{.}} - #ynh_replace_string --match_string="username_template: whatsapp" --replace_string="username_template: $whatsappbot" --target_file="$final_path/config.yaml" - # {{.Localpart}} is the MXID localpart and {{.Server}} is the MXID server part of the user. - #community_template: whatsapp_{{.Localpart}}={{.Server}} - #ynh_replace_string --match_string="community_template: whatsapp" --replace_string="community_template: $whatsappbot" --target_file="$final_path/config.yaml" - # Localpart template for per-user room grouping community IDs. - # On startup, the bridge will try to create these communities, add all of the specific user's - # portals to the community, and invite the Matrix user to it. - # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) - - # Maximum number of connections. Mostly relevant for Postgres. -#ynh_replace_string --match_string="max_open_conns: 20" --replace_string="max_open_conns: 20" --target_file="$final_path/config.yaml" -#ynh_replace_string --match_string="max_idle_conns: 2" --replace_string="max_idle_conns: 2" --target_file="$final_path/config.yaml" - - #You will also need to add your user of admin user under the permissions section. - # Permissions for using the bridge. - # Permitted values: - # relaybot - Talk through the relaybot (if enabled), no access otherwise - # user - Access to use the bridge to chat with a WhatsApp account. - # admin - User level and some additional administration tools - # Permitted keys: - # * - All Matrix users - # domain - All users on that homeserver - # mxid - Specific user - #permissions: -# "*": relaybot -#ynh_replace_string --match_string="'*': relaybot" --replace_string="'': relaybot" --target_file="$final_path/config.yaml" -# "@admin:example.com": admin -ynh_replace_string --match_string="@admin:example.com" --replace_string="$botadmin" --target_file="$final_path/config.yaml" -# "example.com": user +ynh_replace_string --match_string=__DOMAIN__ --replace_string="https://$domain" --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__SERVER_NAME__ --replace_string=$server_name --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__PORT__ --replace_string=$port --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__MAUTRIX_WHATSAPP_USER__ --replace_string=$mautrix_whatsapp_user --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__MAUTRIX_WHATSAPP_DB_PWD__ --replace_string=$mautrix_whatsapp_db_pwd --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__MAUTRIX_WHATSAPP_DB_NAME__ --replace_string=$mautrix_whatsapp_db_name --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__WHATSAPPBOT__ --replace_string=$whatsappbot --target_file="$mautrix_config_path" if [ "$botusers" = "local" ] then -ynh_replace_string --match_string="example.com" --replace_string="$server_name" --target_file="$final_path/config.yaml" +ynh_replace_string --match_string=__BOTUSERS__ --replace_string=$server_name --target_file="$mautrix_config_path" elif [ "$botusers" = "admin" ] then -ynh_replace_string --match_string="'example.com': user" --replace_string="#'example.com': user" --target_file="$final_path/config.yaml" +ynh_replace_string --match_string=__BOTUSERS__ --replace_string=$botadmin --target_file="$mautrix_config_path" else -ynh_replace_string --match_string="example.com" --replace_string="$botusers" --target_file="$final_path/config.yaml" +ynh_replace_string --match_string=__BOTUSERS__ --replace_string=$botusers --target_file="$mautrix_config_path" fi - - -# relaybot: -# # Whether or not relaybot support is enabled. -# enabled: false -ynh_replace_string --match_string="enabled: false" --replace_string="enabled: true" --target_file="$final_path/config.yaml" -# # The management room for the bot. This is where all status notifications are posted and -# # in this room, you can use `!wa ` instead of `!wa relaybot `. Omitting -# # the command prefix completely like in user management rooms is not possible. -# management: !foo:example.com -ynh_replace_string --match_string="management: !foo:example.com" --replace_string="management: !highwaytohell:$server_name" --target_file="$final_path/config.yaml" -# # List of users to invite to all created rooms that include the relaybot. -# invites: [] -#ynh_replace_string --match_string="invites: []" --replace_string='invites: ['"$botadmin"']' --target_file="$final_path/config.yaml" -# # The formats to use when sending messages to WhatsApp via the relaybot. -# message_formats: -# m.text: "{{ .Sender.Displayname }}: {{ .Message }}" -# m.notice: "{{ .Sender.Displayname }}: {{ .Message }}" -# m.emote: "* {{ .Sender.Displayname }} {{ .Message }}" -# m.file: "{{ .Sender.Displayname }} sent a file" -# m.image: "{{ .Sender.Displayname }} sent an image" -# m.audio: "{{ .Sender.Displayname }} sent an audio file" -# m.video: "{{ .Sender.Displayname }} sent a video" -# m.location: "{{ .Sender.Displayname }} sent a location" - -# Logging config. -#logging: - # The directory for log files. Will be created if not found. - #directory: ./logs - ynh_replace_string --match_string="directory: ./logs" --replace_string="directory: /var/log/$app" --target_file="$final_path/config.yaml" - # Available variables: .Date for the file date and .Index for different log files on the same day. - #file_name_format: "{{.Date}}-{{.Index}}.log" - ynh_replace_string --match_string="{{.Date}}-{{.Index}}.log" --replace_string="log.log" --target_file="$final_path/config.yaml" - # Date format for file names in the Go time format: https://golang.org/pkg/time/#pkg-constants - #file_date_format: 2006-01-02 - ynh_replace_string --match_string="file_date_format: 2006-01-02" --replace_string="#file_date_format: 2006-01-02" --target_file="$final_path/config.yaml" - # Log file permissions. - #file_mode: 0600 - #ynh_replace_string --match_string="file_mode: 0600" --replace_string="file_mode: 384" --target_file="$final_path/config.yaml" - # Timestamp format for log entries in the Go time format. - #timestamp_format: Jan _2, 2006 15:04:05 - # Minimum severity for log messages. +ynh_replace_string --match_string=__BOTADMIN__ --replace_string=$botadmin --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__ENABLE_RELAYBOT__ --replace_string="true" --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__RELAYBOT_MANAGEMENT_ROOM__ --replace_string="highwaytohell" --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__RELAYBOT_INVITE__ --replace_string=$botadmin --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__APP__ --replace_string=$app --target_file="$mautrix_config_path" +ynh_replace_string --match_string=__LOG_FORMAT__ --replace_string="log.log" --target_file="$mautrix_config_path" # Options: debug, info, warn, error, fatal - #print_level: debug - ynh_replace_string --match_string="print_level: debug" --replace_string="print_level: warn" --target_file="$final_path/config.yaml" +ynh_replace_string --match_string=__LOG_LEVEL__ --replace_string="error" --target_file="$mautrix_config_path" #cd $final_path #Generate the appservice registration file by running ./mautrix-whatsapp -g. #You can use the -c and -r flags to change the location of the config and registration files. They default to config.yaml and registration.yaml respectively. #mkdir -p $app_service_registration_path -$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_registration_path/$app.yaml +$final_path/mautrix-whatsapp -g -c $mautrix_config_path -r $app_service_registration_path/$app.yaml #Add the path to the registration file (registration.yaml by default) to your synapse homeserver.yaml under app_service_config_files. #cd $base_directory #cp ../conf/$app.yaml $app_service_registration_path @@ -350,7 +265,7 @@ $final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_regis # Calculate and store the config file checksum into the app settings ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" -ynh_store_file_checksum --file="$final_path/config.yaml" +ynh_store_file_checksum --file="$mautrix_config_path" #================================================= # GENERIC FINALIZATION @@ -372,7 +287,7 @@ chown $mautrix_whatsapp_user:root -R $final_path #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --time --weight=3 +ynh_script_progression --message="Configuring log rotation..." --weight=3 # Use logrotate to manage application logfile(s) ynh_use_logrotate --logfile "/var/log/$app/log.log" @@ -388,16 +303,16 @@ yunohost service add $app --description "$app daemon for bridging Whatsapp and M #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 # Start a systemd service ynh_systemd_action --service_name=$app --action="start" # Wait until the synapse user is created sleep 30 # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) - if [ "$bot_is_synapse_admin" = "Yes" ] + if [ "$bot_is_synapse_admin" = true ] then - ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';" + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$whatsappbot"";" #yunohost app action run $synapse_instance set_admin_user -a username=$whatsappbot fi ynh_systemd_action --service_name=$app --action="restart" @@ -406,4 +321,4 @@ ynh_systemd_action --service_name=$app --action="restart" # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --time --last +ynh_script_progression --message="Installation of $app completed" --last diff --git a/scripts/remove b/scripts/remove index a4ce6bb..c42125e 100755 --- a/scripts/remove +++ b/scripts/remove @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=5 app=$YNH_APP_INSTANCE_NAME @@ -32,6 +32,8 @@ final_path=$(ynh_app_setting_get --app=$app --key=final_path) #================================================= src_path=$final_path"_src" +synapse_db_name="matrix_$synapse_instance" +whatsappbot_synapse_db_user="@$whatsappbot:$server_name" mautrix_whatsapp_user=$app mautrix_whatsapp_db_name=$app mautrix_whatsapp_db_user=$app @@ -45,14 +47,14 @@ mautrix_whatsapp_db_user=$app # Remove a service from the admin panel, added by `yunohost service add` if ynh_exec_warn_less yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service..." --time --weight=3 + ynh_script_progression --message="Removing $app service..." --weight=3 yunohost service remove $app fi #================================================= # STOP AND REMOVE SERVICE #================================================= -ynh_script_progression --message="Stopping and removing the systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping and removing the systemd service..." --weight=1 # Remove the dedicated systemd config ynh_remove_systemd_config @@ -60,18 +62,18 @@ ynh_remove_systemd_config #================================================= # REMOVE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Removing the PostgreSQL database..." --time --weight=3 +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=$mautrix_whatsapp_db_name --db_name=$mautrix_whatsapp_db_user -ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY @$whatsappbot:$server_name;" -ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER @$whatsappbot:$server_name;" +ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP OWNED BY ""$whatsappbot"";" +ynh_psql_execute_as_root --database=$synapse_db_name --sql="DROP USER ""$whatsappbot"";" #yunohost app action run $synapse_instance drop_user -a username=$whatsappbot #================================================= # REMOVE DEPENDENCIES #================================================= -ynh_script_progression --message="Removing dependencies..." --time --weight=4 +ynh_script_progression --message="Removing dependencies..." --weight=8 # Remove metapackage and its dependencies ynh_remove_app_dependencies @@ -79,7 +81,7 @@ ynh_remove_app_dependencies #================================================= # REMOVE APP MAIN DIR #================================================= -ynh_script_progression --message="Removing app main directory..." --time --weight=10 +ynh_script_progression --message="Removing app main directory..." --weight=1 # Remove the app directory securely #ynh_secure_remove --file="/etc/$app/" @@ -88,7 +90,7 @@ ynh_secure_remove --file="$final_path" #================================================= # REMOVE LOGROTATE CONFIGURATION #================================================= -ynh_script_progression --message="Removing logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Removing logrotate configuration..." --weight=1 # Remove the app-specific logrotate config ynh_remove_logrotate @@ -96,7 +98,7 @@ ynh_remove_logrotate #================================================= # SPECIFIC REMOVE #================================================= -ynh_script_progression --message="Removing synapse app service..." --time --weight=1 +ynh_script_progression --message="Removing synapse app service..." --weight=6 # Remove a directory securely ynh_secure_remove --file="$src_path" @@ -114,7 +116,7 @@ ynh_secure_remove --file="/var/log/$app" #================================================= # REMOVE DEDICATED USER #================================================= -ynh_script_progression --message="Removing the dedicated system user..." --time --weight=5 +ynh_script_progression --message="Removing the dedicated system user..." --weight=5 # Delete a system user ynh_system_user_delete --username=$mautrix_whatsapp_user diff --git a/scripts/restore b/scripts/restore index b89dba4..ab10cee 100755 --- a/scripts/restore +++ b/scripts/restore @@ -24,12 +24,15 @@ ynh_abort_if_errors #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading settings..." --time --weight=1 +ynh_script_progression --message="Loading settings..." --weight=5 app=$YNH_APP_INSTANCE_NAME +final_path=/opt/yunohost/$app +mautrix_config_path="$final_path/conf.yaml" 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) whatsappbot=$(ynh_app_setting_get --app=$app --key=whatsappbot) 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) @@ -48,17 +51,17 @@ ynh_print_ON #================================================= synapse_db_name="matrix_$synapse_instance" +whatsappbot_synapse_db_user="@$whatsappbot:$server_name" mautrix_whatsapp_user=$app mautrix_whatsapp_db_name=$app mautrix_whatsapp_db_user=$app +upstream_version=$(ynh_app_upstream_version) #================================================= # CHECK IF THE APP CAN BE RESTORED #================================================= -ynh_script_progression --message="Validating restoration parameters..." --time --weight=1 +ynh_script_progression --message="Validating restoration parameters..." --weight=1 -#ynh_webpath_available --domain=$domain --path_url=$path_url \ -# || ynh_die --message="Path not available: ${domain}${path_url}" test ! -d $final_path \ || ynh_die --message="There is already a directory: $final_path " @@ -67,14 +70,14 @@ test ! -d $final_path \ #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --time --weight=1 +ynh_script_progression --message="Restoring the app main directory..." --weight=1 ynh_restore_file --origin_path="$final_path" #================================================= # RECREATE THE DEDICATED USER #================================================= -ynh_script_progression --message="Recreating the dedicated system user..." --time --weight=1 +ynh_script_progression --message="Recreating the dedicated system user..." --weight=1 # Create the dedicated user (if not existing) ynh_system_user_create --username=$app @@ -92,40 +95,30 @@ chown $mautrix_whatsapp_user:root -R $final_path #================================================= # REINSTALL DEPENDENCIES #================================================= -ynh_script_progression --message="Reinstalling dependencies..." --time --weight=1 +ynh_script_progression --message="Reinstalling dependencies..." --weight=100 -ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang" -ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" -# Define and install dependencies ynh_install_app_dependencies $pkg_dependencies +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang-go" +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" + #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --time --weight=1 - -ynh_print_OFF -mautrix_whatsapp_db_pwd=$(ynh_string_random --length=30) -ynh_app_setting_set --app=$app --key=mautrix_whatsapp_db_pwd --value=$mautrix_whatsapp_db_pwd -ynh_print_ON +ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8 ynh_psql_test_if_first_run ynh_print_OFF ynh_psql_create_user $mautrix_whatsapp_db_user $mautrix_whatsapp_db_pwd ynh_print_ON ynh_psql_execute_as_root \ ---sql="CREATE DATABASE $mautrix_whatsapp_db_name - ENCODING 'UTF8' - LC_COLLATE='C' - LC_CTYPE='C' - template=template0 - OWNER $mautrix_whatsapp_db_user;" +--sql="CREATE DATABASE ""$mautrix_whatsapp_db_name"" ENCODING 'UTF8' LC_COLLATE='C' LC_CTYPE='C' template=template0 OWNER ""$mautrix_whatsapp_db_user"";" ynh_psql_execute_file_as_root --file="${YNH_CWD}/dump.sql" --database="$mautrix_whatsapp_db_name" #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= -$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_registration_path/$app.yaml +$final_path/mautrix-whatsapp -g -c $mautrix_config_path -r $app_service_registration_path/$app.yaml #$as_token=; #$hs_token=; #ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file=$app_service_registration_path/$app.yaml @@ -137,33 +130,11 @@ $final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_regis #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --time --weight=1 +ynh_script_progression --message="Restoring the systemd configuration..." --weight=3 ynh_restore_file --origin_path="/etc/systemd/system/$app.service" systemctl enable $app.service -#================================================= -# ADVERTISE SERVICE IN ADMIN PANEL -#================================================= - -yunohost service add $app --log "/var/log/$app/log.log" -# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added -yunohost service add $app --description "$app daemon for bridging Whatsapp and Matrix messages" --log "/var/log/$app/log.log" - -#================================================= -# START SYSTEMD SERVICE -#================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 - -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/log.log" - # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) - if [ "$bot_is_synapse_admin" = "Yes" ] - then - ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';" -# yunohost app action run $synapse_instance set_admin_user -a username=$whatsappbot - fi -ynh_systemd_action --service_name=$app --action="restart" - #================================================= # RESTORE THE LOGROTATE CONFIGURATION #================================================= @@ -172,11 +143,30 @@ ynh_use_logrotate --logfile "/var/log/$app/log.log" chown $mautrix_whatsapp_user:root -R /var/log/$app #================================================= -# GENERIC FINALIZATION +# ADVERTISE SERVICE IN ADMIN PANEL #================================================= +# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added +yunohost service add $app --description "$app daemon for bridging Whatsapp and Matrix messages" --log "/var/log/$app/log.log" + +#================================================= +# START SYSTEMD SERVICE +#================================================= +ynh_script_progression --message="Starting a systemd service..." --weight=30 + +ynh_systemd_action --service_name=$app --action="start" +sleep 30 + # (Note that, by default, non-admins might not have your homeserver's permission to create communities.) + if [ "$bot_is_synapse_admin" = true ] + then + ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$whatsappbot"";" +# yunohost app action run $synapse_instance set_admin_user -a username=$whatsappbot + fi +ynh_systemd_action --service_name=$app --action="restart" + + #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --time --last +ynh_script_progression --message="Restoration completed for $app" --last diff --git a/scripts/upgrade b/scripts/upgrade index 69479a6..b2ae846 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -12,7 +12,7 @@ source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." --weight=5 app=$YNH_APP_INSTANCE_NAME @@ -26,6 +26,7 @@ encryption=$(ynh_app_setting_get --app=$app --key=encryption) botadmin=$(ynh_app_setting_get --app=$app --key=botadmin) botusers=$(ynh_app_setting_get --app=$app --key=botusers) final_path=$(ynh_app_setting_get --app=$app --key=final_path) +mautrix_config_path="$final_path/config.yaml" mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) #================================================= @@ -33,9 +34,11 @@ mautrix_version=$(ynh_app_setting_get --app=$app --key=mautrix_version) #================================================= synapse_db_name="matrix_$synapse_instance" +whatsappbot_synapse_db_user="@$whatsappbot:$server_name" mautrix_whatsapp_user=$app mautrix_whatsapp_db_name=$app mautrix_whatsapp_db_user=$app +upstream_version=$(ynh_app_upstream_version) #================================================= # CHECK VERSION @@ -52,7 +55,7 @@ upgrade_type=$(ynh_check_app_version_changed) #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --time --weight=1 +ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # If db_name doesn't exist, create it if [ -z "$mautrix_whatsapp_db_name" ]; then @@ -69,7 +72,7 @@ fi #================================================= # BACKUP BEFORE UPGRADE THEN ACTIVE TRAP #================================================= -ynh_script_progression --message="Backing up the app before upgrading (may take a while)..." --time --weight=1 +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 @@ -85,9 +88,9 @@ ynh_abort_if_errors #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --time --weight=1 +ynh_script_progression --message="Stopping a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/log.log" +ynh_systemd_action --service_name=$app --action="stop" #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE @@ -95,7 +98,7 @@ ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app if [ "$upgrade_type" == "UPGRADE_APP" ] then - ynh_script_progression --message="Upgrading source files..." --time --weight=1 + 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" @@ -104,12 +107,13 @@ fi #================================================= # UPGRADE DEPENDENCIES #================================================= -ynh_script_progression --message="Upgrading dependencies..." --time --weight=1 +ynh_script_progression --message="Upgrading dependencies..." --weight=100 -ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang" -ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" ynh_install_app_dependencies $pkg_dependencies +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="golang-go" +ynh_install_extra_app_dependencies --repo="http://http.debian.net/debian buster-backports main" --package="libolm-dev" + #================================================= # BUILD GO #================================================= @@ -133,7 +137,7 @@ cd $base_directory #================================================= # CREATE DEDICATED USER #================================================= -ynh_script_progression --message="Making sure dedicated system user exists..." --time --weight=1 +ynh_script_progression --message="Making sure dedicated system user exists..." --weight=8 # Create a dedicated user (if not existing) ynh_system_user_create --username=$mautrix_whatsapp_user @@ -150,13 +154,13 @@ ynh_system_user_create --username=$mautrix_whatsapp_user ### 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="$mautrix_config_path" ynh_backup_if_checksum_is_different --file="$app_service_registration_path/$app.yaml" #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= -$final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_registration_path/$app.yaml +$final_path/mautrix-whatsapp -g -c $mautrix_config_path -r $app_service_registration_path/$app.yaml #$as_token=; #$hs_token=; #ynh_replace_string --match_string=__AS_TOKEN__ --replace_string="$as_token" --target_file=$app_service_registration_path/$app.yaml @@ -166,13 +170,13 @@ $final_path/mautrix-whatsapp -g -c $final_path/config.yaml -r $app_service_regis # Handled by synapse: synapse_ynh adds all registration files added in $app_service_registration_path to the app_service_config_files list # 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="$mautrix_config_path" ynh_store_file_checksum --file="$app_service_registration_path/$app.yaml" #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 # Use logrotate to manage application logfile(s) #ynh_use_logrotate --logfile "/var/log/$app/log.log" @@ -183,7 +187,7 @@ ynh_use_logrotate --non-append #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --time --weight=1 +ynh_script_progression --message="Upgrading systemd configuration..." --weight=4 # Create a dedicated systemd config ynh_add_systemd_config @@ -199,15 +203,22 @@ ynh_add_systemd_config chown -R root: $final_path chown $mautrix_whatsapp_user:root -R $final_path +#================================================= +# ADVERTISE SERVICE IN ADMIN PANEL +#================================================= +#yunohost service add $app --log "/var/log/$app/log.log" +# if using yunohost version 3.2 or more in the 'manifest.json', a description can be added +yunohost service add $app --description "$app daemon for bridging Whatsapp and Matrix messages" --log "/var/log/$app/log.log" + #================================================= # START SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Starting a systemd service..." --time --weight=1 +ynh_script_progression --message="Starting a systemd service..." --weight=1 -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/log.log" +ynh_systemd_action --service_name=$app --action="start" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --time --last +ynh_script_progression --message="Upgrade of $app completed" --last