From e52fd430558bc410c67c18e138cb84b046022bb7 Mon Sep 17 00:00:00 2001 From: Fabian Wilkens Date: Fri, 12 Aug 2022 23:17:56 +0200 Subject: [PATCH] Fix: restore script --- scripts/_common.sh | 17 ++++++++--------- scripts/restore | 4 ++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/scripts/_common.sh b/scripts/_common.sh index edcbb3b..8a95269 100644 --- a/scripts/_common.sh +++ b/scripts/_common.sh @@ -15,16 +15,15 @@ pkg_dependencies="" # PERSONAL HELPERS #================================================= - # Reset failed systemd services. ynh_reset_systemd(){ systemctl reset-failed } -# Substitute/replace a string (or expression) by another in a file on a +# Substitute/replace a string (or expression) by another in a file on a line # -# usage: ynh_replace_string_occurrence --occurrence=occurrence --match_string=match_string --replace_string=replace_string --target_file=target_file -# | arg: -o, --occurrence= - Replace the nth occurrence in the file +# usage: ynh_replace_string_on_line --line=line --match_string=match_string --replace_string=replace_string --target_file=target_file +# | arg: -l, --line= - Replace match on nth line in the file # | arg: -m, --match_string= - String to be searched and replaced in the file # | arg: -r, --replace_string= - String that will replace matches # | arg: -f, --target_file= - File in which the string will be replaced. @@ -32,11 +31,11 @@ ynh_reset_systemd(){ # As this helper is based on sed command, regular expressions and references to # sub-expressions can be used (see sed manual page for more information) # -ynh_replace_string_occurrence() { +ynh_replace_string_on_line() { # Declare an array to define the options of this helper. - local legacy_args=omrf - local -A args_array=([o]=occurrence [m]=match_string= [r]=replace_string= [f]=target_file=) - local occurrence + local legacy_args=lmrf + local -A args_array=([l]=line= [m]=match_string= [r]=replace_string= [f]=target_file=) + local line local match_string local replace_string local target_file @@ -50,7 +49,7 @@ ynh_replace_string_occurrence() { replace_string=${replace_string//${delimit}/"\\${delimit}"} set -o xtrace # set -x - sed --in-place "s${delimit}${match_string}${delimit}${replace_string}${delimit}${occurrence}" "$target_file" + sed --in-place "${line} s${delimit}${match_string}${delimit}${replace_string}${delimit}" "$target_file" } #================================================ diff --git a/scripts/restore b/scripts/restore index 7182150..60b186c 100755 --- a/scripts/restore +++ b/scripts/restore @@ -180,10 +180,10 @@ ynh_replace_string --match_string="^AUTH_SERVER_URL.*$" --replace_string="AUTH_S ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_auth_worker" --target_file="$config_auth_worker" # API-Gateway Port ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_api_gateway" --target_file="$config_api_gateway" -ynh_replace_string_occurrence --occurrence="1" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_api_gateway/;" --target_file="$config_nginx" +ynh_replace_string_on_line --line="2" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_api_gateway/;" --target_file="$config_nginx" # Files Port ynh_replace_string --match_string="^PORT.*$" --replace_string="PORT=$port_files" --target_file="$config_files" -ynh_replace_string_occurrence --occurrence="2" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_files/;" --target_file="$config_nginx" +ynh_replace_string_on_line --line="17" --match_string="proxy_pass.*$" --replace_string="proxy_pass http://127.0.0.1:$port_files/;" --target_file="$config_nginx" #================================================= # RESTORE SYSTEMD