From f0042e4aa06cd5040b4b7ec3ad206b1f8e5f01eb Mon Sep 17 00:00:00 2001 From: Jimmy Monin Date: Tue, 5 Sep 2017 21:23:44 +0200 Subject: [PATCH] Handle nginx conf file checksums --- scripts/_common.sh | 14 ++++++++++++++ scripts/change_url | 10 +++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index a1b1dc7..656978d 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -36,6 +36,7 @@ QUIET () { # redirect standard output to /dev/null $@ > /dev/null } + HUMAN_SIZE () { # Transforms a Kb-based size to a human-readable size human=$(numfmt --to=iec --from-unit=1K $1) echo $human @@ -62,3 +63,16 @@ CHECK_FINALPATH () { # Check if destination directory already exists final_path="/var/www/$app" test ! -e "$final_path" || ynh_die "This path already contains a folder" } + + +# ============= FUTURE YUNOHOST HELPER ============= +# Delete a file checksum from the app settings +# +# $app should be defined when calling this helper +# +# usage: ynh_remove_file_checksum file +# | arg: file - The file for which the checksum will be deleted +ynh_delete_file_checksum () { + local checksum_setting_name=checksum_${1//[\/ ]/_} # Replace all '/' and ' ' by '_' + ynh_app_setting_delete $app $checksum_setting_name +} diff --git a/scripts/change_url b/scripts/change_url index 34495e4..1a2bb6e 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -65,6 +65,8 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf # Change the path in the nginx config file if [ $change_path -eq 1 ] then + # Make a backup of the original nginx config file if modified + ynh_backup_if_checksum_is_different "$nginx_conf_path" if [ "$new_path" = "/" ] && [ "$old_path" != "/" ] ; then # Replace path in several location occurrences based on different recognition patterns ynh_replace_string "location $old_path/ {\$" "location / {" "$nginx_conf_path" @@ -90,12 +92,18 @@ then # Replace path in "rewrite" directive ynh_replace_string "rewrite ^ $old_path" "rewrite ^ $new_path" "$nginx_conf_path" fi + # Calculate and store the nginx config file checksum + ynh_store_file_checksum "$nginx_conf_path" fi # Change the domain for nginx if [ $change_domain -eq 1 ] then - mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "$nginx_conf_path" + mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #=================================================