From ca6c628fbbecec4b3fcebcc57dafcc4c052c37e7 Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 9 May 2019 19:59:14 +0200 Subject: [PATCH 1/2] Add change_url script --- check_process | 2 +- scripts/change_url | 108 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 scripts/change_url diff --git a/check_process b/check_process index cbcaa6a..1a8c4e2 100644 --- a/check_process +++ b/check_process @@ -16,7 +16,7 @@ backup_restore=1 multi_instance=1 incorrect_path=1 - change_url=0 + change_url=1 ;;; Levels Level 1=auto Level 2=auto diff --git a/scripts/change_url b/scripts/change_url new file mode 100644 index 0000000..dc617c9 --- /dev/null +++ b/scripts/change_url @@ -0,0 +1,108 @@ +#!/bin/bash + +#================================================= +# GENERIC STARTING +#================================================= +# IMPORT GENERIC HELPERS +#================================================= + +source _common.sh +source /usr/share/yunohost/helpers + +#================================================= +# RETRIEVE 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 + +app=$YNH_APP_INSTANCE_NAME + +#================================================= +# LOAD SETTINGS +#================================================= +ynh_script_progression --message="Loading installation settings..." --time --weight=1 + +# Needed for helper "ynh_add_nginx_config" +final_path=$(ynh_app_setting_get --app=$app --key=final_path) + +# Add settings here as needed by your application +#db_name=$(ynh_app_setting_get --app=$app --key=db_name) +#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) + +#================================================= +# 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 +#================================================= +ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 + +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 --file="$nginx_conf_path" + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Create a dedicated nginx config + ynh_add_nginx_config +fi + +# Change the domain for nginx +if [ $change_domain -eq 1 ] +then + # Delete file checksum for the old conf file location + ynh_delete_file_checksum --file="$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 --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" +fi + +#================================================= +# SPECIFIC MODIFICATIONS +#================================================= +# CHANGE AMPACHE CONFIGURATION +#================================================= +ynh_script_progression --message="Updating ampache configuration..." --time --weight=1 + +conf_file="$final_path/config/ampache.cfg.php" + +ynh_replace_string --match_string="\(web_path.*=.*\)\"$old_path\"" --replace_string="\1\"$new_path\"" --target_file="$conf_file" +ynh_replace_string --match_string="\(http_host.*=.*\)\"$old_domain\"" --replace_string="\1\"$new_domain\"" --target_file="$conf_file" + +#================================================= +# GENERIC FINALISATION +#================================================= +# RELOAD NGINX +#================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 + +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --time --last From 0e360c1717f2501b58acf3ec3bbc6e1338791e3e Mon Sep 17 00:00:00 2001 From: Maniack Crudelis Date: Thu, 9 May 2019 20:02:39 +0200 Subject: [PATCH 2/2] Clean --- scripts/change_url | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index dc617c9..857edfe 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -24,15 +24,11 @@ app=$YNH_APP_INSTANCE_NAME #================================================= # LOAD SETTINGS #================================================= -ynh_script_progression --message="Loading installation settings..." --time --weight=1 +ynh_script_progression --message="Loading installation settings..." # Needed for helper "ynh_add_nginx_config" final_path=$(ynh_app_setting_get --app=$app --key=final_path) -# Add settings here as needed by your application -#db_name=$(ynh_app_setting_get --app=$app --key=db_name) -#db_pwd=$(ynh_app_setting_get --app=$app --key=db_pwd) - #================================================= # CHECK WHICH PARTS SHOULD BE CHANGED #================================================= @@ -54,7 +50,7 @@ fi #================================================= # MODIFY URL IN NGINX CONF #================================================= -ynh_script_progression --message="Updating nginx web server configuration..." --time --weight=1 +ynh_script_progression --message="Updating nginx web server configuration..." --weight=2 nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -85,7 +81,7 @@ fi #================================================= # CHANGE AMPACHE CONFIGURATION #================================================= -ynh_script_progression --message="Updating ampache configuration..." --time --weight=1 +ynh_script_progression --message="Updating ampache configuration..." conf_file="$final_path/config/ampache.cfg.php" @@ -97,7 +93,7 @@ ynh_replace_string --match_string="\(http_host.*=.*\)\"$old_domain\"" --replace_ #================================================= # RELOAD NGINX #================================================= -ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 +ynh_script_progression --message="Reloading nginx web server..." ynh_systemd_action --service_name=nginx --action=reload @@ -105,4 +101,4 @@ ynh_systemd_action --service_name=nginx --action=reload # END OF SCRIPT #================================================= -ynh_script_progression --message="Change of URL completed for $app" --time --last +ynh_script_progression --message="Change of URL completed for $app" --last