diff mbox series

[nft,6/7] tools: check more strictly for bash shebang in "check-tree.sh"

Message ID 20231031185449.1033380-7-thaller@redhat.com
State Changes Requested
Headers show
Series add and check dump files for JSON in tests/shell | expand

Commit Message

Thomas Haller Oct. 31, 2023, 6:53 p.m. UTC
There is no principle problem to allow any executable/shebang. However,
it also not clear why we would want to use anything except bash.  Unless
we have a good reason, check and reject anything else.

Also not that `./tests/shell/run-tests.sh -x` only works if the shebang
is either "#!/bin/bash" or "#!/bin/bash -e". It probably could also work
with other tests, but it's unclear what they are and how to enable
verbose mode in that case.

Just check that they are all bash scripts. If there is a use-case, we
can always adjust this check.

Signed-off-by: Thomas Haller <thaller@redhat.com>
---
 tools/check-tree.sh | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/tools/check-tree.sh b/tools/check-tree.sh
index b16d37c4651b..4be874fcd85e 100755
--- a/tools/check-tree.sh
+++ b/tools/check-tree.sh
@@ -72,8 +72,13 @@  if [ "${#SHELL_TESTS[@]}" -eq 0 ] ; then
 fi
 for t in "${SHELL_TESTS[@]}" ; do
 	check_shell_dumps "$t"
-	if head -n 1 "$t" |grep -q  '^#!/bin/sh' ; then
-		msg_err "$t uses #!/bin/sh instead of /bin/bash"
+	if ! ( head -n 1 "$t" | grep -q '^#!/bin/bash\( -e\)\?$' ) ; then
+		# Currently all tests only use bash as shebang. That also
+		# works with `./tests/shell/run-tests.sh -x`.
+		#
+		# We could allow other shebangs, but for now there is no need.
+		# Unless you have a good reason, create a bash script.
+		msg_err "$t should use either \"#!/bin/bash\" or \"#!/bin/bash -e\" as shebang"
 	fi
 done