#!/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() 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. set__registrations_require_3pid() { # 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 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" # 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"; allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidemail})'"; done; ;; 'msisdn') # registrations_require_3pid: part 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" # allowed_local_3pids: part allowedLocal3pids=${allowedLocal3pids}"\1" readarray -td, arr3pidmsisdn < <(echo ${allowed_local_3pids_msisdn}); for pidmsisdn in "${arr3pidmsisdn[@]}"; do # add it to regex substitution part allowedLocal3pids=${allowedLocal3pids}"\n - medium: msisdn"; allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidmsisdn})'"; done; ;; 'email&msisdn') # registrations_require_3pid: part 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" # 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"; allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidemail})'"; done; readarray -td, arr3pidmsisdn < <(echo ${allowed_local_3pids_msisdn}); for pidmsisdn in "${arr3pidmsisdn[@]}"; do # add it to regex substitution part allowedLocal3pids=${allowedLocal3pids}"\n - medium: msisdn"; allowedLocal3pids=${allowedLocal3pids}"\n$(echo ' ')pattern: '$(echo ${pidmsisdn})'"; done; ;; *) 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" # empty fields and comment registration allowedLocal3pids=${allowedLocal3pids}"#\1" ;; esac # finalize regex then apply sed command on the homeserver conf file allowedLocal3pids="${allowedLocal3pids}\n;"; sed -i -z -r "${allowedLocal3pids}" "/etc/matrix-$app/homeserver.yaml" 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() { set__registrations_require_3pid; 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() { set__registrations_require_3pid; 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 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" else readarray -td, arrroom < <(echo ${auto_join_rooms}); # print header then all space separated values autoJoinRooms="s|#?([^\S\n]*auto_join_rooms:)\n(#?[^\S\n]*-[^\n]*\n)*|\1"; for room in "${arrroom[@]}"; do autoJoinRooms="${autoJoinRooms}\n - '$(echo ${room})'"; done; autoJoinRooms="${autoJoinRooms}\n|"; sed -i -z -r "${autoJoinRooms}" "/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