From 7da9eb853b5dd769084f63b20e7f5d4eda5b3b31 Mon Sep 17 00:00:00 2001 From: Robles Rodolphe Date: Thu, 9 Apr 2020 16:00:23 +0200 Subject: [PATCH] try to debug slash for root directory in install and upgrade --- scripts/change_url | 45 ++++++++++++++++++++++++++++++++------------- scripts/install | 9 +++++++-- scripts/upgrade | 6 +++++- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/scripts/change_url b/scripts/change_url index 067a756..7685e2a 100644 --- a/scripts/change_url +++ b/scripts/change_url @@ -51,34 +51,46 @@ fi #================================================= # 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 final_path=/var/www/$app # 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" + # # Replace locations starting with old_path + # # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) + # ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" + # # Replace path in "return" directives + # ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path" + # # Calculate and store the nginx config file checksum + # ynh_store_file_checksum "$nginx_conf_path" + # # ynh_replace_string # Make a backup of the original nginx config file if modified - ynh_backup_if_checksum_is_different "$nginx_conf_path" - # Replace locations starting with old_path - # Look for every location possible patterns (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location) - ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? $old_path" "location\1 $new_path" "$nginx_conf_path" - # Replace path in "return" directives - ynh_replace_string "return \([[:digit:]]\{3\}\) $old_path" "return \1 $new_path" "$nginx_conf_path" - # Calculate and store the nginx config file checksum - ynh_store_file_checksum "$nginx_conf_path" - # ynh_replace_string + 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 +elif [ "$new_path" == "/" ] +then + ynh_replace_string --match_string="const WWW_URI = '$old_path/';" --replace_string="const WWW_URI = '$new_path';" --target_file="$final_path/config.local.php" +else ynh_replace_string --match_string="const WWW_URI = '$old_path/';" --replace_string="const WWW_URI = '$new_path/';" --target_file="$final_path/config.local.php" fi +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" + 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 "/etc/nginx/conf.d/$new_domain.d/$app.conf" + ynh_store_file_checksum --file="/etc/nginx/conf.d/$new_domain.d/$app.conf" fi #================================================= @@ -86,5 +98,12 @@ fi #================================================= # RELOAD NGINX #================================================= +ynh_script_progression --message="Reloading nginx web server..." --time --weight=1 -systemctl reload nginx +ynh_systemd_action --service_name=nginx --action=reload + +#================================================= +# END OF SCRIPT +#================================================= + +ynh_script_progression --message="Change of URL completed for $app" --time --last \ No newline at end of file diff --git a/scripts/install b/scripts/install index b6b6388..3d48aba 100644 --- a/scripts/install +++ b/scripts/install @@ -132,9 +132,14 @@ systemctl reload nginx #================================================= key=$(ynh_string_random --length=50) cp -a $final_path/config.dist.php $final_path/config.local.php - -ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" ynh_replace_string --match_string="const SECRET_KEY = '3xUhIgGwuovRKOjVsVPQ5yUMfXUSIOX2GKzcebsz5OINrYC50r';" --replace_string="const SECRET_KEY = '$key';" --target_file="$final_path/config.local.php" +if [ "$path_url" == "/" ] +then + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url';" --target_file="$final_path/config.local.php" +else + ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php" +fi + # ynh_replace_string --match_string="const ROOT = __DIR__;" --replace_string="const ROOT = /var/www/garradin/;" --target_file="$final_path/config.local.php" # ynh_replace_string --match_string="const PREFER_HTTPS = false;" --replace_string="const PREFER_HTTPS = true;" --target_file="$final_path/config.local.php" # echo "const WWW_URI = '$path_url/';" >> $final_path/config.local.php diff --git a/scripts/upgrade b/scripts/upgrade index 6c534ee..30bbc66 100644 --- a/scripts/upgrade +++ b/scripts/upgrade @@ -185,6 +185,11 @@ ynh_systemd_action --service_name=nginx --action=reload #================================================= # backup bdd, squelettes directory and config.local.php #================================================= +if [ "$new_path" == "/" ] + echo "const WWW_URI = '$path_url';" >> $final_path/config.local.php +else + echo "const WWW_URI = '$path_url/';" >> $final_path/config.local.php +fi backup_bdd=/tmp/association.sqlite backup_squelettes=/tmp/squelettes @@ -199,7 +204,6 @@ then cp -a $backup_bdd $final_path/association.sqlite fi -echo "const WWW_URI = '$path_url/';" >> $final_path/config.local.php #cp -a $final_path/config.dist.php $final_path/config.local.php # ynh_replace_string --match_string="//const WWW_URI = '/asso/';" --replace_string="const WWW_URI = '$path_url/';" --target_file="$final_path/config.local.php"