1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh.git synced 2024-09-03 19:46:01 +02:00
* Do PR in testing

* conditional bot_is_synapse_admin

* Ask if bot_is_synapse_admin in manifest

* go build after ynh_setup_source

* bot_is_synapse_admin string

* syntax
This commit is contained in:
Gredin67 2020-05-02 19:47:37 +02:00 committed by GitHub
parent 5ad308edc8
commit 1a8d14cf4c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 89 additions and 29 deletions

View file

@ -99,6 +99,14 @@ https://github.com/tulir/mautrix-whatsapp/wiki
Developers info
----------------
Please do your pull request to the testing branch.
To try the testing branch, please proceed like that:
```
sudo yunohost app install https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh/tree/testing --debug
or
sudo yunohost app upgrade synapse -u https://github.com/YunoHost-Apps/mautrix_whatsapp_ynh/tree/testing --debug
```
To test communication between the app service and synapse on a VM, you must install a certificate:
```
echo | openssl s_client -showcerts -servername synapse.vm -connect synapse.vm:443 2>/dev/null | awk '/-----BEGIN CERTIFICATE-----/, /-----END CERTIFICATE-----/' >> /usr/local/share/ca-certificates/synapse.vm.crt

View file

@ -27,18 +27,22 @@
"name": "port",
"type": "string",
"ask": {
"en": "Choose a port for communication between mautrix_whatsapp (app service) and synapse (home server)",
"fr": "Choisissez un port pour la communication entre mautrix_whatsapp (app service) et synapse (home server)"
"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",
"ask": {
"en": "Choose the local synapse instance number to communicate with app service",
"fr": "Choisissez le numéro de l'instance synapse qui doit communiquer avec l'app service"
"en": "Choose the local synapse instance number to communicate with mautrix_whatsapp",
"fr": "Choisissez le numéro de l'instance synapse qui doit communiquer avec mautrix_whatsapp"
},
"example": "2 (for instance synapse__2)",
"help": {
@ -51,8 +55,8 @@
"name": "whatsappbot",
"type": "string",
"ask": {
"en": "Choose a local Matrix/Synapse user name for the WhatsApp bot",
"fr": "Choisissez un nom d'utilisateur local Matrix/Synapse pour le robot WhatsApp"
"en": "Choose a local synapse user name for the WhatsApp bot",
"fr": "Choisissez un nom d'utilisateur synapse local pour le robot WhatsApp"
},
"example": "whatsappbot",
"help": {
@ -61,6 +65,19 @@
},
"default": "whatsappbot"
},
{
"name": "bot_is_synapse_admin",
"type": "string",
"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."
},
"default": "Yes"
},
{
"name": "botadmin",
"type": "string",
@ -70,8 +87,8 @@
},
"example": "@johndoe:localsynapse.servername or @johndoe:matrix.org",
"help": {
"en": "The WhatsApp bot administrator does not need to be a local Matrix/Synapse account.",
"fr": "Le compte administrateur du robot WhatsApp peut ne pas être un compte local Matrix/Synapse."
"en": "The WhatsApp bot administrator does not need to be a local synapse account.",
"fr": "Le compte administrateur du robot WhatsApp peut ne pas être un compte local synapse."
},
"default": "Your main Matrix account"
},
@ -85,8 +102,8 @@
"example": "admin or local or @johndoe:server.name or server.name or *",
"default": "admin",
"help": {
"en": "Either the administrator only (admin), all local Matrix/Synapse users (local), a remote or local user (@johndoe:server.name), a remote server (matrix.org), or all remote/local servers (*) can be authorized. Give the matrix server_name, not the full domain/url.",
"fr": "On peut autoriser le compte administrateur seul (admin), tous les comptes Matrix/Synapse locaux (local), un compte local ou distant (@johndoe:server.name), un serveur distant (matrix.org), ou tous les serveurs remote/local (*). Donner le nom du serveur matrix, pas le domaine/url complet."
"en": "Either the administrator only (admin), all local synapse users (local), a remote or local user (@johndoe:server.name), a remote server (matrix.org), or all remote/local servers (*) can be authorized. Give the matrix server_name, not the full domain/url.",
"fr": "On peut autoriser le compte administrateur seul (admin), tous les comptes synapse locaux (local), un compte local ou distant (@johndoe:server.name), un serveur distant (matrix.org), ou tous les serveurs remote/local (*). Donner le nom du serveur matrix, pas le domaine/url complet."
}
}
]

View file

@ -31,6 +31,7 @@ ynh_abort_if_errors
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
botadmin=$YNH_APP_ARG_BOTADMIN
botusers=$YNH_APP_ARG_BOTUSERS
#is_public=$YNH_APP_ARG_IS_PUBLIC
@ -52,13 +53,17 @@ app=$YNH_APP_INSTANCE_NAME
# ToDo check (in manifest?) if the selected synapse instance is not already connected to a mautrix_whatsapp bridge
if [ $synapsenumber -eq "1" ]
then
server_name=$(ynh_app_setting_get --app synapse --key server_name)
domain=$(ynh_app_setting_get --app synapse --key domain)
synapse_instance="synapse"
else
server_name=$(ynh_app_setting_get --app synapse__$synapsenumber --key server_name)
domain=$(ynh_app_setting_get --app synapse__$synapsenumber --key domain)
synapse_instance="synapse__$synapsenumber"
fi
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
synapse_config_path="/etc/matrix-$synapse_instance"
synapse_name="matrix-$synapse_instance"
synapse_user="matrix-$synapse_instance"
synapse_db_name="matrix_$synapse_instance"
synapse_db_user="matrix_$synapse_instance"
#=================================================
# SET CONSTANTS
@ -103,6 +108,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=path --value=$path_url
ynh_app_setting_set --app=$app --key=whatsappbot --value=$whatsappbot
ynh_app_setting_set --app=$app --key=bot_is_synapse_admin --value=$bot_is_synapse_admin
ynh_app_setting_set --app=$app --key=botadmin --value=$botadmin
ynh_app_setting_set --app=$app --key=botusers --value=$botusers
ynh_app_setting_set --app=$app --key=mautrix_version --value=$upstream_version
@ -155,7 +161,7 @@ ynh_install_app_dependencies $pkg_dependencies
# wget https://dl.google.com/go/go$GO_VERSION.linux-$architecture.tar.gz -q
# tar -C /usr/lib -xzf go$GO_VERSION.linux-$architecture.tar.gz
#}
export PATH=$PATH:/usr/lib/go-$GO_VERSION/bin
#export PATH=$PATH:/usr/lib/go-$GO_VERSION/bin
#=================================================
# CREATE A POSTGRESQL DATABASE
@ -195,6 +201,21 @@ ynh_app_setting_set --app=$app --key=final_path --value=$final_path
# Download, check integrity, uncompress and patch the source from app.src
ynh_setup_source --dest_dir="$final_path"
# Build mautrix-whatsapp
base_directory=$PWD
#export GOPATH="$final_path"
#export GOCACHE="$final_path/.cache/go-build"
cd $final_path
export PATH=$PATH:$GO_PATH
go build
#$GO_PATH/go build
cd $base_directory
#sudo ln -s "$final_path"_src/src/github.com/gogits/gogs $final_path
#fi
#=================================================
@ -229,13 +250,12 @@ ynh_add_systemd_config --service=$app
# SPECIFIC SETUP
#=================================================
cd $final_path
#cd $final_path
#echo 'export PATH=$PATH:/usr/lib/go-1.11/bin/' >> /etc/profile
#source /etc/profile
export PATH=$PATH:/usr/lib/go-$GO_VERSION/bin
go build
#Copy example-config.yaml to config.yaml
cp example-config.yaml config.yaml
#export PATH=$PATH:$GO_PATH
#go build
#$GO_PATH/go build
#=================================================
@ -244,6 +264,9 @@ cp example-config.yaml config.yaml
# MODIFY A CONFIG FILE
#=================================================
#Copy example-config.yaml to config.yaml
cp $final_path/example-config.yaml $final_path/config.yaml
### `ynh_replace_string` is used to replace a string in a file.
### (It's compatible with sed regular expressions syntax)
@ -295,6 +318,16 @@ ynh_replace_string --match_string="uri: mautrix-whatsapp.db" --replace_string="u
# {{.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.)
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';"
#ynh_psql_connect_as --user=$synapse_db_user --database=$synapse_db_name <<< "UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name';"
fi
#su --command="psql matrix_synapse" postgres <<< "UPDATE users SET admin = 1 WHERE name = '@$whatsappbot:$server_name'"
# 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"
@ -367,18 +400,20 @@ fi
# 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"
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.
./mautrix-whatsapp -g -r /etc/matrix-synapse/$app-registration.yaml
$final_path/mautrix-whatsapp -g -r $synapse_config_path/$app-registration.yaml
cd $base_directory
#Add the path to the registration file (registration.yaml by default) to your synapse homeserver.yaml under app_service_config_files.
# A list of application service config files to use
#
#app_service_config_files:
# - app_service_1.yaml
# - "/etc/matrix-synapse/registration.yaml"
ynh_replace_string --match_string="#app_service_config_files:" --replace_string="app_service_config_files:" --target_file="/etc/matrix-synapse/homeserver.yaml"
ynh_replace_string --match_string="# - app_service_1.yaml" --replace_string=" - '/etc/matrix-synapse/$app-registration.yaml'" --target_file="/etc/matrix-synapse/homeserver.yaml"
ynh_replace_string --match_string="#app_service_config_files:" --replace_string="app_service_config_files:" --target_file="$synapse_config_path/homeserver.yaml"
ynh_replace_string --match_string="# - app_service_1.yaml" --replace_string=" - '$synapse_config_path/$app-registration.yaml'" --target_file="$synapse_config_path/homeserver.yaml"
#You will then need to restart the synapse server. Remember to restart it every time the registration file is regenerated.
@ -392,7 +427,7 @@ ynh_replace_string --match_string="# - app_service_1.yaml" --replace_string="
# Calculate and store the config file checksum into the app settings
ynh_store_file_checksum --file="$final_path/config.yaml"
ynh_store_file_checksum --file="/etc/matrix-synapse/homeserver.yaml"
ynh_store_file_checksum --file="$synapse_config_path/homeserver.yaml"
#=================================================
# GENERIC FINALIZATION
@ -419,10 +454,10 @@ chown $mautrix_whatsapp_user:root -R $final_path
#setfacl -R -m user:turnserver:rX /etc/matrix-$app
#setfacl -R -m user:turnserver:rwX /var/log/matrix-$app
chown /etc/matrix-synapse/$app-registration.yaml --reference="/etc/matrix-synapse/homeserver.yaml"
chmod u=rwX,g=rX,o= /etc/matrix-synapse/$app-registration.yaml
chown $synapse_config_path/$app-registration.yaml --reference="$synapse_config_path/homeserver.yaml"
chmod u=rwX,g=rX,o= $synapse_config_path/$app-registration.yaml
#You will then need to restart the synapse server. Remember to restart it every time the registration file is regenerated.
service matrix-synapse restart
service $synapse_name restart
#Run the bridge with
#service mautrix-whatsapp restart
#./mautrix-whatsapp.