From 9e0f0a565632327263c1c3466978f8bc5e759194 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 3 Apr 2019 17:52:31 +0300 Subject: [PATCH 1/5] Fix SC2086 warnings in test_key_expiration.sh --- src/test/test_key_expiration.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/test/test_key_expiration.sh b/src/test/test_key_expiration.sh index cf6608634d..5e89bbbd6a 100755 --- a/src/test/test_key_expiration.sh +++ b/src/test/test_key_expiration.sh @@ -6,7 +6,7 @@ umask 077 set -e -if [ $# -eq 0 ] || [ ! -f ${1} ] || [ ! -x ${1} ]; then +if [ $# -eq 0 ] || [ ! -f "${1}" ] || [ ! -x "${1}" ]; then if [ "$TESTING_TOR_BINARY" = "" ] ; then echo "Usage: ${0} PATH_TO_TOR [case-number]" exit 1 @@ -48,7 +48,7 @@ die() { echo "$1" >&2 ; exit 5; } check_dir() { [ -d "$1" ] || die "$1 did not exist"; } check_file() { [ -e "$1" ] || die "$1 did not exist"; } check_no_file() { [ -e "$1" ] && die "$1 was not supposed to exist" || true; } -check_files_eq() { cmp "$1" "$2" || die "$1 and $2 did not match: `dump $1` vs `dump $2`"; } +check_files_eq() { cmp "$1" "$2" || die "$1 and $2 did not match: `dump "$1"` vs `dump "$2"`"; } check_keys_eq() { check_files_eq "${SRC}/keys/${1}" "${ME}/keys/${1}"; } DATA_DIR=`mktemp -d -t tor_key_expiration_tests.XXXXXX` From 700310df613e379dc1930917f0f8a25f0c894a52 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 3 Apr 2019 17:56:52 +0300 Subject: [PATCH 2/5] Fix SC2006 warnings --- src/test/test_key_expiration.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/test/test_key_expiration.sh b/src/test/test_key_expiration.sh index 5e89bbbd6a..6e49919941 100755 --- a/src/test/test_key_expiration.sh +++ b/src/test/test_key_expiration.sh @@ -13,7 +13,7 @@ if [ $# -eq 0 ] || [ ! -f "${1}" ] || [ ! -x "${1}" ]; then fi fi -UNAME_OS=`uname -s | cut -d_ -f1` +UNAME_OS=$(uname -s | cut -d_ -f1) if test "$UNAME_OS" = 'CYGWIN' || \ test "$UNAME_OS" = 'MSYS' || \ test "$UNAME_OS" = 'MINGW'; then @@ -48,10 +48,10 @@ die() { echo "$1" >&2 ; exit 5; } check_dir() { [ -d "$1" ] || die "$1 did not exist"; } check_file() { [ -e "$1" ] || die "$1 did not exist"; } check_no_file() { [ -e "$1" ] && die "$1 was not supposed to exist" || true; } -check_files_eq() { cmp "$1" "$2" || die "$1 and $2 did not match: `dump "$1"` vs `dump "$2"`"; } +check_files_eq() { cmp "$1" "$2" || die "$1 and $2 did not match: $(dump "$1") vs $(dump "$2")"; } check_keys_eq() { check_files_eq "${SRC}/keys/${1}" "${ME}/keys/${1}"; } -DATA_DIR=`mktemp -d -t tor_key_expiration_tests.XXXXXX` +DATA_DIR=$(mktemp -d -t tor_key_expiration_tests.XXXXXX) if [ -z "$DATA_DIR" ]; then echo "Failure: mktemp invocation returned empty string" >&2 exit 3 @@ -63,7 +63,7 @@ fi trap "rm -rf '$DATA_DIR'" 0 # Use an absolute path for this or Tor will complain -DATA_DIR=`cd "${DATA_DIR}" && pwd` +DATA_DIR=$(cd "${DATA_DIR}" && pwd) touch "${DATA_DIR}/empty_torrc" From 9e04a8722081cd761ee3a2e173b53c7859a8c916 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 3 Apr 2019 17:58:05 +0300 Subject: [PATCH 3/5] Fix SC2064 warning --- src/test/test_key_expiration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test_key_expiration.sh b/src/test/test_key_expiration.sh index 6e49919941..8614a4fa48 100755 --- a/src/test/test_key_expiration.sh +++ b/src/test/test_key_expiration.sh @@ -60,7 +60,7 @@ if [ ! -d "$DATA_DIR" ]; then echo "Failure: mktemp invocation result doesn't point to directory" >&2 exit 3 fi -trap "rm -rf '$DATA_DIR'" 0 +trap 'rm -rf "$DATA_DIR"' 0 # Use an absolute path for this or Tor will complain DATA_DIR=$(cd "${DATA_DIR}" && pwd) From 4172b638b8221e2d56c20e2a408948977c68358a Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 3 Apr 2019 18:03:34 +0300 Subject: [PATCH 4/5] Fix SC2015 warning --- src/test/test_key_expiration.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test_key_expiration.sh b/src/test/test_key_expiration.sh index 8614a4fa48..1ed81c81c7 100755 --- a/src/test/test_key_expiration.sh +++ b/src/test/test_key_expiration.sh @@ -47,7 +47,7 @@ dump() { xxd -p "$1" | tr -d '\n '; } die() { echo "$1" >&2 ; exit 5; } check_dir() { [ -d "$1" ] || die "$1 did not exist"; } check_file() { [ -e "$1" ] || die "$1 did not exist"; } -check_no_file() { [ -e "$1" ] && die "$1 was not supposed to exist" || true; } +check_no_file() { if [ -e "$1" ]; then die "$1 was not supposed to exist"; fi } check_files_eq() { cmp "$1" "$2" || die "$1 and $2 did not match: $(dump "$1") vs $(dump "$2")"; } check_keys_eq() { check_files_eq "${SRC}/keys/${1}" "${ME}/keys/${1}"; } From b2eced6c0747159ab7b3942a45c1a147a5ecfc96 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 3 Apr 2019 18:05:23 +0300 Subject: [PATCH 5/5] Add changes file --- changes/bug30002 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/bug30002 diff --git a/changes/bug30002 b/changes/bug30002 new file mode 100644 index 0000000000..da61c9e4b2 --- /dev/null +++ b/changes/bug30002 @@ -0,0 +1,2 @@ + o Code simplification and refactoring (shell scripts): + - Fix shellcheck warnings in test_key_expiration.sh. Resolves issue 30002.