From 7341d9acdc4699498a593d0ff848be5e7d7fe0c5 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sat, 2 Feb 2019 16:32:37 +0200 Subject: [PATCH 1/6] Fix all instances of SC2166 in test-network.sh --- src/test/test-network.sh | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/test/test-network.sh b/src/test/test-network.sh index b7a9f1b3c0..51b298ca84 100755 --- a/src/test/test-network.sh +++ b/src/test/test-network.sh @@ -5,7 +5,7 @@ # If we already know CHUTNEY_PATH, don't bother with argument parsing TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh" # Call the chutney version of this script, if it exists, and we can find it -if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then +if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then # we can't produce any output, because we might be --quiet # this preserves arguments with spaces correctly exec "$TEST_NETWORK" "$@" @@ -52,12 +52,12 @@ done # - if $PWD looks like a tor build directory, set it to $PWD, or # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH if [ ! -d "$TOR_DIR" ]; then - if [ -d "$BUILDDIR/src/core/or" -a -d "$BUILDDIR/src/tools" ]; then + if [ -d "$BUILDDIR/src/core/or" ] && [ -d "$BUILDDIR/src/tools" ]; then # Choose the build directory # But only if it looks like one $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR" TOR_DIR="$BUILDDIR" - elif [ -d "$PWD/src/core/or" -a -d "$PWD/src/tools" ]; then + elif [ -d "$PWD/src/core/or" ] && [ -d "$PWD/src/tools" ]; then # Guess the tor directory is the current directory # But only if it looks like one $ECHO "$myname: \$TOR_DIR not set, trying \$PWD" @@ -73,12 +73,12 @@ fi # - if $PWD looks like a chutney directory, set it to $PWD, or # - set it based on $TOR_DIR, expecting chutney to be next to tor, or # - fail and tell the user how to clone the chutney repository -if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then +if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then if [ -x "$PWD/chutney" ]; then $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD" CHUTNEY_PATH="$PWD" - elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \ - -x "$TOR_DIR/../chutney/chutney" ]; then + elif [ -d "$TOR_DIR" ] && [ -d "$TOR_DIR/../chutney" ] && \ + [ -x "$TOR_DIR/../chutney/chutney" ]; then $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney" CHUTNEY_PATH="$TOR_DIR/../chutney" else @@ -94,7 +94,7 @@ fi TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh" # Call the chutney version of this script, if it exists, and we can find it -if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then +if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then $ECHO "$myname: Calling newer chutney script $TEST_NETWORK" # this may fail if some arguments have spaces in them # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces From f888b3e2ee23f6e0394c9c7589c10e320714deda Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sat, 2 Feb 2019 16:46:30 +0200 Subject: [PATCH 2/6] Update test-network.sh to bash script to use array This lets us to save original script argument to array (POSIX shell does not support that). Fixes shellcheck warnings SC2124 and SC2086. --- src/test/test-network.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/test-network.sh b/src/test/test-network.sh index 51b298ca84..e382eec66e 100755 --- a/src/test/test-network.sh +++ b/src/test/test-network.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash # This script calls the equivalent script in chutney/tools @@ -20,7 +20,7 @@ myname=$(basename $0) # Save the arguments before we destroy them # This might not preserve arguments with spaces in them -ORIGINAL_ARGS="$@" +ORIGINAL_ARGS=( "$@" ) # We need to find CHUTNEY_PATH, so that we can call the version of this script # in chutney/tools with the same arguments. We also need to respect --quiet. @@ -99,7 +99,7 @@ if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then # this may fail if some arguments have spaces in them # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces # will be handled correctly - exec "$TEST_NETWORK" $ORIGINAL_ARGS + exec "$TEST_NETWORK" "${ORIGINAL_ARGS[@]}" # $ORIGINAL_ARGS else $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH." $ECHO "$myname: Please update your chutney using 'git pull'." From d7e5086694e722573dc46fd45f1a5571e10d5590 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sat, 2 Feb 2019 16:49:19 +0200 Subject: [PATCH 3/6] Fix one last SC2086 --- src/test/test-network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test-network.sh b/src/test/test-network.sh index e382eec66e..6c678849b6 100755 --- a/src/test/test-network.sh +++ b/src/test/test-network.sh @@ -16,7 +16,7 @@ fi # Do we output anything at all? ECHO="${ECHO:-echo}" # Output is prefixed with the name of the script -myname=$(basename $0) +myname=$(basename "$0") # Save the arguments before we destroy them # This might not preserve arguments with spaces in them From 583e20615cf0826a4b1774eead50c40d246f6962 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Sat, 2 Feb 2019 16:54:50 +0200 Subject: [PATCH 4/6] Add changes file --- changes/ticket29060 | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changes/ticket29060 diff --git a/changes/ticket29060 b/changes/ticket29060 new file mode 100644 index 0000000000..380cc8eb11 --- /dev/null +++ b/changes/ticket29060 @@ -0,0 +1,2 @@ + o Code simplification and refactoring (shell scripts): + - Fix shellcheck warnings in test-network.sh. Resolves issue 29060. From 4f9061868b04724bf3eaecddf9b536c189bd34da Mon Sep 17 00:00:00 2001 From: rl1987 Date: Wed, 13 Feb 2019 14:51:42 +0200 Subject: [PATCH 5/6] Use env to find bash --- src/test/test-network.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/test-network.sh b/src/test/test-network.sh index 6c678849b6..4d56e83806 100755 --- a/src/test/test-network.sh +++ b/src/test/test-network.sh @@ -1,4 +1,4 @@ -#!/bin/bash +#!/usr/bin/env bash # This script calls the equivalent script in chutney/tools From c346eff223e94b5fbeb6e751a99393fc5f7dd4b0 Mon Sep 17 00:00:00 2001 From: rl1987 Date: Thu, 21 Feb 2019 21:09:40 +0200 Subject: [PATCH 6/6] Walk back from requiring bash Refrain from using bash array to remember $@. --- src/test/test-network.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/test/test-network.sh b/src/test/test-network.sh index 4d56e83806..372c8cbac3 100755 --- a/src/test/test-network.sh +++ b/src/test/test-network.sh @@ -1,4 +1,4 @@ -#!/usr/bin/env bash +#!/bin/sh # This script calls the equivalent script in chutney/tools @@ -18,10 +18,6 @@ ECHO="${ECHO:-echo}" # Output is prefixed with the name of the script myname=$(basename "$0") -# Save the arguments before we destroy them -# This might not preserve arguments with spaces in them -ORIGINAL_ARGS=( "$@" ) - # We need to find CHUTNEY_PATH, so that we can call the version of this script # in chutney/tools with the same arguments. We also need to respect --quiet. until [ -z "$1" ] @@ -99,7 +95,7 @@ if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then # this may fail if some arguments have spaces in them # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces # will be handled correctly - exec "$TEST_NETWORK" "${ORIGINAL_ARGS[@]}" # $ORIGINAL_ARGS + exec "$TEST_NETWORK" "$@" else $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH." $ECHO "$myname: Please update your chutney using 'git pull'."