From c5234b240e1e574106e8b6e04f9630b46dbcab7e Mon Sep 17 00:00:00 2001 From: Yunohost-Bot <> Date: Sat, 31 Aug 2024 01:05:09 +0200 Subject: [PATCH] [autopatch] Automatic patch attempt for helpers 2.1 --- .gitignore | 1 + manifest.toml | 3 +- scripts/_common.sh | 20 ++--- scripts/backup | 23 ++---- scripts/config | 18 ++--- scripts/install | 106 ++++++++++++------------- scripts/remove | 24 +++--- scripts/restore | 56 ++++++-------- scripts/upgrade | 189 +++++++++++++++++++++------------------------ 9 files changed, 195 insertions(+), 245 deletions(-) diff --git a/.gitignore b/.gitignore index 783a4ae..8f144f3 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ *.sw[op] +.DS_Store diff --git a/manifest.toml b/manifest.toml index 95244d0..f86fc63 100644 --- a/manifest.toml +++ b/manifest.toml @@ -19,7 +19,8 @@ admindoc = "https://docs.mau.fi/bridges/go/whatsapp/index.html" fund = "https://github.com/sponsors/tulir" [integration] -yunohost = ">= 11.2" +yunohost = ">= 11.2.18" +helpers_version = "2.1" architectures = ["amd64", "arm64", "armhf"] multi_instance = true ldap = false diff --git a/scripts/_common.sh b/scripts/_common.sh index 8872aa1..b95f23a 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -1,9 +1,5 @@ #!/bin/bash -#================================================= -# PERSONAL HELPERS -#================================================= - get_synapse_db_name() { # Parameters: synapse instance identifier # Returns: database name @@ -23,7 +19,7 @@ apply_permissions() { if [ -n "$newValues" ] then - #ynh_systemd_action --service_name="$app" --action=stop + #ynh_systemctl --service="$app" --action=stop # Get all entries between "permissions:" and "relay:" keys, remove the role part, remove commented parts, format it with newlines and clean whitespaces and double quotes. allDefinedEntries=$(awk '/permissions:/{flag=1; next} /relay:/{flag=0} flag' "$install_dir/config.yaml" | sed "/: $role/d" | sed -r 's/: (admin|user|relay)//' | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr ',' '\n' ) # Delete everything from the corresponding role to insert the new defined values. This way we also handle deletion of users. @@ -45,25 +41,23 @@ apply_permissions() { ynh_print_info "Users with role $role added in $install_dir/config.yaml" } - - set__listuser() { role="user" - ynh_app_setting_set --app=$app --key=listuser --value="$listuser" + ynh_app_setting_set --key=listuser --value="$listuser" apply_permissions - ynh_store_file_checksum --file="$install_dir/config.yaml" + ynh_store_file_checksum "$install_dir/config.yaml" } set__listrelay() { role="relay" - ynh_app_setting_set --app=$app --key=listrelay --value="$listrelay" + ynh_app_setting_set --key=listrelay --value="$listrelay" apply_permissions - ynh_store_file_checksum --file="$install_dir/config.yaml" + ynh_store_file_checksum "$install_dir/config.yaml" } set__listadmin() { role="admin" - ynh_app_setting_set --app=$app --key=listadmin --value="$listadmin" + ynh_app_setting_set --key=listadmin --value="$listadmin" apply_permissions - ynh_store_file_checksum --file="$install_dir/config.yaml" + ynh_store_file_checksum "$install_dir/config.yaml" } diff --git a/scripts/backup b/scripts/backup index e6e6343..502e84b 100755 --- a/scripts/backup +++ b/scripts/backup @@ -1,43 +1,34 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # 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 -#================================================= -# DECLARE DATA AND CONF FILES TO BACKUP -#================================================= -ynh_print_info --message="Declaring files to be backed up..." +ynh_print_info "Declaring files to be backed up..." #================================================= # BACKUP THE APP MAIN DIR #================================================= -ynh_backup --src_path="$install_dir" +ynh_backup "$install_dir" #================================================= # SYSTEM CONFIGURATION #================================================= -ynh_backup --src_path="/etc/logrotate.d/$app" +ynh_backup "/etc/logrotate.d/$app" -ynh_backup --src_path="/etc/systemd/system/$app.service" +ynh_backup "/etc/systemd/system/$app.service" #================================================= # BACKUP THE POSTGRESQL DATABASE #================================================= -ynh_print_info --message="Backing up the PostgreSQL database..." +ynh_print_info "Backing up the PostgreSQL database..." -ynh_psql_dump_db --database="$db_name" > db.sql +ynh_psql_dump_db > db.sql #================================================= # END OF SCRIPT #================================================= -ynh_print_info --message="Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." +ynh_print_info "Backup script completed for $app. (YunoHost will then actually copy those files to the archive)." diff --git a/scripts/config b/scripts/config index 364874c..0db8508 100644 --- a/scripts/config +++ b/scripts/config @@ -1,14 +1,14 @@ #!/bin/bash source _common.sh source /usr/share/yunohost/helpers -ynh_abort_if_errors +#REMOVEME? ynh_abort_if_errors #================================================= # SPECIFIC GETTERS FOR TOML SHORT KEY #================================================= get__botname() { - botname=$(ynh_app_setting_get --app $app --key botname) + botname=$(ynh_app_setting_get --key botname) echo "${botname}" } @@ -45,21 +45,21 @@ EOF #================================================= set__botname() { - old_botname=$(ynh_app_setting_get --app $app --key botname) + old_botname=$(ynh_app_setting_get --key botname) if [ "$botname" -eq "$old_botname" ] # Check to avoid updating botname when it's not needed. then return fi - ynh_app_setting_set --app=$app --key=botname --value="$botname" - synapse_instance=$(ynh_app_setting_get --app $app --key synapse_instance) + ynh_app_setting_set --key=botname --value="$botname" + synapse_instance=$(ynh_app_setting_get --key synapse_instance) sed -i "s/username:.*/username: $botname/" "$install_dir/config.yaml" "$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 --message="Synapse can't restart with the appservice configuration" - chown -R "$app:$app" "$install_dir" - ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" - ynh_store_file_checksum --file="$install_dir/config.yaml" + "/opt/yunohost/matrix-$synapse_instance/update_synapse_for_appservice.sh" || ynh_die "Synapse can't restart with the appservice configuration" + #REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R "$app:$app" "$install_dir" + ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml" + ynh_store_file_checksum "$install_dir/config.yaml" } ynh_app_config_run $1 diff --git a/scripts/install b/scripts/install index d7f0744..66ff399 100755 --- a/scripts/install +++ b/scripts/install @@ -1,19 +1,13 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers # Retrieve some values from selected Synapse instance and store them server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name) domain=$(ynh_app_setting_get --app $synapse_instance --key domain) -ynh_app_setting_set --app=$app --key=server_name --value=$server_name -ynh_app_setting_set --app=$app --key=domain --value=$domain +ynh_app_setting_set --key=server_name --value=$server_name +ynh_app_setting_set --key=domain --value=$domain synapse_db_name="$(get_synapse_db_name $synapse_instance)" # This is needed to convert the value from the manifest to a valid value for the config.yaml file. @@ -52,50 +46,49 @@ listrelay="*" listadmin="$botadmin" listuser="$botusers" -ynh_app_setting_set --app=$app --key=appserviceid --value=$appserviceid -ynh_app_setting_set --app=$app --key=async_media --value=$async_media -ynh_app_setting_set --app=$app --key=displayname --value=$displayname -ynh_app_setting_set --app=$app --key=avatar --value=$avatar -ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events -ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics -ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port -ynh_app_setting_set --app=$app --key=os_name --value=$os_name -ynh_app_setting_set --app=$app --key=browser_name --value=$browser_name -ynh_app_setting_set --app=$app --key=username_template --value=$username_template -ynh_app_setting_set --app=$app --key=personal_filtering_spaces --value=$personal_filtering_spaces -ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts -ynh_app_setting_set --app=$app --key=send_presence_on_typing --value=$send_presence_on_typing -ynh_app_setting_set --app=$app --key=url_previews --value=$url_previews -ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default -ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require -ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot -ynh_app_setting_set --app=$app --key=admin_only --value=$admin_only -ynh_app_setting_set --app=$app --key=print_level --value=$print_level -ynh_app_setting_set --app=$app --key=listrelay --value=$listrelay +ynh_app_setting_set --key=appserviceid --value=$appserviceid +ynh_app_setting_set --key=async_media --value=$async_media +ynh_app_setting_set --key=displayname --value=$displayname +ynh_app_setting_set --key=avatar --value=$avatar +ynh_app_setting_set --key=ephemeral_events --value=$ephemeral_events +ynh_app_setting_set --key=enable_metrics --value=$enable_metrics +ynh_app_setting_set --key=listen_port --value=$listen_port +ynh_app_setting_set --key=os_name --value=$os_name +ynh_app_setting_set --key=browser_name --value=$browser_name +ynh_app_setting_set --key=username_template --value=$username_template +ynh_app_setting_set --key=personal_filtering_spaces --value=$personal_filtering_spaces +ynh_app_setting_set --key=delivery_receipts --value=$delivery_receipts +ynh_app_setting_set --key=send_presence_on_typing --value=$send_presence_on_typing +ynh_app_setting_set --key=url_previews --value=$url_previews +ynh_app_setting_set --key=encryption_default --value=$encryption_default +ynh_app_setting_set --key=encryption_require --value=$encryption_require +ynh_app_setting_set --key=enable_relaybot --value=$enable_relaybot +ynh_app_setting_set --key=admin_only --value=$admin_only +ynh_app_setting_set --key=print_level --value=$print_level +ynh_app_setting_set --key=listrelay --value=$listrelay #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -ynh_script_progression --message="Setting up source files..." --weight=5 +ynh_script_progression "Setting up source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" -chmod 750 "$install_dir" -chmod -R 750 "$install_dir" -chown -R $app:$app "$install_dir" - +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 750 "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" #================================================= # SPECIFIC SETUP #================================================= # ADD A CONFIGURATION #================================================= -ynh_script_progression --message="Adding a configuration file..." --weight=2 +ynh_script_progression "Adding $app's configuration..." -ynh_add_config --template="../conf/config.yaml" --destination="$install_dir/config.yaml" +ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml" -chmod 400 "$install_dir/config.yaml" -chown $app:$app "$install_dir/config.yaml" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/config.yaml" # This calls allows to set multiple users during install question "botusers" specifying them separated by a comma set__listuser @@ -105,62 +98,61 @@ set__listadmin #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= -ynh_script_progression --message="Registering Synapse app-service" --weight=1 +ynh_script_progression "Registering Synapse app-service" $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 --message="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" -chown -R $app:$app "$install_dir" -ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" -ynh_store_file_checksum --file="$install_dir/config.yaml" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" +ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml" +ynh_store_file_checksum "$install_dir/config.yaml" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Configuring a systemd service..." --weight=5 +ynh_script_progression "Configuring $app's systemd service..." # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Configuring log rotation..." --weight=3 +ynh_script_progression "Configuring log rotation..." # Use logrotate to manage application logfile(s) -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_config_add_logrotate "/var/log/$app/$app.log" $app/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 600 "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 700 "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app /var/log/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." 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=15 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$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 Spaces.) if [ "$bot_synapse_adm" = true ] then - ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" + ynh_psql_db_shell $synapse_db_name <<< "UPDATE users SET admin = 1 WHERE name = ""$botname"";" #yunohost app action run $synapse_instance set_admin_user -a username=$botname fi -ynh_systemd_action --service_name=$app --action="restart" +ynh_systemctl --service=$app --action="restart" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Installation of $app completed" --last +ynh_script_progression "Installation of $app completed" diff --git a/scripts/remove b/scripts/remove index db594d3..1412515 100755 --- a/scripts/remove +++ b/scripts/remove @@ -1,18 +1,12 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --weight=5 +ynh_script_progression "Loading installation settings..." app=$YNH_APP_INSTANCE_NAME @@ -27,31 +21,31 @@ bot_synapse_db_user="@""$botname"":""$server_name" #================================================= # Remove the service from the list of services known by YunoHost (added from `yunohost service add`) -if ynh_exec_warn_less yunohost service status $app >/dev/null +if ynh_hide_warnings yunohost service status $app >/dev/null then - ynh_script_progression --message="Removing $app service integration..." --weight=3 + ynh_script_progression "Removing $app service integration..." yunohost service remove $app fi # Remove the dedicated systemd config -ynh_remove_systemd_config +ynh_config_remove_systemd # Remove the app-specific logrotate config -ynh_remove_logrotate +ynh_config_remove_logrotate #================================================= # SPECIFIC REMOVE #================================================= # REMOVE VARIOUS FILES #================================================= -ynh_script_progression --message="Removing various files..." --weight=6 +ynh_script_progression "Removing various files..." # 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 --message="Synapse can't restart with the appservice configuration" +ynh_safe_rm "/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" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Removal of $app completed" --last +ynh_script_progression "Removal of $app completed" diff --git a/scripts/restore b/scripts/restore index d2d9d0a..5637032 100755 --- a/scripts/restore +++ b/scripts/restore @@ -1,16 +1,10 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - # 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 -server_name=$(ynh_app_setting_get --app=$app --key=server_name) +server_name=$(ynh_app_setting_get --key=server_name) synapse_db_name="$(get_synapse_db_name $synapse_instance)" bot_synapse_db_user="@$botname:$server_name" @@ -18,79 +12,79 @@ bot_synapse_db_user="@$botname:$server_name" #================================================= # RESTORE THE APP MAIN DIR #================================================= -ynh_script_progression --message="Restoring the app main directory..." --weight=1 +ynh_script_progression "Restoring the app main directory..." -ynh_restore_file --origin_path="$install_dir" - -chmod 750 "$install_dir" -chmod -R 750 "$install_dir" -chown -R $app:$app "$install_dir" +ynh_restore "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 750 "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" #================================================= # SPECIFIC RESTORATION #================================================= # RESTORE THE POSTGRESQL DATABASE #================================================= -ynh_script_progression --message="Restoring the PostgreSQL database..." --weight=8 +ynh_script_progression "Restoring the PostgreSQL database..." -ynh_psql_execute_file_as_root --file="./db.sql" --database=$db_name +ynh_psql_db_shell < "./db.sql"" #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= -ynh_script_progression --message="Registering Synapse app-service" --weight=1 +ynh_script_progression "Registering Synapse app-service" $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" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/config.yaml" #================================================= # RESTORE SYSTEMD #================================================= -ynh_script_progression --message="Restoring the systemd configuration..." --weight=3 +ynh_script_progression "Restoring $app's systemd service..." -ynh_restore_file --origin_path="/etc/systemd/system/$app.service" +ynh_restore "/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_script_progression "Restoring the logrotate configuration..." -ynh_restore_file --origin_path="/etc/logrotate.d/$app" +ynh_restore "/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 +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 600 "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 700 "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app /var/log/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." 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 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$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_synapse_adm" = true ] then - ynh_psql_execute_as_root --database=$synapse_db_name --sql="UPDATE users SET admin = 1 WHERE name = ""$botname"";" + ynh_psql_db_shell $synapse_db_name <<< "UPDATE users SET admin = 1 WHERE name = ""$botname"";" #yunohost app action run $synapse_instance set_admin_user -a username=$botname fi -ynh_systemd_action --service_name=$app --action="restart" +ynh_systemctl --service=$app --action="restart" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Restoration completed for $app" --last +ynh_script_progression "Restoration completed for $app" diff --git a/scripts/upgrade b/scripts/upgrade index d5364fa..811419b 100755 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -1,15 +1,9 @@ #!/bin/bash -#================================================= -# GENERIC START -#================================================= -# IMPORT GENERIC HELPERS -#================================================= - source _common.sh source /usr/share/yunohost/helpers -server_name=$(ynh_app_setting_get --app=$app --key=server_name) +server_name=$(ynh_app_setting_get --key=server_name) synapse_db_name="$(get_synapse_db_name $synapse_instance)" bot_synapse_db_user="@$botname:$server_name" @@ -17,209 +11,200 @@ 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) +async_media=$(ynh_app_setting_get --key=async_media) +displayname=$(ynh_app_setting_get --key=displayname) +avatar=$(ynh_app_setting_get --key=avatar) +ephemeral_events=$(ynh_app_setting_get --key=ephemeral_events) +enable_metrics=$(ynh_app_setting_get --key=enable_metrics) +listen_port=$(ynh_app_setting_get --key=listen_port) +os_name=$(ynh_app_setting_get --key=os_name) +browser_name=$(ynh_app_setting_get --key=browser_name) +username_template=$(ynh_app_setting_get --key=username_template) +personal_filtering_spaces=$(ynh_app_setting_get --key=personal_filtering_spaces) +delivery_receipts=$(ynh_app_setting_get --key=delivery_receipts) +send_presence_on_typing=$(ynh_app_setting_get --key=send_presence_on_typing) +url_previews=$(ynh_app_setting_get --key=url_previews) +encryption_default=$(ynh_app_setting_get --key=encryption_default) +encryption_require=$(ynh_app_setting_get --key=encryption_require) +enable_relaybot=$(ynh_app_setting_get --key=enable_relaybot) +admin_only=$(ynh_app_setting_get --key=admin_only) +print_level=$(ynh_app_setting_get --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) +listrelay=$(ynh_app_setting_get --key=listrelay) +listuser=$(ynh_app_setting_get --key=listuser) +listadmin=$(ynh_app_setting_get --key=listadmin) -#================================================= -# CHECK VERSION -#================================================= -ynh_script_progression --message="Checking version..." --weight=1 +ynh_script_progression "Checking version..." -upgrade_type=$(ynh_check_app_version_changed) - -#================================================= -# STANDARD UPGRADE STEPS #================================================= # STOP SYSTEMD SERVICE #================================================= -ynh_script_progression --message="Stopping a systemd service..." --weight=1 +ynh_script_progression "Stopping $app's systemd service..." -ynh_systemd_action --service_name=$app --action="stop" --log_path="/var/log/$app/$app.log" +ynh_systemctl --service=$app --action="stop" #================================================= # ENSURE DOWNWARD COMPATIBILITY #================================================= -ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 +ynh_script_progression "Ensuring downward compatibility..." # DB Backup missing because of wrong Upgrade from <=0.2.0 if [ -z "$botname" ] then - botname=$(ynh_app_setting_get --app=$app --key=whatsappbot) - ynh_app_setting_set --app=$app --key=botname --value=$botname + botname=$(ynh_app_setting_get --key=whatsappbot) + ynh_app_setting_set --key=botname --value=$botname fi if [ -z "$db_name" ] then - db_name=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_name) - ynh_app_setting_set --app=$app --key=db_name --value=$db_name + db_name=$(ynh_app_setting_get --key=mautrix_whatsapp_db_name) + ynh_app_setting_set --key=db_name --value=$db_name fi if [ -z "$db_pwd" ] then - db_pwd=$(ynh_app_setting_get --app=$app --key=mautrix_whatsapp_db_pwd) - ynh_app_setting_set --app=$app --key=db_pwd --value=$db_pwd + db_pwd=$(ynh_app_setting_get --key=mautrix_whatsapp_db_pwd) + ynh_app_setting_set --key=db_pwd --value=$db_pwd fi -ynh_app_setting_delete --app=$app --key=whatsappbot -ynh_app_setting_delete --app=$app --key=mautrix_whatsapp_db_name -ynh_app_setting_delete --app=$app --key=mautrix_whatsapp_db_pwd +ynh_app_setting_delete --key=whatsappbot +ynh_app_setting_delete --key=mautrix_whatsapp_db_name +ynh_app_setting_delete --key=mautrix_whatsapp_db_pwd # SET STANDARD SETTINGS FROM DEFAULT CONFIG if [ -z "$async_media" ] then async_media="false" - ynh_app_setting_set --app=$app --key=async_media --value=$async_media + ynh_app_setting_set --key=async_media --value=$async_media fi if [ -z "$displayname" ] then displayname="WhatsApp bridge bot" - ynh_app_setting_set --app=$app --key=displayname --value=$displayname + ynh_app_setting_set --key=displayname --value=$displayname fi if [ -z "$avatar" ] then avatar="mxc://maunium.net/NeXNQarUbrlYBiPCpprYsRqr" - ynh_app_setting_set --app=$app --key=avatar --value=$avatar + ynh_app_setting_set --key=avatar --value=$avatar fi if [ -z "$ephemeral_events" ] then ephemeral_events="true" - ynh_app_setting_set --app=$app --key=ephemeral_events --value=$ephemeral_events + ynh_app_setting_set --key=ephemeral_events --value=$ephemeral_events fi if [ -z "$enable_metrics" ] then enable_metrics="false" - ynh_app_setting_set --app=$app --key=enable_metrics --value=$enable_metrics + ynh_app_setting_set --key=enable_metrics --value=$enable_metrics fi if [ -z "$listen_port" ] then listen_port="127.0.0.1:8001" - ynh_app_setting_set --app=$app --key=listen_port --value=$listen_port + ynh_app_setting_set --key=listen_port --value=$listen_port fi if [ -z "$os_name" ] then os_name="Mautrix-WhatsApp bridge" - ynh_app_setting_set --app=$app --key=os_name --value=$os_name + ynh_app_setting_set --key=os_name --value=$os_name fi if [ -z "$browser_name" ] then browser_name="unknown" - ynh_app_setting_set --app=$app --key=browser_name --value=$browser_name + ynh_app_setting_set --key=browser_name --value=$browser_name fi if [ -z "$username_template" ] then username_template="whatsapp_{{.}}" - ynh_app_setting_set --app=$app --key=username_template --value=$username_template + ynh_app_setting_set --key=username_template --value=$username_template fi if [ -z "$personal_filtering_spaces" ] then personal_filtering_spaces="false" - ynh_app_setting_set --app=$app --key=personal_filtering_spaces --value=$personal_filtering_spaces + ynh_app_setting_set --key=personal_filtering_spaces --value=$personal_filtering_spaces fi if [ -z "$delivery_receipts" ] then delivery_receipts="false" - ynh_app_setting_set --app=$app --key=delivery_receipts --value=$delivery_receipts + ynh_app_setting_set --key=delivery_receipts --value=$delivery_receipts fi if [ -z "$send_presence_on_typing" ] then send_presence_on_typing="false" - ynh_app_setting_set --app=$app --key=send_presence_on_typing --value=$send_presence_on_typing + ynh_app_setting_set --key=send_presence_on_typing --value=$send_presence_on_typing fi if [ -z "$url_previews" ] then url_previews="false" - ynh_app_setting_set --app=$app --key=url_previews --value=$url_previews + ynh_app_setting_set --key=url_previews --value=$url_previews fi if [ -z "$encryption_default" ] then encryption_default="false" - ynh_app_setting_set --app=$app --key=encryption_default --value=$encryption_default + ynh_app_setting_set --key=encryption_default --value=$encryption_default fi if [ -z "$encryption_require" ] then encryption_require="false" - ynh_app_setting_set --app=$app --key=encryption_require --value=$encryption_require + ynh_app_setting_set --key=encryption_require --value=$encryption_require fi if [ -z "$enable_relaybot" ] then enable_relaybot="true" - ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot + ynh_app_setting_set --key=enable_relaybot --value=$enable_relaybot fi if [ -z "$admin_only" ] then admin_only="true" - ynh_app_setting_set --app=$app --key=admin_only --value=$admin_only + ynh_app_setting_set --key=admin_only --value=$admin_only fi if [ -z "$print_level" ] then print_level="info" - ynh_app_setting_set --app=$app --key=print_level --value=$print_level + ynh_app_setting_set --key=print_level --value=$print_level fi if [ -z "$listrelay" ] then listrelay="*" - ynh_app_setting_set --app=$app --key=listrelay --value=$listrelay + ynh_app_setting_set --key=listrelay --value=$listrelay fi if [ -z "$enable_relaybot" ] then enable_relaybot="true" - ynh_app_setting_set --app=$app --key=enable_relaybot --value=$enable_relaybot + ynh_app_setting_set --key=enable_relaybot --value=$enable_relaybot fi if [ -z "$listuser" ] then - listuser=$(ynh_app_setting_get --app=$app --key=botusers) - ynh_app_setting_set --app=$app --key=listuser --value=$listuser - ynh_app_setting_delete --app=$app --key=botusers + listuser=$(ynh_app_setting_get --key=botusers) + ynh_app_setting_set --key=listuser --value=$listuser + ynh_app_setting_delete --key=botusers fi if [ -z "$listadmin" ] then - listadmin=$(ynh_app_setting_get --app=$app --key=botadmin) - ynh_app_setting_set --app=$app --key=listadmin --value=$listadmin - ynh_app_setting_delete --app=$app --key=botadmin + listadmin=$(ynh_app_setting_get --key=botadmin) + ynh_app_setting_set --key=listadmin --value=$listadmin + ynh_app_setting_delete --key=botadmin fi #================================================= # DOWNLOAD, CHECK AND UNPACK SOURCE #================================================= -if [ "$upgrade_type" == "UPGRADE_APP" ] +# FIXME: this is still supported but the recommendation is now to *always* re-setup the app sources wether or not the upstream sources changed +if ynh_app_upstream_version_changed then - ynh_script_progression --message="Upgrading source files..." --weight=2 + ynh_script_progression "Upgrading source files..." # Download, check integrity, uncompress and patch the source from app.src ynh_setup_source --dest_dir="$install_dir" fi -chmod 750 "$install_dir" -chmod -R 750 "$install_dir" -chown -R $app:$app "$install_dir" - -#================================================= -# SPECIFIC UPGRADE +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 750 "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 750 "$install_dir" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" #================================================= # UPDATE A CONFIG FILE #================================================= -ynh_script_progression --message="Updating a configuration file..." --weight=2 +ynh_script_progression "Updating configuration..." # reset permissions to be able to apply_permissions with app_setting values after upgrade listrelay_=$listrelay @@ -229,10 +214,10 @@ listrelay="*" listuser="@user:domain.tld" listadmin="@admin:domain.tld" -ynh_add_config --template="../conf/config.yaml" --destination="$install_dir/config.yaml" +ynh_config_add --template="config.yaml" --destination="$install_dir/config.yaml" -chmod 400 "$install_dir/config.yaml" -chown $app:$app "$install_dir/config.yaml" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 400 "$install_dir/config.yaml" +#REMOVEME? Assuming the file is setup using ynh_config_add, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown $app:$app "$install_dir/config.yaml" listrelay=$listrelay_ listuser=$listuser_ @@ -246,54 +231,52 @@ set__listadmin #================================================= # REGISTER SYNAPSE APP-SERVICE #================================================= -ynh_script_progression --message="Registering Synapse app-service" --weight=1 +ynh_script_progression "Registering Synapse app-service" $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" # Set permissions on app files -chown -R $app:$app "$install_dir" -ynh_store_file_checksum --file="/etc/matrix-$synapse_instance/app-service/$app.yaml" -ynh_store_file_checksum --file="$install_dir/config.yaml" +#REMOVEME? Assuming the install dir is setup using ynh_setup_source, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app "$install_dir" +ynh_store_file_checksum "/etc/matrix-$synapse_instance/app-service/$app.yaml" +ynh_store_file_checksum "$install_dir/config.yaml" #================================================= # SETUP SYSTEMD #================================================= -ynh_script_progression --message="Upgrading systemd configuration..." --weight=4 +ynh_script_progression "Upgrading systemd configuration..." # Create a dedicated systemd config -ynh_add_systemd_config +ynh_config_add_systemd -#================================================= -# GENERIC FINALIZATION #================================================= # SETUP LOGROTATE #================================================= -ynh_script_progression --message="Upgrading logrotate configuration..." --weight=1 +ynh_script_progression "Upgrading logrotate configuration..." # Use logrotate to manage application logfile(s) -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_config_add_logrotate "/var/log/$app/$app.log" $app/$app +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod -R 600 "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chmod 700 "/var/log/$app" +#REMOVEME? Assuming ynh_config_add_logrotate is called, the proper chmod/chowns are now already applied and it shouldn't be necessary to tweak perms | chown -R $app:$app /var/log/$app #================================================= # INTEGRATE SERVICE IN YUNOHOST #================================================= -ynh_script_progression --message="Integrating service in YunoHost..." --weight=1 +ynh_script_progression "Integrating service in YunoHost..." 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 +ynh_script_progression "Starting $app's systemd service..." # Start a systemd service -ynh_systemd_action --service_name=$app --action="start" +ynh_systemctl --service=$app --action="start" #================================================= # END OF SCRIPT #================================================= -ynh_script_progression --message="Upgrade of $app completed" --last +ynh_script_progression "Upgrade of $app completed"