diff --git a/conf/nginx_regen_conf.hook b/conf/nginx_regen_conf.hook new file mode 100644 index 0000000..6e548e7 --- /dev/null +++ b/conf/nginx_regen_conf.hook @@ -0,0 +1,31 @@ +#!/bin/bash + +force=${2:-0} # 0/1 --force argument +dryrun=${3:-0} # 0/1 --dry-run argument +pending_conf=$4 # Path of the pending conf file + +do_pre_regen() { + # Put your code here for pre regen conf. + sed --in-place "s/X-Frame-Options : SAMEORIGIN/X-Frame-Options : ALLOWALL/g" "${pending_conf}/../nginx/etc/nginx/conf.d/__DOMAIN__.conf" +} + +do_post_regen() { + # Put your code here for post regen conf. + # Be careful, this part will be executed only if the configuration has been modified. + regen_conf_files=$1 +} + +case "$1" in + pre) + do_pre_regen + ;; + post) + do_post_regen + ;; + *) + echo "Hook called with unknown argument \`$1'" >&2 + exit 1 + ;; +esac + +exit 0 diff --git a/scripts/backup b/scripts/backup index 48d6c9c..40f3993 100644 --- a/scripts/backup +++ b/scripts/backup @@ -63,6 +63,13 @@ ynh_psql_dump_db --database="$db_name" > db.sql #================================================= # SPECIFIC BACKUP +#================================================= +# BACKUP HOOK +#================================================= +ynh_print_info --message="Backing up hook configuration..." + +ynh_backup --src_path="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" + #================================================= # BACKUP LOGROTATE #================================================= diff --git a/scripts/install b/scripts/install index 13f6b24..56e6685 100644 --- a/scripts/install +++ b/scripts/install @@ -162,7 +162,9 @@ cp ../conf/local-production.json "$final_path/config/local-production.json" # FIX NGINX DOMAIN CONFIGURATION #================================================= -ynh_replace_string --match_string="X-Frame-Options : SAMEORIGIN" --replace_string="X-Frame-Options : ALLOWALL" --target_file="/etc/nginx/conf.d/$domain.conf" +cp -R ../conf/nginx_regen_conf.hook /usr/share/yunohost/hooks/conf_regen/15-nginx_$app +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" +yunohost tools regen-conf nginx #================================================= # STORE THE CHECKSUM OF THE CONFIG FILE diff --git a/scripts/remove b/scripts/remove index 5b44809..df5dca4 100644 --- a/scripts/remove +++ b/scripts/remove @@ -102,7 +102,8 @@ fi # RESTORE ORIGINAL NGINX DOMAIN CONFIGURATION #================================================= -ynh_replace_string --match_string="X-Frame-Options : ALLOWALL" --replace_string="X-Frame-Options : SAMEORIGIN" --target_file="/etc/nginx/conf.d/$domain.conf" +ynh_secure_remove --file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" +yunohost tools regen-conf nginx #================================================= # GENERIC FINALIZATION diff --git a/scripts/restore b/scripts/restore index e381ca5..36f36e5 100644 --- a/scripts/restore +++ b/scripts/restore @@ -105,7 +105,8 @@ ynh_install_extra_app_dependencies --repo="deb https://dl.yarnpkg.com/debian/ st # FIX NGINX DOMAIN CONFIGURATION #================================================= -ynh_replace_string --match_string="X-Frame-Options : SAMEORIGIN" --replace_string="X-Frame-Options : ALLOWALL" --target_file="/etc/nginx/conf.d/$domain.conf" +ynh_restore_file --origin_path="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" +yunohost tools regen-conf nginx #================================================= # RESTORE THE POSTGRESQL DATABASE diff --git a/scripts/upgrade b/scripts/upgrade index 1c61765..f3f5e10 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -188,7 +188,9 @@ ynh_store_file_checksum --file="$final_path/config/production.yaml" # FIX NGINX DOMAIN CONFIGURATION #================================================= -ynh_replace_string --match_string="X-Frame-Options : SAMEORIGIN" --replace_string="X-Frame-Options : ALLOWALL" --target_file="/etc/nginx/conf.d/$domain.conf" +cp -R ../conf/nginx_regen_conf.hook /usr/share/yunohost/hooks/conf_regen/15-nginx_$app +ynh_replace_string --match_string="__DOMAIN__" --replace_string="$domain" --target_file="/usr/share/yunohost/hooks/conf_regen/15-nginx_$app" +yunohost tools regen-conf nginx #================================================= # BUILD YARN DEPENDENCIES