#!/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() { registrations_require_3pid=$(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() { allowed_local_3pids_email=$(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" fi ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value="${allowed_local_3pids_email}" } get__allowed_local_3pids_msisdn() { allowed_local_3pids_msisdn=$(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" fi ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value="${allowed_local_3pids_msisdn}" } get__auto_join_rooms() { auto_join_rooms=$(ynh_app_setting_get --app $app --key auto_join_rooms) echo "${auto_join_rooms}" } set__auto_join_rooms() { if [ -z ${auto_join_rooms} ] ; then # remove all values comment header ans example value sed -i -z -r "s|#?([^\S\n]*auto_join_rooms:\n)#?([^\S\n]*-[^\S\n]*"[^\"]*"\n)*|#\1# - "#example:example.com"\n\n|" "/etc/matrix-$app/homeserver.yaml" else IFS=' ' read -r -a arrroom <<< "${auto_join_rooms}"; # print header then all space separated values myregex='s|#?([^\S\n]*auto_join_rooms:)#?([^\S\n]*-[^\S\n]*"[^\"]*"\n)*|#\1'; for room in "${arrroom[@]}"; do myregex="${myregex}\n - ${room}"; done; myregex="${myregex}\n\n|"; sed -i -z -r "${myregex}" "/etc/matrix-$app/homeserver.yaml" fi ynh_app_setting_set --app=$app --key=auto_join_rooms --value="${auto_join_rooms}" } #================================================= # GENERIC FINALIZATION #================================================= # SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT #================================================= ynh_app_config_run $1