1
0
Fork 0
mirror of https://github.com/YunoHost-Apps/wallabag2_ynh.git synced 2024-10-01 13:35:06 +02:00

Handle nginx conf file checksums

This commit is contained in:
Jimmy Monin 2017-09-05 21:23:44 +02:00
parent 99fe5e9a3b
commit f0042e4aa0
2 changed files with 23 additions and 1 deletions

View file

@ -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
}

View file

@ -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
#=================================================