1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/synapse_ynh.git synced 2024-09-03 20:26:38 +02:00
synapse_ynh/scripts/config
rosbeef andino c9151251c5
Update config allowed_local_3pids
allowed_local_3pids should work
its mandatory that config part is like that
#allowed_local_3pids:
#  - medium: email
#    pattern: '<pattern>'
#  - medium: msisdn
#    pattern: 'pattern'

no more o duplicate medium with different pattern are allowed
no separated lines

should just vary the comented lines or not
the line starting spaces
2023-07-01 09:27:41 +00:00

85 lines
3.9 KiB
Bash

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
final_path=$(ynh_app_setting_get --app=$app --key=final_path)
get__max_upload_size() {
max_upload_size=$(ynh_app_setting_get --app $app --key max_upload_size)
echo "${max_upload_size}"
}
set__max_upload_size() {
ynh_write_var_in_file --file=/etc/matrix-$app/homeserver.yaml --key=max_upload_size --value="${max_upload_size}"
sed -i -r "s|client_max_body_size\s[[:digit:]]*[GMK]?;|client_max_body_size ${max_upload_size};|g" "/etc/nginx/conf.d/$domain.d/$app.conf
ynh_add_nginx_conf
}
get__registrations_require_3pid() {
max_upload_size=$(ynh_app_setting_get --app $app --key registrations_require_3pid)
echo "${registrations_require_3pid}"
}
set__registrations_require_3pid() {
# sed -z do the trick on this king of multline replacement
case ${registrations_require_3pid} in
email)
sed -i -z -r "s|#?([^\S\n]*registrations_require_3pid:\n)#?([^\S\n]*-[^\S\n]*email\n)#?([^\S\n]*-[^\S\n]*msisdn)|\1\2#\3|" "/etc/matrix-$app/homeserver.yaml"
;;
msisdn)
sed -i -z -r "s|#?([^\S\n]*registrations_require_3pid:\n)#?([^\S\n]*-[^\S\n]*email\n)#?([^\S\n]*-[^\S\n]*msisdn)|\1#\2\3|" "/etc/matrix-$app/homeserver.yaml"
;;
email&msisdn)
sed -i -z -r "s|#?([^\S\n]*registrations_require_3pid:\n)#?([^\S\n]*-[^\S\n]*email\n)#?([^\S\n]*-[^\S\n]*msisdn)|\1\2\3|" "/etc/matrix-$app/homeserver.yaml"
;;
*)
sed -i -z -r "s|#?([^\S\n]*registrations_require_3pid:\n)#?([^\S\n]*-[^\S\n]*email\n)#?([^\S\n]*-[^\S\n]*msisdn)|#\1#\2#\3|" "/etc/matrix-$app/homeserver.yaml"
;;
esac
ynh_app_setting_set --app=$app --key=registrations_require_3pid --value="${registrations_require_3pid}"
}
get__allowed_local_3pids_email() {
max_upload_size=$(ynh_app_setting_get --app $app --key allowed_local_3pids_email)
echo "${allowed_local_3pids_email}"
}
set__allowed_local_3pids_email() {
if [ -z ${registrations_require_3pid} ] ; then
sed -i -z -r "s|#?([^\S\n]*allowed_local_3pids:\n)#?([^\S\n]*-[^\S\n]*medium: email\n)#?([^\S\n]*pattern:[^\S\n]*')([^']*)('\n)#?([^\S\n]*-[^\S\n]*medium: msisdn\n)#?([^\S\n]*pattern: ')([^']*)('?)|#\1#\2#\3\4\5#\6#\7\8\9|" "/etc/matrix-$app/homeserver.yaml"
else
sed -i -z -r "s|#?([^\S\n]*allowed_local_3pids:\n)#?([^\S\n]*-[^\S\n]*medium: email\n)#?([^\S\n]*pattern:[^\S\n]*')([^']*)('\n)#?([^\S\n]*-[^\S\n]*medium: msisdn\n)#?([^\S\n]*pattern: ')([^']*)('?)|\1#\2#\3EMAIL\5#\6#\7\8\9|" "/etc/matrix-$app/homeserver.yaml"
ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value="${allowed_local_3pids_email}"
}
get__allowed_local_3pids_msisdn() {
max_upload_size=$(ynh_app_setting_get --app $app --key allowed_local_3pids_msisdn)
echo "${allowed_local_3pids_msisdn}"
}
set__allowed_local_3pids_msisdn() {
if [ -z ${registrations_require_3pid} ] ; then
sed -i -z -r "s|#?([^\S\n]*allowed_local_3pids:\n)#?([^\S\n]*-[^\S\n]*medium: email\n)#?([^\S\n]*pattern:[^\S\n]*')([^']*)('\n)#?([^\S\n]*-[^\S\n]*medium: msisdn\n)#?([^\S\n]*pattern: ')([^']*)('?)|#\1#\2#\3\4\5#\6#\7\8\9|" "/etc/matrix-$app/homeserver.yaml"
else
sed -i -z -r "s|#?([^\S\n]*allowed_local_3pids:\n)#?([^\S\n]*-[^\S\n]*medium: email\n)#?([^\S\n]*pattern:[^\S\n]*')([^']*)('\n)#?([^\S\n]*-[^\S\n]*medium: msisdn\n)#?([^\S\n]*pattern: ')([^']*)('?)|\1#\2#\3\4\5#\6#\7MSISDN\9|" "/etc/matrix-$app/homeserver.yaml"
ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value="${allowed_local_3pids_msisdn}"
}
#=================================================
# GENERIC FINALIZATION
#=================================================
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
#=================================================
ynh_app_config_run $1