Tools: setup-unit: unified repeated code.

Instead of doing the same operation in each subcommand, do it once in
the parent.

Reviewed-by: Andrew Clayton <a.clayton@nginx.com>
Signed-off-by: Alejandro Colomar <alx@nginx.com>
This commit is contained in:
Alejandro Colomar
2023-04-03 18:16:28 +02:00
parent 4f8a9e305d
commit 6f36a67fc3

View File

@@ -290,7 +290,11 @@ unit_ctl()
err 'ctl: Missing subcommand.'; err 'ctl: Missing subcommand.';
fi; fi;
if test -v sock && echo $sock | grep '^ssh://' >/dev/null; then if ! test -v sock; then
local sock="$(unit_sock_find)";
fi;
if echo $sock | grep '^ssh://' >/dev/null; then
local remote="$(echo $sock | sed 's,\(ssh://[^/]*\).*,\1,')"; local remote="$(echo $sock | sed 's,\(ssh://[^/]*\).*,\1,')";
local sock="$(echo $sock | sed 's,ssh://[^/]*\(.*\),unix:\1,')"; local sock="$(echo $sock | sed 's,ssh://[^/]*\(.*\),unix:\1,')";
fi; fi;
@@ -298,11 +302,11 @@ unit_ctl()
case $1 in case $1 in
http) http)
shift; shift;
unit_ctl_http ${remote:+ ---r $remote} ${sock:+ ---s $sock} $@; unit_ctl_http ${remote:+ ---r $remote} ---s "$sock" $@;
;; ;;
insert) insert)
shift; shift;
unit_ctl_insert ${remote:+ ---r $remote} ${sock:+ ---s $sock} $@; unit_ctl_insert ${remote:+ ---r $remote} ---s "$sock" $@;
;; ;;
*) *)
err "ctl: $1: Unknown argument."; err "ctl: $1: Unknown argument.";
@@ -403,9 +407,6 @@ unit_ctl_http()
-L "$local_sock:$remote_sock" "$remote"; -L "$local_sock:$remote_sock" "$remote";
sock="unix:$local_sock"; sock="unix:$local_sock";
elif ! test -v sock; then
local sock="$(unit_sock_find)";
fi; fi;
curl $curl_options -X $method -d@- \ curl $curl_options -X $method -d@- \
@@ -490,9 +491,6 @@ unit_ctl_insert()
-L "$local_sock:$remote_sock" "$remote"; -L "$local_sock:$remote_sock" "$remote";
sock="unix:$local_sock"; sock="unix:$local_sock";
elif ! test -v sock; then
local sock="$(unit_sock_find)";
fi; fi;
local old="$(mktemp ||:)"; local old="$(mktemp ||:)";