summaryrefslogtreecommitdiffhomepage
path: root/tools/setup-unit
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@nginx.com>2023-04-03 18:16:28 +0200
committerAlejandro Colomar <alx@nginx.com>2023-04-15 00:29:52 +0200
commit6f36a67fc37004511299133e39d9a6fbb9d55a0c (patch)
treebc3f568c79249988928e2558576412ecf306cb63 /tools/setup-unit
parent4f8a9e305d0b45a455cb303bd29faaec0b80af02 (diff)
downloadunit-6f36a67fc37004511299133e39d9a6fbb9d55a0c.tar.gz
unit-6f36a67fc37004511299133e39d9a6fbb9d55a0c.tar.bz2
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>
Diffstat (limited to 'tools/setup-unit')
-rwxr-xr-xtools/setup-unit16
1 files changed, 7 insertions, 9 deletions
diff --git a/tools/setup-unit b/tools/setup-unit
index da276448..de1d4f5f 100755
--- a/tools/setup-unit
+++ b/tools/setup-unit
@@ -290,7 +290,11 @@ unit_ctl()
err 'ctl: Missing subcommand.';
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 sock="$(echo $sock | sed 's,ssh://[^/]*\(.*\),unix:\1,')";
fi;
@@ -298,11 +302,11 @@ unit_ctl()
case $1 in
http)
shift;
- unit_ctl_http ${remote:+ ---r $remote} ${sock:+ ---s $sock} $@;
+ unit_ctl_http ${remote:+ ---r $remote} ---s "$sock" $@;
;;
insert)
shift;
- unit_ctl_insert ${remote:+ ---r $remote} ${sock:+ ---s $sock} $@;
+ unit_ctl_insert ${remote:+ ---r $remote} ---s "$sock" $@;
;;
*)
err "ctl: $1: Unknown argument.";
@@ -403,9 +407,6 @@ unit_ctl_http()
-L "$local_sock:$remote_sock" "$remote";
sock="unix:$local_sock";
-
- elif ! test -v sock; then
- local sock="$(unit_sock_find)";
fi;
curl $curl_options -X $method -d@- \
@@ -490,9 +491,6 @@ unit_ctl_insert()
-L "$local_sock:$remote_sock" "$remote";
sock="unix:$local_sock";
-
- elif ! test -v sock; then
- local sock="$(unit_sock_find)";
fi;
local old="$(mktemp ||:)";