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

Simplify change_url script by using newly accessible conf folder

This commit is contained in:
Jimmy Monin 2018-01-27 16:18:03 +01:00
parent 5c4b874536
commit e0edf9cd6c
2 changed files with 15 additions and 31 deletions

View file

@ -15,7 +15,7 @@
}, },
"multi_instance": true, "multi_instance": true,
"requirements": { "requirements": {
"yunohost": ">= 2.7.2" "yunohost": ">= 2.7.12"
}, },
"services": [ "services": [
"nginx", "nginx",

View file

@ -66,35 +66,19 @@ nginx_conf_path=/etc/nginx/conf.d/$old_domain.d/$app.conf
# Change the path in the nginx config file # Change the path in the nginx config file
if [ $change_path -eq 1 ] if [ $change_path -eq 1 ]
then then
# Make a backup of the original nginx config file if modified domain="$old_domain"
ynh_backup_if_checksum_is_different "$nginx_conf_path" path_url="$new_path"
if [ "$new_path" = "/" ] && [ "$old_path" != "/" ] ; then ynh_add_nginx_config
# Replace path in several location occurrences based on different recognition patterns if [ "$path_url" = "/" ]
ynh_replace_string "location $old_path/ {\$" "location / {" "$nginx_conf_path" then
ynh_replace_string "location ~ ^$old_path" "location ~ ^" "$nginx_conf_path" # Replace "//" location (due to nginx template)
ynh_replace_string "location $old_path {" "location / {" "$nginx_conf_path" # Prevent from replacing in "http://" expressions by excluding ":" as preceding character
ynh_replace_string "rewrite ^ $old_path" "rewrite ^ " "$nginx_conf_path" sed --in-place "s@\([^:]\)//@\1/@g" /etc/nginx/conf.d/$domain.d/$app.conf
else
# Move #for-subdir comment at the beginning of the line (line not needed for "/" path) # Move prefix comment #for-subdir at end of lines
ynh_replace_string "\(.*\) #for-subdir" "#for-subdir \1" "$nginx_conf_path" sed --in-place "s/#for-subdir\(.*\)/\1 #for-subdir/g" /etc/nginx/conf.d/$domain.d/$app.conf
elif [ "$new_path" != "/" ] && [ "$old_path" = "/" ] ; then fi
# Move #for-subdir comment at the end of the line (line needed for "/path" path) ynh_store_file_checksum "/etc/nginx/conf.d/$domain.d/$app.conf"
ynh_replace_string "#for-subdir\(.*\)" "\1 #for-subdir" "$nginx_conf_path"
# Replace path in several location occurrences based on different recognition patterns
ynh_replace_string "location / {\$" "location $new_path/ {" "$nginx_conf_path"
ynh_replace_string "location ~ ^" "location ~ ^$new_path" "$nginx_conf_path"
ynh_replace_string "location / {" "location $new_path {" "$nginx_conf_path"
ynh_replace_string "rewrite ^ /" "rewrite ^ $new_path/" "$nginx_conf_path"
else
# Replace locations starting with old_path
# Look for every possible patterns for location directive (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location)
ynh_replace_string "location\( \(=\|~\|~\*\|\^~\)\)\? \(\^\)\?$old_path" "location\1 \3$new_path" "$nginx_conf_path"
# 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 fi
# Change the domain for nginx # Change the domain for nginx
@ -122,7 +106,7 @@ download_images_enabled=$(ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_user"
if [ "$download_images_enabled" = "1" ] ; then if [ "$download_images_enabled" = "1" ] ; then
echo "Updating images URL; this operation may take a while..." echo "Updating images URL; this operation may take a while..."
# Query/replace the domain/path in every entry.content in mysql database # Query/replace the domain/path in every entry.content in mysql database
ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_user" <<< "UPDATE entry SET content = REPLACE(content, '$old_domain$old_path', '$new_domain$new_path');" ynh_mysql_connect_as "$db_name" "$db_pwd" "$db_user" <<< "UPDATE entry SET content = REPLACE(content, '$old_domain$old_path', '$new_domain$new_path');"
fi fi
#================================================= #=================================================