2024-01-13 18:39:34 +01:00
#!/bin/bash
source _common.sh
source /usr/share/yunohost/helpers
ynh_abort_if_errors
#=================================================
# SPECIFIC GETTERS FOR TOML SHORT KEY
#=================================================
2024-02-28 18:29:21 +01:00
get_config_permission() {
result=$(grep -- ".*: $role" "$install_dir/config.yaml" | sed -r "s/: $role//" | tr -d '[:blank:]' | sed '/^#/d' | tr -d '\"' | tr -d "'" | tr '\n' ',')
echo $result
}
2024-01-13 18:39:34 +01:00
get__botname() {
botname=$(ynh_app_setting_get --app $app --key botname)
echo "${botname}"
}
get__listrelaybot() {
2024-02-28 18:29:21 +01:00
role="relaybot"
existingRelaybotUsers=$(get_config_permission)
2024-01-13 18:39:34 +01:00
cat <<EOF
"$existingRelaybotUsers"
EOF
}
get__listuser() {
2024-02-28 18:29:21 +01:00
role="user"
existingUsers=$(get_config_permission)
2024-01-13 18:39:34 +01:00
cat <<EOF
"$existingUsers"
EOF
}
get__listpuppeting() {
2024-02-28 18:29:21 +01:00
role="puppeting"
existingPuppeting=$(get_config_permission)
2024-01-13 18:39:34 +01:00
cat <<EOF
"$existingPuppeting"
EOF
}
get__listfull() {
2024-02-28 18:29:21 +01:00
role="full"
existingFull=$(get_config_permission)
2024-01-13 18:39:34 +01:00
cat <<EOF
"$existingFull"
EOF
}
get__listadmin() {
2024-02-28 18:29:21 +01:00
role="admin"
existingAdmins=$(get_config_permission)
2024-01-13 18:39:34 +01:00
cat <<EOF
"$existingAdmins"
EOF
}
#=================================================
# SPECIFIC VALIDATORS FOR TOML SHORT KEYS
#=================================================
#=================================================
# SPECIFIC SETTERS FOR TOML SHORT KEYS
#=================================================
set__botname() {
old_botname=$(ynh_app_setting_get --app $app --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)
sed -i "s/bot_username:.*/bot_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"
}
ynh_app_config_run $1