2018-08-03 16:06:29 +02:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
|
|
#=================================================
|
|
|
|
# GENERIC START
|
|
|
|
#=================================================
|
|
|
|
# IMPORT GENERIC HELPERS
|
|
|
|
#=================================================
|
|
|
|
|
|
|
|
source /usr/share/yunohost/helpers
|
|
|
|
|
|
|
|
# Stop script if errors
|
|
|
|
ynh_abort_if_errors
|
2023-04-18 22:48:23 +02:00
|
|
|
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}"
|
2023-07-02 21:12:53 +02:00
|
|
|
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"
|
2023-04-18 22:48:23 +02:00
|
|
|
ynh_add_nginx_conf
|
|
|
|
}
|
2018-08-03 16:06:29 +02:00
|
|
|
|
2023-06-29 16:09:16 +02:00
|
|
|
get__registrations_require_3pid() {
|
2023-07-02 21:10:42 +02:00
|
|
|
registrations_require_3pid=$(ynh_app_setting_get --app $app --key registrations_require_3pid)
|
2023-06-29 16:09:16 +02:00
|
|
|
echo "${registrations_require_3pid}"
|
|
|
|
}
|
|
|
|
|
2023-07-06 08:53:43 +02:00
|
|
|
# set__registrations_require_3pid() this function is setting datas for registrations_require_3pid field and allowed_local_3pids_(email/msisdn)
|
|
|
|
# it consist on comment or not "registrations_require_3pid:", " - email" and/or " - msisdn"
|
|
|
|
# then depending on the "registrations_require_3pid" value it comment or not "allowed_local_3pids:" lines
|
|
|
|
# and generate all it sub configuration :
|
|
|
|
#
|
|
|
|
# allowed_local_3pids:
|
|
|
|
# - medium: email
|
|
|
|
# pattern: *
|
|
|
|
# ...
|
|
|
|
# - medium: msisdn
|
|
|
|
# pattern: *
|
|
|
|
#
|
|
|
|
# sed -z and \n as new line carracter do the trick on this kind of multline replacement.
|
|
|
|
|
2023-06-29 16:09:16 +02:00
|
|
|
set__registrations_require_3pid() {
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
# search pattern to replace (it correspond to the complete section)
|
|
|
|
allowedLocal3pids="s;#?([^\S\n]*allowed_local_3pids:)\n(#?([^\S\n]*-[^\S\n]*medium:[^\S\n]*(email|msisdn)\n)#?([^\S\n]*pattern:[^\S\n]*[^\n]*\n))*;"
|
|
|
|
|
|
|
|
case ${registrations_require_3pid} in
|
|
|
|
'email')
|
|
|
|
# registrations_require_3pid: part
|
2023-07-09 15:29:41 +02:00
|
|
|
sed -i -z -r "s|#?[^\S\n]*registrations_require_3pid:\n#?[^\S\n]*-[^\S\n]*email\n#?[^\S\n]*-[^\S\n]*msisdn|registrations_require_3pid:\n - email\n# - msisdn|" "/etc/matrix-$app/homeserver.yaml"
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
# allowed_local_3pids: part
|
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\1"
|
|
|
|
|
|
|
|
readarray -td, arr3pidemail < <(echo ${allowed_local_3pids_email});
|
|
|
|
for pidemail in "${arr3pidemail[@]}"; do
|
|
|
|
# add it to regex substitution part
|
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n - medium: email";
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidemail})'";
|
2023-07-06 08:53:43 +02:00
|
|
|
done;
|
|
|
|
;;
|
|
|
|
|
|
|
|
'msisdn')
|
|
|
|
# registrations_require_3pid: part
|
2023-07-09 15:29:41 +02:00
|
|
|
sed -i -z -r "s|#?[^\S\n]*registrations_require_3pid:\n#?[^\S\n]*-[^\S\n]*email\n#?[^\S\n]*-[^\S\n]*msisdn|registrations_require_3pid:\n# - email\n - msisdn|" "/etc/matrix-$app/homeserver.yaml"
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
# allowed_local_3pids: part
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\1"
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
readarray -td, arr3pidmsisdn < <(echo ${allowed_local_3pids_msisdn});
|
|
|
|
for pidmsisdn in "${arr3pidmsisdn[@]}"; do
|
|
|
|
# add it to regex substitution part
|
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n - medium: msisdn";
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidmsisdn})'";
|
2023-07-06 08:53:43 +02:00
|
|
|
done;
|
|
|
|
;;
|
|
|
|
|
|
|
|
'email&msisdn')
|
|
|
|
# registrations_require_3pid: part
|
2023-07-09 15:29:41 +02:00
|
|
|
sed -i -z -r "s|#?[^\S\n]*registrations_require_3pid:\n#?[^\S\n]*-[^\S\n]*email\n#?[^\S\n]*-[^\S\n]*msisdn|registrations_require_3pid:\n - email\n - msisdn|" "/etc/matrix-$app/homeserver.yaml"
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
# allowed_local_3pids: part
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\1"
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
readarray -td, arr3pidemail < <(echo ${allowed_local_3pids_email});
|
|
|
|
for pidemail in "${arr3pidemail[@]}"; do
|
|
|
|
# add it to regex substitution part
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n - medium: email";
|
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidemail})'";
|
2023-07-06 08:53:43 +02:00
|
|
|
done;
|
|
|
|
|
|
|
|
readarray -td, arr3pidmsisdn < <(echo ${allowed_local_3pids_msisdn});
|
|
|
|
for pidmsisdn in "${arr3pidmsisdn[@]}"; do
|
|
|
|
# add it to regex substitution part
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n - medium: msisdn";
|
|
|
|
allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidmsisdn})'";
|
2023-07-06 08:53:43 +02:00
|
|
|
done;
|
|
|
|
;;
|
|
|
|
|
|
|
|
*)
|
2023-07-09 15:29:41 +02:00
|
|
|
sed -i -z -r "s|#?[^\S\n]*registrations_require_3pid:\n#?[^\S\n]*-[^\S\n]*email\n#?[^\S\n]*-[^\S\n]*msisdn|#registrations_require_3pid:\n# - email\n# - msisdn|" "/etc/matrix-$app/homeserver.yaml"
|
2023-07-06 08:53:43 +02:00
|
|
|
|
|
|
|
# empty fields and comment registration
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids=${allowedLocal3pids}"#\1"
|
2023-07-06 08:53:43 +02:00
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# finalize regex then apply sed command on the homeserver conf file
|
2023-07-09 15:29:41 +02:00
|
|
|
allowedLocal3pids="${allowedLocal3pids}\n;";
|
2023-07-06 08:53:43 +02:00
|
|
|
sed -i -z -r "${allowedLocal3pids}" "/etc/matrix-$app/homeserver.yaml"
|
|
|
|
|
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=registrations_require_3pid --value="${registrations_require_3pid}"
|
2023-06-29 16:09:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get__allowed_local_3pids_email() {
|
2023-07-06 08:53:43 +02:00
|
|
|
allowed_local_3pids_email=$(ynh_app_setting_get --app $app --key allowed_local_3pids_email)
|
|
|
|
echo "${allowed_local_3pids_email}"
|
2023-06-29 16:09:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set__allowed_local_3pids_email() {
|
2023-07-06 08:53:43 +02:00
|
|
|
set__registrations_require_3pid;
|
2023-07-02 20:47:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value="${allowed_local_3pids_email}"
|
2023-07-01 11:27:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
get__allowed_local_3pids_msisdn() {
|
2023-07-06 08:53:43 +02:00
|
|
|
allowed_local_3pids_msisdn=$(ynh_app_setting_get --app $app --key allowed_local_3pids_msisdn)
|
|
|
|
echo "${allowed_local_3pids_msisdn}"
|
2023-07-01 11:27:41 +02:00
|
|
|
}
|
2023-06-29 16:09:16 +02:00
|
|
|
|
2023-07-01 11:27:41 +02:00
|
|
|
set__allowed_local_3pids_msisdn() {
|
2023-07-06 08:53:43 +02:00
|
|
|
set__registrations_require_3pid;
|
2023-07-02 20:47:44 +02:00
|
|
|
ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value="${allowed_local_3pids_msisdn}"
|
2023-06-29 16:09:16 +02:00
|
|
|
}
|
|
|
|
|
2023-07-01 16:07:50 +02:00
|
|
|
get__auto_join_rooms() {
|
2023-07-06 08:53:43 +02:00
|
|
|
auto_join_rooms=$(ynh_app_setting_get --app $app --key auto_join_rooms)
|
|
|
|
echo "${auto_join_rooms}"
|
2023-07-01 16:07:50 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
set__auto_join_rooms() {
|
2023-06-29 16:09:16 +02:00
|
|
|
|
2023-07-01 16:07:50 +02:00
|
|
|
if [ -z ${auto_join_rooms} ] ; then
|
2023-07-06 08:53:43 +02:00
|
|
|
# remove all values comment header and example value
|
|
|
|
sed -i -z -r "s|#?([^\S\n]*auto_join_rooms:\n)#?([^\S\n]*-[^\n]*\n)*|#\1# - \"#example:example.com\"\n|" "/etc/matrix-$app/homeserver.yaml"
|
2023-07-01 16:07:50 +02:00
|
|
|
else
|
|
|
|
|
2023-07-06 08:53:43 +02:00
|
|
|
readarray -td, arrroom < <(echo ${auto_join_rooms});
|
2023-07-01 16:07:50 +02:00
|
|
|
|
|
|
|
# print header then all space separated values
|
2023-07-06 08:53:43 +02:00
|
|
|
autoJoinRooms="s|#?([^\S\n]*auto_join_rooms:)\n(#?[^\S\n]*-[^\n]*\n)*|\1";
|
2023-07-01 16:07:50 +02:00
|
|
|
for room in "${arrroom[@]}"; do
|
2023-07-06 08:53:43 +02:00
|
|
|
autoJoinRooms="${autoJoinRooms}\n - '$(echo ${room})'";
|
2023-07-01 16:07:50 +02:00
|
|
|
done;
|
2023-07-06 08:53:43 +02:00
|
|
|
autoJoinRooms="${autoJoinRooms}\n|";
|
|
|
|
sed -i -z -r "${autoJoinRooms}" "/etc/matrix-$app/homeserver.yaml"
|
2023-07-01 16:07:50 +02:00
|
|
|
fi
|
2023-07-02 20:47:44 +02:00
|
|
|
|
|
|
|
ynh_app_setting_set --app=$app --key=auto_join_rooms --value="${auto_join_rooms}"
|
2023-07-01 16:07:50 +02:00
|
|
|
}
|
2023-07-01 10:25:47 +02:00
|
|
|
|
2018-08-03 16:06:29 +02:00
|
|
|
#=================================================
|
|
|
|
# GENERIC FINALIZATION
|
|
|
|
#=================================================
|
|
|
|
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
|
|
|
|
#=================================================
|
2023-01-11 15:02:48 +01:00
|
|
|
ynh_app_config_run $1
|