1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/snserver_ynh.git synced 2024-09-03 20:26:22 +02:00
snserver_ynh/scripts/config
2021-01-22 23:47:08 +01:00

67 lines
2.1 KiB
Bash
Executable file

#!/bin/bash
#=================================================
# GENERIC START
#=================================================
# IMPORT GENERIC HELPERS
#=================================================
source ./_common.sh
source /usr/share/yunohost/helpers
# Stop script if errors
ynh_abort_if_errors
#=================================================
# RETRIEVE ARGUMENTS
#=================================================
app=$YNH_APP_INSTANCE_NAME
access_domain=$(ynh_app_setting_get --app=$app --key=access_domain)
domain=$(ynh_app_setting_get --app=$app --key=domain)
#=================================================
# SHOW_CONFIG FUNCTION FOR 'SHOW' COMMAND
#=================================================
show_config() {
if [ ! -z $access_domain ]
then
ynh_return "YNH_CONFIG_MAIN_ACCESS_DOMAIN_ACCESS_DOMAIN=$access_domain"
else
ynh_return "YNH_CONFIG_MAIN_ACCESS_DOMAIN_ACCESS_DOMAIN=$domain"
fi
}
#=================================================
# MODIFY THE CONFIGURATION
#=================================================
apply_config() {
access_domain=${YNH_CONFIG_MAIN_ACCESS_DOMAIN_ACCESS_DOMAIN:-$access_domain}
ynh_print_info "1: $access_domain"
ynh_app_setting_set --app=$app --key=access_domain --value=$access_domain
access_domain=$(ynh_app_setting_get --app=$app --key=access_domain)
ynh_print_info "2: $access_domain"
nginx_conf_path=/etc/nginx/conf.d/$domain.d/$app.conf
ynh_delete_file_checksum --file=$nginx_conf_path
ynh_replace_string \
--match_string='more_set_headers "X-Frame-Options: allow-from .*";' \
--replace_string='more_set_headers "X-Frame-Options: allow-from '$access_domain'";' \
--target_file=$nginx_conf_path
ynh_store_file_checksum --file=$nginx_conf_path
systemctl reload nginx
}
#=================================================
# GENERIC FINALIZATION
#=================================================
# SELECT THE ACTION FOLLOWING THE GIVEN ARGUMENT
#=================================================
case $1 in
show) show_config;;
apply) apply_config;;
esac