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

Use ynh_replace_string

This commit is contained in:
Jimmy Monin 2017-09-05 21:17:03 +02:00
parent 4ac33ccf59
commit 99fe5e9a3b

View file

@ -67,26 +67,26 @@ if [ $change_path -eq 1 ]
then
if [ "$new_path" = "/" ] && [ "$old_path" != "/" ] ; then
# Replace path in several location occurrences based on different recognition patterns
sed --in-place "s@location $old_path/ {\$@location / {@" "$nginx_conf_path"
ynh_replace_string "location $old_path/ {\$" "location / {" "$nginx_conf_path"
ynh_replace_string "location ~ ^$old_path" "location ~ ^" "$nginx_conf_path"
ynh_replace_string "location $old_path {" "location / {" "$nginx_conf_path"
ynh_replace_string "rewrite ^ $old_path" "rewrite ^ " "$nginx_conf_path"
# Move #for-subdir comment at the beginning of the line (line not needed for "/" path)
sed --in-place "s/\(.*\) #for-subdir/#for-subdir \1/g" "$nginx_conf_path"
ynh_replace_string "\(.*\) #for-subdir" "#for-subdir \1" "$nginx_conf_path"
elif [ "$new_path" != "/" ] && [ "$old_path" = "/" ] ; then
# Move #for-subdir comment at the end of the line (line needed for "/path" path)
sed --in-place "s/#for-subdir\(.*\)/\1 #for-subdir/g" "$nginx_conf_path"
ynh_replace_string "#for-subdir\(.*\)" "\1 #for-subdir" "$nginx_conf_path"
# Replace path in several location occurrences based on different recognition patterns
sed --in-place "s@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 "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 (see https://nginx.org/en/docs/http/ngx_http_core_module.html#location)
sed --in-place "s@location\( \(=\|~\|~\*\|\^~\)\)\? \(\^\)\?$old_path@location\1 \3$new_path@" "$nginx_conf_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