]> git.ipfire.org Git - thirdparty/openssh-portable.git/commitdiff
tidy up test of $SCRATCH_DIR creation
authorPhilip Hands <phil@hands.com>
Sat, 3 Oct 2020 19:10:03 +0000 (21:10 +0200)
committerDarren Tucker <dtucker@dtucker.net>
Tue, 13 Oct 2020 01:44:38 +0000 (12:44 +1100)
SSH-Copy-ID-Upstream: 2d8b22d96c105d87743ffe8874887b06f8989b93

contrib/ssh-copy-id

index 6b8aca7d994a53e65808e3a1e7e3f9828948c975..d7c3a61f608cc6f88ed841afe54f739c49f49094 100644 (file)
@@ -290,17 +290,15 @@ installkeys_via_sftp() {
 
 
 # create a scratch dir for any temporary files needed
-SCRATCH_DIR=$(mktemp -d ~/.ssh/ssh-copy-id.XXXXXXXXXX)
-if test $? -ne 0 || test "x$SCRATCH_DIR" = "x" ; then
-  printf '%s: ERROR: mktemp failed\n' "$0" >&2
-  exit 1
-fi
-chmod 0700 $SCRATCH_DIR
-if [ -d "$SCRATCH_DIR" ] ; then
+if SCRATCH_DIR=$(mktemp -d ~/.ssh/ssh-copy-id.XXXXXXXXXX) &&
+    [ "$SCRATCH_DIR" ] && [ -d "$SCRATCH_DIR" ]
+then
+  chmod 0700 "$SCRATCH_DIR"
   SCRATCH_CLEANUP="rm -rf \"$SCRATCH_DIR\""
+  #shellcheck disable=SC2064
   trap "$SCRATCH_CLEANUP" EXIT TERM INT QUIT
 else
-  printf '%s: ERROR: Required scratch directory (%s) was not created\n' "$0" "$SCRATCH_DIR" >&2
+  printf '%s: ERROR: failed to create required temporary directory under ~/.ssh\n' "$0" >&2
   exit 1
 fi