1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/synapse_ynh.git synced 2024-09-03 20:26:38 +02:00

Factorize variable initalization

This commit is contained in:
Josué Tille 2024-04-05 01:03:01 +02:00
parent 5cfb69ce78
commit 4a5841baff
No known key found for this signature in database
GPG key ID: 5F259226AD51F2F5
3 changed files with 170 additions and 199 deletions

View file

@ -92,28 +92,170 @@ configure_nginx() {
ynh_add_nginx_config ynh_add_nginx_config
} }
set_permissions() { ensure_vars_set() {
chown $app:$app -R $code_dir if [ -z "${report_stats:-}" ]; then
chmod o= -R $code_dir report_stats=false
ynh_app_setting_set --app="$app" --key=report_stats --value="$report_stats"
fi
if [ -z "${e2e_enabled_by_default:-}" ] ; then
e2e_enabled_by_default=invite
ynh_app_setting_set --app="$app" --key=e2e_enabled_by_default --value="$e2e_enabled_by_default"
fi
chmod 770 $code_dir/Coturn_config_rotate.sh if [ -z "${web_client_location:-}" ]
chmod 700 $code_dir/update_synapse_for_appservice.sh then
chmod 700 $code_dir/set_admin_user.sh web_client_location="https://matrix.to/"
element_instance=element
if yunohost --output-as plain app list | grep -q "^$element_instance"'$'; then
element_domain=$(ynh_app_setting_get --app $element_instance --key domain)
element_path=$(ynh_app_setting_get --app $element_instance --key path)
web_client_location="https://""$element_domain""$element_path"
fi
ynh_app_setting_set --app="$app" --key=web_client_location --value="$web_client_location"
fi
if [ -z "${client_base_url:-}" ]
then
client_base_url="$web_client_location"
ynh_app_setting_set --app="$app" --key=client_base_url --value="$client_base_url"
fi
if [ -z "${invite_client_location:-}" ]
then
invite_client_location="$web_client_location"
ynh_app_setting_set --app="$app" --key=invite_client_location --value="$invite_client_location"
fi
if [ -z "${allow_public_rooms_without_auth:-}" ]
then
allow_public_rooms_without_auth=${allow_public_rooms:-false}
ynh_app_setting_set --app="$app" --key=allow_public_rooms_without_auth --value="$allow_public_rooms_without_auth"
fi
if [ -z "${allow_public_rooms_over_federation:-}" ]
then
allow_public_rooms_over_federation=${allow_public_rooms:-false}
ynh_app_setting_set --app="$app" --key=allow_public_rooms_over_federation --value="$allow_public_rooms_over_federation"
fi
if [ -z "${max_upload_size:-}" ]
then
max_upload_size=100M
ynh_app_setting_set --app="$app" --key=max_upload_size --value="$max_upload_size"
fi
if [ -z "${disable_msisdn_registration:-}" ]
then
disable_msisdn_registration=true
ynh_app_setting_set --app="$app" --key=disable_msisdn_registration --value=$disable_msisdn_registration
fi
if [ -z "${account_threepid_delegates_msisdn:-}" ]
then
account_threepid_delegates_msisdn=''
ynh_app_setting_set --app="$app" --key=account_threepid_delegates_msisdn --value="$account_threepid_delegates_msisdn"
fi
if [ -z "${registrations_require_3pid:-}" ]
then
registrations_require_3pid=email
ynh_app_setting_set --app="$app" --key=registrations_require_3pid --value="$registrations_require_3pid"
fi
if [ -z "${allowed_local_3pids_email:-}" ]
then
allowed_local_3pids_email=''
ynh_app_setting_set --app="$app" --key=allowed_local_3pids_email --value="$allowed_local_3pids_email"
fi
if [ -z "${allowed_local_3pids_msisdn:-}" ]
then
allowed_local_3pids_msisdn=''
ynh_app_setting_set --app="$app" --key=allowed_local_3pids_msisdn --value="$allowed_local_3pids_msisdn"
fi
if [ -z "${account_threepid_delegates_msisdn:-}" ]
then
account_threepid_delegates_msisdn=""
ynh_app_setting_set --app="$app" --key=account_threepid_delegates_msisdn --value="$account_threepid_delegates_msisdn"
fi
if [ -z "${allow_guest_access:-}" ]
then
allow_guest_access=false
ynh_app_setting_set --app="$app" --key=allow_guest_access --value="$allow_guest_access"
fi
if [ -z "${default_identity_server:-}" ]
then
default_identity_server='https://matrix.org'
ynh_app_setting_set --app=$app --key=default_identity_server --value="$default_identity_server"
fi
if [ -z "${auto_join_rooms:-}" ]
then
auto_join_rooms=''
ynh_app_setting_set --app="$app" --key=auto_join_rooms --value="$auto_join_rooms"
fi
if [ -z "${autocreate_auto_join_rooms:-}" ]
then
autocreate_auto_join_rooms=false
ynh_app_setting_set --app="$app" --key=autocreate_auto_join_rooms --value="$autocreate_auto_join_rooms"
fi
if [ -z "${auto_join_rooms_for_guests:-}" ]
then
auto_join_rooms_for_guests=true
ynh_app_setting_set --app="$app" --key=auto_join_rooms_for_guests --value="$auto_join_rooms_for_guests"
fi
if [ -z "${enable_notifs:-}" ]
then
enable_notifs=true
ynh_app_setting_set --app="$app" --key=enable_notifs --value="$enable_notifs"
fi
if [ -z "${notif_for_new_users:-}" ]
then
notif_for_new_users=true
ynh_app_setting_set --app="$app" --key=notif_for_new_users --value="$notif_for_new_users"
fi
if [ -z "${enable_group_creation:-}" ]
then
enable_group_creation=true
ynh_app_setting_set --app="$app" --key=enable_group_creation --value="$enable_group_creation"
fi
if [ -z "${enable_3pid_lookup:-}" ]
then
enable_3pid_lookup=false
ynh_app_setting_set --app="$app" --key=enable_3pid_lookup --value="$enable_3pid_lookup"
fi
if [ -z "${push_include_content:-}" ]
then
push_include_content=true
ynh_app_setting_set --app="$app" --key=push_include_content --value="$push_include_content"
fi
if [ -z "${enable_dtls_for_audio_video_turn_call:-}" ]
then
enable_dtls_for_audio_video_turn_call=true
ynh_app_setting_set --app="$app" --key=enable_dtls_for_audio_video_turn_call --value="$enable_dtls_for_audio_video_turn_call"
fi
}
set_permissions() {
chown $app:$app -R "$code_dir"
chmod o= -R "$code_dir"
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
if [ "${1:-}" == data ]; then if [ "${1:-}" == data ]; then
find $data_dir \( \! -perm -o= \ find "$data_dir" \( \! -perm -o= \
-o \! -user $app \ -o \! -user "$app" \
-o \! -group $app \) \ -o \! -group "$app" \) \
-exec chown $app:$app {} \; \ -exec chown "$app:$app" {} \; \
-exec chmod o= {} \; -exec chmod o= {} \;
fi fi
chown $app:$app -R /etc/matrix-$app chown "$app:$app" -R /etc/matrix-"$app"
chmod u=rwX,g=rX,o= -R /etc/matrix-$app chmod u=rwX,g=rX,o= -R /etc/matrix-"$app"
setfacl -R -m user:turnserver:rX /etc/matrix-$app setfacl -R -m user:turnserver:rX /etc/matrix-"$app"
chmod 600 /etc/matrix-$app/$server_name.signing.key chmod 600 /etc/matrix-"$app"/"$server_name".signing.key
chown $app:root -R /var/log/matrix-$app chown "$app":root -R /var/log/matrix-"$app"
setfacl -R -m user:turnserver:rwX /var/log/matrix-$app setfacl -R -m user:turnserver:rwX /var/log/matrix-"$app"
} }

View file

@ -23,76 +23,19 @@ fi
ynh_script_progression --message="Storing installation settings..." --weight=1 ynh_script_progression --message="Storing installation settings..." --weight=1
report_stats="false" ensure_vars_set
e2e_enabled_by_default="off"
allow_public_rooms_without_auth="false"
allow_public_rooms_over_federation="false"
max_upload_size="100M"
disable_msisdn_registration="true"
registrations_require_3pid=email
allowed_local_3pids_email=""
allowed_local_3pids_msisdn=""
allow_guest_access="false"
account_threepid_delegates_msisdn=""
default_identity_server="https://matrix.org"
auto_join_rooms=""
autocreate_auto_join_rooms="false"
auto_join_rooms_for_guests="true"
enable_notifs="true"
notif_for_new_users="true"
enable_group_creation="true"
push_include_content="true"
enable_3pid_lookup=false
enable_dtls_for_audio_video_turn_call=true
if [ "$is_free_registration" -eq 0 ] if [ "$is_free_registration" -eq 0 ]
then then
enable_registration="false" enable_registration=false
password_enabled="false" password_enabled=false
else else
enable_registration="true" enable_registration=true
password_enabled="true" password_enabled=true
fi fi
element_ynh_url="https://matrix.to/" ynh_app_setting_set --app="$app" --key=password_enabled --value="$password_enabled"
# Get app name of first Element Instance (can be changed later in Config Panel) ynh_app_setting_set --app="$app" --key=enable_registration --value="$enable_registration"
element_instance="element"
if yunohost --output-as plain app list | grep -q "^$element_instance$"; then
element_domain=$(ynh_app_setting_get --app $element_instance --key domain)
element_path=$(ynh_app_setting_get --app $element_instance --key path)
element_ynh_url="https://""$element_domain""$element_path"
fi
web_client_location=$element_ynh_url
client_base_url=$element_ynh_url
invite_client_location=$element_ynh_url
ynh_app_setting_set --app=$app --key=report_stats --value=$report_stats
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
ynh_app_setting_set --app=$app --key=web_client_location --value=$web_client_location
ynh_app_setting_set --app=$app --key=client_base_url --value=$client_base_url
ynh_app_setting_set --app=$app --key=invite_client_location --value=$invite_client_location
ynh_app_setting_set --app=$app --key=allow_public_rooms_without_auth --value=$allow_public_rooms_without_auth
ynh_app_setting_set --app=$app --key=allow_public_rooms_over_federation --value=$allow_public_rooms_over_federation
ynh_app_setting_set --app=$app --key=max_upload_size --value=$max_upload_size
ynh_app_setting_set --app=$app --key=disable_msisdn_registration --value=$disable_msisdn_registration
ynh_app_setting_set --app=$app --key=registrations_require_3pid --value=$registrations_require_3pid
ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value=$allowed_local_3pids_email
ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value=$allowed_local_3pids_msisdn
ynh_app_setting_set --app=$app --key=account_threepid_delegates_msisdn --value=$account_threepid_delegates_msisdn
ynh_app_setting_set --app=$app --key=allow_guest_access --value=$allow_guest_access
ynh_app_setting_set --app=$app --key=default_identity_server --value=$default_identity_server
ynh_app_setting_set --app=$app --key=auto_join_rooms --value=$auto_join_rooms
ynh_app_setting_set --app=$app --key=autocreate_auto_join_rooms --value=$autocreate_auto_join_rooms
ynh_app_setting_set --app=$app --key=auto_join_rooms_for_guests --value=$auto_join_rooms_for_guests
ynh_app_setting_set --app=$app --key=password_enabled --value=$password_enabled
ynh_app_setting_set --app=$app --key=enable_notifs --value=$enable_notifs
ynh_app_setting_set --app=$app --key=notif_for_new_users --value=$notif_for_new_users
ynh_app_setting_set --app=$app --key=enable_group_creation --value=$enable_group_creation
ynh_app_setting_set --app=$app --key=push_include_content --value=$push_include_content
ynh_app_setting_set --app=$app --key=enable_registration --value=$enable_registration
ynh_app_setting_set --app=$app --key=password_enabled --value=$password_enabled
ynh_app_setting_set --app=$app --key=enable_3pid_lookup --value=$enable_3pid_lookup
ynh_app_setting_set --app=$app --key=enable_dtls_for_audio_video_turn_call --value=$enable_dtls_for_audio_video_turn_call
#================================================= #=================================================
# STANDARD MODIFICATIONS # STANDARD MODIFICATIONS

View file

@ -33,6 +33,8 @@ if [ -z "${domain:-}" ]; then
ynh_app_setting_set --app=$app --key=no_sso --value true ynh_app_setting_set --app=$app --key=no_sso --value true
fi fi
ensure_vars_set
# Define $server_name if not already defined # Define $server_name if not already defined
if [ -z "${server_name:-}" ]; then if [ -z "${server_name:-}" ]; then
server_name=$domain server_name=$domain
@ -45,135 +47,30 @@ if [ -z "${jitsi_server:-}" ]; then
ynh_app_setting_set --app=$app --key=jitsi_server --value=$jitsi_server ynh_app_setting_set --app=$app --key=jitsi_server --value=$jitsi_server
fi fi
# Define $e2e_enabled_by_default if not already defined
if [ -z "${e2e_enabled_by_default:-}" ] ; then
e2e_enabled_by_default="invite"
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
fi
if [ "$e2e_enabled_by_default" = "true" ] ; then if [ "$e2e_enabled_by_default" = "true" ] ; then
e2e_enabled_by_default="all" e2e_enabled_by_default="all"
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
fi fi
if [ "$e2e_enabled_by_default" = "false" ]; then if [ "$e2e_enabled_by_default" = "false" ]; then
e2e_enabled_by_default="off" e2e_enabled_by_default="off"
ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default ynh_app_setting_set --app=$app --key=e2e_enabled_by_default --value=$e2e_enabled_by_default
fi fi
if [ -z "${report_stats:-}" ]; then if [ "${registrations_require_3pid}" == none ]
report_stats="false"
ynh_app_setting_set --app=$app --key=report_stats --value=$report_stats
fi
if [ -z "${web_client_location:-}" ]
then
web_client_location="https://matrix.to/"
element_instance="element"
if yunohost --output-as plain app list | grep -q "^$element_instance"'$'; then
element_domain=$(ynh_app_setting_get --app $element_instance --key domain)
element_path=$(ynh_app_setting_get --app $element_instance --key path)
web_client_location="https://""$element_domain""$element_path"
fi
ynh_app_setting_set --app=$app --key=web_client_location --value=$web_client_location
fi
if [ -z "${client_base_url:-}" ]
then
client_base_url=$web_client_location
ynh_app_setting_set --app=$app --key=client_base_url --value=$client_base_url
fi
if [ -z "${invite_client_location:-}" ]
then
invite_client_location=$web_client_location
ynh_app_setting_set --app=$app --key=invite_client_location --value=$invite_client_location
fi
if [ -z "${allow_public_rooms_without_auth:-}" ]
then
allow_public_rooms_without_auth=${allow_public_rooms:-false}
ynh_app_setting_set --app=$app --key=allow_public_rooms_without_auth --value=$allow_public_rooms_without_auth
fi
if [ -z "${allow_public_rooms_over_federation:-}" ]
then
allow_public_rooms_over_federation=${allow_public_rooms:-false}
ynh_app_setting_set --app=$app --key=allow_public_rooms_over_federation --value=$allow_public_rooms_over_federation
fi
if [ -z "${max_upload_size:-}" ]
then
max_upload_size="100M"
ynh_app_setting_set --app=$app --key=max_upload_size --value=$max_upload_size
fi
if [ -z "${disable_msisdn_registration:-}" ]
then
disable_msisdn_registration="true"
ynh_app_setting_set --app=$app --key=disable_msisdn_registration --value=$disable_msisdn_registration
fi
if [ -z "${registrations_require_3pid:-}" ] || [ "${registrations_require_3pid}" == none ]
then then
registrations_require_3pid=email registrations_require_3pid=email
ynh_app_setting_set --app=$app --key=registrations_require_3pid --value=$registrations_require_3pid ynh_app_setting_set --app=$app --key=registrations_require_3pid --value=$registrations_require_3pid
fi fi
if [ -z "${allowed_local_3pids_email:-}" ] || [[ "${allowed_local_3pids_email}" =~ \'.*\' ]] # Also remove shit value from previous config panel if [[ "${allowed_local_3pids_email}" =~ \'.*\' ]] # Also remove shit value from previous config panel
then then
allowed_local_3pids_email='' allowed_local_3pids_email=''
ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value=$allowed_local_3pids_email ynh_app_setting_set --app=$app --key=allowed_local_3pids_email --value=$allowed_local_3pids_email
fi fi
if [ -z "${allowed_local_3pids_msisdn:-}" ] || [[ "${allowed_local_3pids_msisdn}" =~ \'.*\' ]] # Also remove shit value from previous config panel if [[ "${allowed_local_3pids_msisdn}" =~ \'.*\' ]] # Also remove shit value from previous config panel
then then
allowed_local_3pids_msisdn='' allowed_local_3pids_msisdn=''
ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value=$allowed_local_3pids_msisdn ynh_app_setting_set --app=$app --key=allowed_local_3pids_msisdn --value=$allowed_local_3pids_msisdn
fi fi
if [ -z "${account_threepid_delegates_msisdn:-}" ]
then
account_threepid_delegates_msisdn=""
ynh_app_setting_set --app=$app --key=account_threepid_delegates_msisdn --value=$account_threepid_delegates_msisdn
fi
if [ -z "${allow_guest_access:-}" ]
then
allow_guest_access="false"
ynh_app_setting_set --app=$app --key=allow_guest_access --value=$allow_guest_access
fi
if [ -z "${default_identity_server:-}" ]
then
default_identity_server="https://matrix.org"
ynh_app_setting_set --app=$app --key=default_identity_server --value=$default_identity_server
fi
if [ -z "${auto_join_rooms:-}" ]
then
auto_join_rooms=""
ynh_app_setting_set --app=$app --key=auto_join_rooms --value=$auto_join_rooms
fi
if [ -z "${autocreate_auto_join_rooms:-}" ]
then
autocreate_auto_join_rooms="false"
ynh_app_setting_set --app=$app --key=autocreate_auto_join_rooms --value=$autocreate_auto_join_rooms
fi
if [ -z "${auto_join_rooms_for_guests:-}" ]
then
auto_join_rooms_for_guests="true"
ynh_app_setting_set --app=$app --key=auto_join_rooms_for_guests --value=$auto_join_rooms_for_guests
fi
if [ -z "${enable_notifs:-}" ]
then
enable_notifs="true"
ynh_app_setting_set --app=$app --key=enable_notifs --value=$enable_notifs
fi
if [ -z "${notif_for_new_users:-}" ]
then
notif_for_new_users="true"
ynh_app_setting_set --app=$app --key=notif_for_new_users --value=$notif_for_new_users
fi
if [ -z "${enable_group_creation:-}" ]
then
enable_group_creation="true"
ynh_app_setting_set --app=$app --key=enable_group_creation --value=$enable_group_creation
fi
if [ -z "${enable_3pid_lookup:-}" ]
then
enable_3pid_lookup=false
ynh_app_setting_set --app=$app --key=enable_3pid_lookup --value=$enable_3pid_lookup
fi
if [ -z "${enable_registration:-}" ] if [ -z "${enable_registration:-}" ]
then then
@ -194,17 +91,6 @@ then
ynh_app_setting_set --app=$app --key=password_enabled --value=$password_enabled ynh_app_setting_set --app=$app --key=password_enabled --value=$password_enabled
fi fi
if [ -z "${push_include_content:-}" ]
then
push_include_content="true"
ynh_app_setting_set --app=$app --key=push_include_content --value=$push_include_content
fi
if [ -z "${enable_dtls_for_audio_video_turn_call:-}" ]
then
enable_dtls_for_audio_video_turn_call=true
ynh_app_setting_set --app=$app --key=enable_dtls_for_audio_video_turn_call --value=$enable_dtls_for_audio_video_turn_call
fi
# remove legacy env file into /etc/default # remove legacy env file into /etc/default
ynh_secure_remove --file=/etc/default/coturn-$app ynh_secure_remove --file=/etc/default/coturn-$app