diff --git a/scripts/change_url b/scripts/change_url index 8058180..7dbfb7a 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -22,7 +22,7 @@ new_path=$YNH_APP_NEW_PATH app=$YNH_APP_INSTANCE_NAME #================================================= -# CHECK THE SYNTAX OF THE PATHS +# CHECK PATHS SYNTAX #================================================= test -n "$old_path" || old_path="/" @@ -46,21 +46,10 @@ then change_path=1 fi -#================================================= -# MANAGE FAILURE OF THE SCRIPT -#================================================= - -ynh_clean_setup () { -# Nettoyage des résidus d'installation non pris en charge par le script remove. - ynh_clean_check_starting -} -# Exit if an error occurs during the execution of the script -ynh_abort_if_errors - #================================================= # STANDARD MODIFICATIONS #================================================= -# MODIFY URL IN NGINX CONF +# MODIFY URL IN NGINX CONF FILE #================================================= nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf @@ -70,67 +59,53 @@ 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" - - # Move from sub path to root - if [ "$new_path" == "/" ] + # Set global variables for nginx helper + domain="$old_domain" + path_url="$new_path" + # Store path_url setting + ynh_app_setting_set $app path_url "$path_url" + # Create a dedicated nginx config + ynh_add_nginx_config + if [ "$path_url" = "/" ] then - ynh_replace_string "^location $old_path/" "location $new_path" "$nginx_conf_path" - ynh_replace_string "^.*rewrite.*\^/" "#sub_path_only&" "$nginx_conf_path" - ynh_replace_string "^location ~\* $old_path/" "location ~* $new_path" "$nginx_conf_path" - - # Change the path in the two rewrite instructions - ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path" "$nginx_conf_path" - ynh_replace_string "\(rewrite *\^\)$old_path/*admin\$ $old_path/*" "\1${new_path}admin\$ $new_path" "$nginx_conf_path" - - # Move to a sub path + # Replace "//" location (due to nginx template) + # Prevent from replacing in "http://" expressions by excluding ":" as preceding character + sed --in-place "s@\([^:]\)//@\1/@g" "$nginx_conf_path" else - ynh_replace_string "^location $old_path.*" "location $new_path/ {" "$nginx_conf_path" - ynh_replace_string "^#sub_path_only" "" "$nginx_conf_path" - ynh_replace_string "^location ~\* $old_path/*" "location ~* $new_path/" "$nginx_conf_path" - - # Change the path in the two rewrite instructions - ynh_replace_string "\(rewrite *\^\)$old_path\$ $old_path/*" "\1$new_path$ $new_path/" "$nginx_conf_path" - ynh_replace_string "\(rewrite *\^\)$old_path/*admin\$ $old_path/*" "\1$new_path/admin\$ $new_path/" "$nginx_conf_path" + # Move prefix comment #for-subdir at end of lines + sed --in-place "s/#for-subdir\(.*\)/\1 #for-subdir/g" "$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 - # 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 - - nginx_conf_path=/etc/nginx/conf.d/$new_domain.d/$app.conf - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" + # 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 #================================================= +# SPECIFIC MODIFICATIONS +#================================================= + # STOP TRANSMISSION -#================================================= - systemctl stop transmission-daemon -#================================================= -# CHANGE TRANSMISSION CONFIGURATION -#================================================= - if [ $change_path -eq 1 ] then - [ "$new_path" = "/" ] || new_path=${new_path}/ - ynh_replace_string "\"rpc-url\": \"${old_path}transmission/\"" "\"rpc-url\": \"${new_path}transmission/\"" /etc/transmission-daemon/settings.json + [ "$new_path" = "/" ] || new_path=${new_path}/ + ynh_replace_string "\"rpc-url\": \"${old_path}transmission/\"" "\"rpc-url\": \"${new_path}transmission/\"" /etc/transmission-daemon/settings.json fi -#================================================= # START TRANSMISSION -#================================================= - systemctl start transmission-daemon +#================================================= +# GENERIC FINALIZATION #================================================= # RELOAD NGINX #=================================================