commit 1ebed39da12c302739b827ffb03627d7e36f9f12 Author: c c@chroniko.jp Date: Wed Jun 24 02:48:50 2020 +0000
Add `set -o errexit -o nounset` to shell scripts
For #33604 --- scripts/git/pre-commit.git-hook | 3 ++- tests/shellcheck-tests.sh | 4 ++-- tests/unit-tests.sh | 4 ++-- tools/bootstrap-network.sh | 3 +++ tools/diagnostics.sh | 3 +++ tools/hsaddress.sh | 3 +++ tools/test-network-impl.sh | 3 +++ tools/test-network.sh | 3 +++ tools/warnings.sh | 3 +++ 9 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/scripts/git/pre-commit.git-hook b/scripts/git/pre-commit.git-hook index 9aa89d2..885df80 100755 --- a/scripts/git/pre-commit.git-hook +++ b/scripts/git/pre-commit.git-hook @@ -10,7 +10,8 @@ workdir=$(git rev-parse --show-toplevel)
cd "$workdir" || exit 1
-set -e +set -o errexit +set -o nounset
if [ -e tests/shellcheck-tests.sh ]; then tests/shellcheck-tests.sh diff --git a/tests/shellcheck-tests.sh b/tests/shellcheck-tests.sh index 3a16387..9506f44 100755 --- a/tests/shellcheck-tests.sh +++ b/tests/shellcheck-tests.sh @@ -1,7 +1,7 @@ #!/bin/sh
-# Exit on errors -set -e +set -o errexit +set -o nounset
# SC1117 was disabled after 0.5, because it was too pedantic EXCLUSIONS="--exclude=SC1117" diff --git a/tests/unit-tests.sh b/tests/unit-tests.sh index 8520e8a..82688e6 100755 --- a/tests/unit-tests.sh +++ b/tests/unit-tests.sh @@ -1,7 +1,7 @@ #!/bin/sh
-# Exit on errors -set -e +set -o errexit +set -o nounset
# Output is prefixed with the name of the script myname=$(basename "$0") diff --git a/tools/bootstrap-network.sh b/tools/bootstrap-network.sh index 3c25021..d253455 100755 --- a/tools/bootstrap-network.sh +++ b/tools/bootstrap-network.sh @@ -12,6 +12,9 @@ # network-flavour: one of the files in the networks directory, # (default: 'bridges+hs-v23')
+set -o errexit +set -o nounset + # Get a working chutney path if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then # looks like a broken path: use the path to this tool instead diff --git a/tools/diagnostics.sh b/tools/diagnostics.sh index e099514..fe5065a 100755 --- a/tools/diagnostics.sh +++ b/tools/diagnostics.sh @@ -17,6 +17,9 @@ # tools/diagnostics.sh # tools/diagnostics.sh 001a
+set -o errexit +set -o nounset + if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then # looks like a broken path: use the path to this tool instead TOOLS_PATH=$(dirname "$0") diff --git a/tools/hsaddress.sh b/tools/hsaddress.sh index b975f0a..8f42540 100755 --- a/tools/hsaddress.sh +++ b/tools/hsaddress.sh @@ -7,6 +7,9 @@ # Examples: tools/hsaddress.sh # tools/hsaddress.sh 025h
+set -o errexit +set -o nounset + if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then # looks like a broken path: use the path to this tool instead TOOLS_PATH=$(dirname "$0") diff --git a/tools/test-network-impl.sh b/tools/test-network-impl.sh index e73a154..afa1c80 100755 --- a/tools/test-network-impl.sh +++ b/tools/test-network-impl.sh @@ -1,5 +1,8 @@ #!/bin/sh
+set -o errexit +set -o nounset + if ! "$CHUTNEY_PATH/tools/bootstrap-network.sh" "$NETWORK_FLAVOUR"; then if test "$?" = 77; then $ECHO "SKIP: $NETWORK_FLAVOUR not supported." diff --git a/tools/test-network.sh b/tools/test-network.sh index 09ed85c..91baa09 100755 --- a/tools/test-network.sh +++ b/tools/test-network.sh @@ -1,5 +1,8 @@ #!/bin/sh
+set -o errexit +set -o nounset + export ECHO="${ECHO:-echo}"
# Output is prefixed with the name of the script diff --git a/tools/warnings.sh b/tools/warnings.sh index 174393e..577c543 100755 --- a/tools/warnings.sh +++ b/tools/warnings.sh @@ -25,6 +25,9 @@ # CHUTNEY_WARNINGS_SKIP: # set to "true" to skip all warnings
+set -o errexit +set -o nounset + if [ "$CHUTNEY_WARNINGS_SKIP" = true ]; then exit 0 fi
tor-commits@lists.torproject.org