From 62287a7f319ac614660d97079a5d9e0caf011733 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josu=C3=A9=20Tille?= Date: Thu, 2 Aug 2018 15:59:04 +0200 Subject: [PATCH] Refactor change-url --- scripts/_common.sh | 10 +++---- scripts/change_url | 48 +++++++++------------------------- scripts/experimental_helper.sh | 11 ++++++++ 3 files changed, 28 insertions(+), 41 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index 488269f..8c016be 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -63,15 +63,15 @@ set_permission() { } config_pgadmin() { - ynh_replace_string __USER__ $pgadmin_user ../conf/config_local.py - ynh_replace_string __DOMAIN__ $domain ../conf/config_local.py cp ../conf/config_local.py $final_path/lib/python2.7/site-packages/pgadmin4/config_local.py + ynh_replace_string __USER__ $pgadmin_user $final_path/lib/python2.7/site-packages/pgadmin4/config_local.py + ynh_replace_string __DOMAIN__ $domain $final_path/lib/python2.7/site-packages/pgadmin4/config_local.py } config_uwsgi() { - ynh_replace_string __USER__ $pgadmin_user ../conf/pgadmin.ini - ynh_replace_string __FINALPATH__ $final_path ../conf/pgadmin.ini - ynh_replace_string __PATH__ $path_url ../conf/pgadmin.ini cp ../conf/pgadmin.ini /etc/uwsgi/apps-enabled/ + ynh_replace_string __USER__ $pgadmin_user /etc/uwsgi/apps-enabled/pgadmin.ini + ynh_replace_string __FINALPATH__ $final_path /etc/uwsgi/apps-enabled/pgadmin.ini + ynh_replace_string __PATH__ $path_url /etc/uwsgi/apps-enabled/pgadmin.ini } diff --git a/scripts/change_url b/scripts/change_url index 926c4bd..9c7c398 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -16,53 +16,29 @@ source ./_common.sh # Retrive arguments old_domain=$YNH_APP_OLD_DOMAIN -old_path=$YNH_APP_OLD_PATH - -new_domain=$YNH_APP_NEW_DOMAIN -new_path=$YNH_APP_NEW_PATH - -test -n "$old_path" || old_path="/" -test -n "$new_path" || new_path="/" - -new_path=$(ynh_normalize_url_path $new_path) -old_path=$(ynh_normalize_url_path $old_path) - +domain=$YNH_APP_NEW_DOMAIN +path_url=$(ynh_normalize_url_path ${YNH_APP_NEW_PATH:-'/'}) http_port=$(ynh_app_setting_get "$app" http_port) -# CHECK WHICH PARTS SHOULD BE CHANGED -change_domain=0 -if [ "$old_domain" != "$new_domain" ] -then - change_domain=1 -fi - -change_path=0 -if [ "$old_path" != "$new_path" ] -then - change_path=1 -fi - #================================================= # STANDARD MODIFICATIONS #================================================= -# MODIFY URL IN NGINX CONF -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 ] +# Update nginx config +if [ "$old_domain" != "$domain" ] then - ynh_replace_string "location $old_path" "location $new_path" "$nginx_conf_path" -fi + # Delete file checksum for the old conf file location + ynh_delete_file_checksum "/etc/nginx/conf.d/$old_domain.d/$app.conf" -# Change the domain for nginx -if [ $change_domain -eq 1 ] -then - sudo mv $nginx_conf_path /etc/nginx/conf.d/$new_domain.d/$app.conf + mv "/etc/nginx/conf.d/$old_domain.d/$app.conf" "/etc/nginx/conf.d/$domain.d/$app.conf" + + # Store file checksum for the new config file location + ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf" fi +ynh_add_nginx_config # Update UWSGI Config -ynh_replace_string "mount = $old_path=pgAdmin4.py" "mount = $new_path=pgAdmin4.py" /etc/uwsgi/apps-enabled/pgadmin.ini +config_uwsgi # Reload services sudo systemctl reload nginx.service diff --git a/scripts/experimental_helper.sh b/scripts/experimental_helper.sh index a124a52..4cfc732 100644 --- a/scripts/experimental_helper.sh +++ b/scripts/experimental_helper.sh @@ -192,4 +192,15 @@ ynh_app_package_version () { fi version_key=$(ynh_read_manifest "$manifest_path" "version") echo "${version_key/*~ynh/}" +} + +# 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 } \ No newline at end of file