mirror of
https://github.com/YunoHost-Apps/mautrix_signal_ynh.git
synced 2024-09-03 19:46:07 +02:00
Handle missing enable_relaybot setting
Also add a helper "yaml2json" python script to allow using jq from the shell to query config values.
This commit is contained in:
parent
f2d359e254
commit
070b255e0e
4 changed files with 56 additions and 0 deletions
|
@ -64,6 +64,14 @@ ram.runtime = "50M" # FIXME: replace with an **estimate** minimum ram requiremen
|
|||
example = "admin or domain or @johndoe:server.name or server.name or *"
|
||||
default = "domain"
|
||||
|
||||
[install.enable_relaybot]
|
||||
ask.en = "Choose whether to enable the relay bot feature"
|
||||
ask.fr = "Choisissez si vous souhaitez activer la fonctionnalité de relai par bot"
|
||||
help.en = "If enabled, allows to use a single signal account (bot) to forward messages from multiple Matrix users. Messages will appear on Signal as if originating from a single user, with a prefix that indicates who is talking."
|
||||
help.fr = "Si activé, permet d'utiliser un seul compte signal (bot) pour transmettre les messages de multiples utilisateurs Matrix. Les messages apparaîtront sur Signal comme envoyés par un seul utilisateur, avec un préfixe indiquant leur auteur."
|
||||
type = "boolean"
|
||||
default = true
|
||||
|
||||
[resources]
|
||||
[resources.sources]
|
||||
[resources.sources.main]
|
||||
|
|
|
@ -30,6 +30,15 @@ then
|
|||
else
|
||||
synapse_instance="synapse__$synapsenumber"
|
||||
fi
|
||||
|
||||
# Convert user choice boolean from the manifest into a config value
|
||||
if [ "$enable_relaybot" -eq "1" ]
|
||||
then
|
||||
enable_relaybot="true"
|
||||
else
|
||||
enable_relaybot="false"
|
||||
fi
|
||||
|
||||
server_name=$(ynh_app_setting_get --app $synapse_instance --key server_name)
|
||||
domain=$(ynh_app_setting_get --app $synapse_instance --key domain)
|
||||
mautrix_version=$(ynh_app_upstream_version)
|
||||
|
@ -38,6 +47,7 @@ synapse_db_name="matrix_$synapse_instance"
|
|||
|
||||
ynh_app_setting_set --app=$app --key=bot_synapse_adm --value=$bot_synapse_adm
|
||||
ynh_app_setting_set --app=$app --key=encryption --value=$encryption
|
||||
ynh_app_setting_set --app="$app" --key=enable_relaybot --value="$enable_relaybot"
|
||||
ynh_app_setting_set --app=$app --key=synapse_instance --value=$synapse_instance
|
||||
ynh_app_setting_set --app=$app --key=server_name --value=$server_name
|
||||
ynh_app_setting_set --app=$app --key=mautrix_version --value=$mautrix_version
|
||||
|
|
|
@ -31,3 +31,23 @@ ynh_secure_remove --file="$signald_data"
|
|||
# Remove signald system user
|
||||
ynh_system_user_delete --username=$signald_user
|
||||
|
||||
|
||||
#=================================================
|
||||
# MIGRATION 2 : MISSING CONFIGURATION VARIABLES
|
||||
#=================================================
|
||||
|
||||
# Check if variable exists
|
||||
enable_relaybot="$(ynh_app_setting_get --app="$app" --key=enable_relaybot)"
|
||||
|
||||
if [[ ! "$enable_relaybot" = "true" && ! "$enable_relaybot" = "false" ]] # Check setting is valid
|
||||
then
|
||||
enable_relaybot=$(python yaml2json.py "$install_dir/config.yaml" | jq -r .bridge.relay.enabled)
|
||||
if [[ ! "$enable_relaybot" = "true" && ! "$enable_relaybot" = "false" ]]
|
||||
then
|
||||
ynh_script_progression --message="Previous setting for enable_relaybot was invalid, defaulting to enabled" --weight=2
|
||||
enable_relaybot="true"
|
||||
else
|
||||
ynh_script_progression --message="Migrating previous configuration value for enable_relaybot: $enable_relaybot" --weight=1
|
||||
fi
|
||||
ynh_app_setting_set --app="$app" --key=enable_relaybot --value="$enable_relaybot"
|
||||
fi
|
||||
|
|
18
scripts/yaml2json.py
Normal file
18
scripts/yaml2json.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
# Usage: yaml2json.py <file>
|
||||
|
||||
import sys
|
||||
import yaml
|
||||
import json
|
||||
|
||||
|
||||
assert len(sys.argv) == 2, "Expected a file as argument"
|
||||
|
||||
|
||||
with open(sys.argv[1], "r") as f:
|
||||
y = yaml.safe_load(f)
|
||||
|
||||
j = json.dumps(y)
|
||||
|
||||
print(j)
|
Loading…
Reference in a new issue