From fe51aea7047d57e8a4bd4c0bc555d5bcc918c305 Mon Sep 17 00:00:00 2001 From: Benedikt Tissot Date: Fri, 17 Sep 2021 17:53:12 +0200 Subject: [PATCH] add bot_synapse_adm option --- manifest.json | 15 ++++++++++++++- scripts/install | 12 +++++++----- scripts/upgrade | 11 ++++++----- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/manifest.json b/manifest.json index e7f2f46..abe21ba 100644 --- a/manifest.json +++ b/manifest.json @@ -70,7 +70,20 @@ "fr": "N'activer que si vous connaissez les prérequis et constraintes liées à e2b." }, "default": false - }, + }, + { + "name": "bot_synapse_adm", + "type": "boolean", + "ask": { + "en": "Give the Telegram bot administrator rights to the synapse instance?", + "fr": "Donner au robot Telegram des droits administrateur à l'instance synapse ?" + }, + "help": { + "en": "If true, the bot can group Telegram 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 Telegram 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": true + }, { "name": "botadmin", "type": "string", diff --git a/scripts/install b/scripts/install index ffb4686..1b05268 100755 --- a/scripts/install +++ b/scripts/install @@ -29,6 +29,7 @@ botname=$YNH_APP_ARG_BOTNAME encryption=$YNH_APP_ARG_ENCRYPTION botadmin=$YNH_APP_ARG_BOTADMIN botusers=$YNH_APP_ARG_BOTUSERS +bot_synapse_adm=$YNH_APP_ARG_BOT_SYNAPSE_ADM # TODO new settings specific to telegram apiid=$YNH_APP_ARG_APIID @@ -90,6 +91,7 @@ ynh_app_setting_set --app=$app --key=server_name --value=$server_name ynh_app_setting_set --app=$app --key=port --value=$port ynh_app_setting_set --app=$app --key=botname --value=$botname ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance +ynh_app_setting_set --app=$app --key=bot_synapse_adm --value=$bot_synapse_adm ynh_app_setting_set --app=$app --key=app_service_registration_path --value=$app_service_registration_path ynh_app_setting_set --app=$app --key=encryption --value=$encryption ynh_app_setting_set --app=$app --key=mautrix_bridge_db_name --value=$mautrix_bridge_db_name @@ -256,12 +258,12 @@ ynh_script_progression --message="Starting a systemd service..." --weight=1 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" = true ] -# then + # (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"";" -# #yunohost app action run $synapse_instance set_admin_user -a username=$botname -# fi + #yunohost app action run $synapse_instance set_admin_user -a username=$botname + fi ynh_systemd_action --service_name=$app --action="restart" #================================================= diff --git a/scripts/upgrade b/scripts/upgrade index 8536cfa..864f9ae 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -53,11 +53,12 @@ ynh_script_progression --message="Ensuring downward compatibility..." --weight=1 # some legacy installs and you therefore want to initiaze stuff during upgrade) # -# If db_name doesn't exist, create it -#if [ -z "$db_name" ]; then -# db_name=$(ynh_sanitize_dbid --db_name=$app) -# ynh_app_setting_set --app=$app --key=db_name --value=$db_name -#fi +bot_synapse_adm=$(ynh_app_setting_get --app=$app --key=bot_synapse_adm) +# If bot_synapse_adm doesn't exist, create it +if [ -z "$bot_synapse_adm" ]; then + bot_synapse_adm=true + ynh_app_setting_set --app=$app --key=bot_synapse_adm --value=$bot_synapse_adm +fi # If final_path doesn't exist, create it #if [ -z "$final_path" ]; then