diff --git a/scripts/_common.sh b/scripts/_common.sh index 952c13c..07ee630 100755 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -161,6 +161,7 @@ set_permissions() { chmod 770 $code_dir/Coturn_config_rotate.sh chmod 700 $code_dir/update_synapse_for_appservice.sh + chmod 700 $code_dir/set_admin_user.sh find $data_dir \( \! -perm -o= \ -o \! -user $app \ diff --git a/scripts/install b/scripts/install index 4c92b50..e52d5b9 100644 --- a/scripts/install +++ b/scripts/install @@ -254,6 +254,7 @@ ynh_use_logrotate --logfile "/var/log/matrix-$app" ynh_add_config --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh" ynh_add_config --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh" +ynh_add_config --template=../sources/set_admin_user.sh --destination=$code_dir/set_admin_user.sh #================================================= # GENERIC FINALIZATION diff --git a/scripts/upgrade b/scripts/upgrade index 189bb3c..b53de36 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -339,7 +339,7 @@ fi # MIGRATION 12 : update system user and drop yunohost user #================================================= -if grep -q matrix-$app /etc/passwd; then +if grep -q "^matrix-$app" /etc/passwd; then ynh_system_user_delete --username=matrix-$app yunohost user delete $app || true ynh_system_user_create --username=$app --home_dir=$code_dir @@ -440,6 +440,7 @@ configure_coturn ynh_add_config --template="../sources/Coturn_config_rotate.sh" --destination="$code_dir/Coturn_config_rotate.sh" ynh_add_config --template="../sources/update_synapse_for_appservice.sh" --destination="$code_dir/update_synapse_for_appservice.sh" +ynh_add_config --template=../sources/set_admin_user.sh --destination=$code_dir/set_admin_user.sh # Ensure app-service folder has exists and the config file exit (Migration) mkdir -p /etc/matrix-$app/app-service diff --git a/sources/Coturn_config_rotate.sh b/sources/Coturn_config_rotate.sh index e036579..168e85b 100644 --- a/sources/Coturn_config_rotate.sh +++ b/sources/Coturn_config_rotate.sh @@ -2,34 +2,27 @@ set -eu -app_instance=__APP__ +app=__APP__ +pushd /etc/yunohost/apps/$app/conf source /usr/share/yunohost/helpers +source ../scripts/_common.sh -coturn_config_path="/etc/matrix-$app_instance/coturn.conf" -public_ip4="$(curl ip.yunohost.org)" || true -public_ip6="$(curl ipv6.yunohost.org)" || true +domain=$(ynh_app_setting_get --app=$app --key=domain) +port_cli=$(ynh_app_setting_get --app=$app --key=port_cli) +turnserver_pwd=$(ynh_app_setting_get --app=$app --key=turnserver_pwd) +port_turnserver_tls=$(ynh_app_setting_get --app=$app --key=port_turnserver_tls) +port_turnserver_alt_tls=$(ynh_app_setting_get --app=$app --key=port_turnserver_alt_tls) -old_config_line=$(egrep "^external-ip=.*\$" $coturn_config_path) -perl -i -pe 's/(^external-ip=.*\n)*//g' $coturn_config_path +previous_checksum=$(ynh_app_setting_get --app=$app --key=checksum__etc_matrix-synapse_coturn.conf) +configure_coturn +new_checksum=$(ynh_app_setting_get --app=$app --key=checksum__etc_matrix-synapse_coturn.conf) -if [ -n "$public_ip4" ] && ynh_validate_ip4 --ip_address="$public_ip4" +setfacl -R -m user:turnserver:rX /etc/matrix-$app + +if [ "$previous_checksum" != "$new_checksum" ] then - echo "external-ip=$public_ip4" >> "$coturn_config_path" -fi - -if [ -n "$public_ip6" ] && ynh_validate_ip6 --ip_address="$public_ip6" -then - echo "external-ip=$public_ip6" >> "$coturn_config_path" -fi - -new_config_line=$(egrep "^external-ip=.*\$" "/etc/matrix-$app_instance/coturn.conf") - -setfacl -R -m user:turnserver:rX /etc/matrix-$app_instance - -if [ "$old_config_line" != "$new_config_line" ] -then - systemctl restart $app_instance-coturn.service + systemctl restart $app-coturn.service fi exit 0 diff --git a/sources/set_admin_user.sh b/sources/set_admin_user.sh new file mode 100644 index 0000000..2bbee3a --- /dev/null +++ b/sources/set_admin_user.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +set -eu + +source /usr/share/yunohost/helpers + +app=__APP__ + +db_name=$(ynh_app_setting_get --app=$app --key=db_name) +db_user=$(ynh_app_setting_get --app=$app --key=db_user) +db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) +server_name=$(ynh_app_setting_get --app=$app --key=server_name) + +if [ -z ${1:-} ]; then + echo "Usage: set_admin_user.sh user_to_set_as_admin" + exit 1 +fi + +ynh_psql_execute_as_root --database=$db_name --sql="UPDATE users SET admin = 1 WHERE name = '@$1:$server_name'" + +exit 0