]> git.ipfire.org Git - thirdparty/nftables.git/commitdiff
tools: check more strictly for bash shebang in "check-tree.sh"
authorThomas Haller <thaller@redhat.com>
Tue, 14 Nov 2023 16:08:30 +0000 (17:08 +0100)
committerFlorian Westphal <fw@strlen.de>
Wed, 15 Nov 2023 12:12:06 +0000 (13:12 +0100)
There is no problem in principle to allow any executable/shebang. However,
it also not clear why we would want to use anything except bash. Unless
we have a good use case, check and reject anything else.

Also not that `./tests/shell/run-tests.sh -x` only works if the shebang
is either exactly "#!/bin/bash" or "#!/bin/bash -e". While it probably
could be made work with other shebangs, the simpler thing is to just use
bash consistently.

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

Signed-off-by: Thomas Haller <thaller@redhat.com>
Signed-off-by: Florian Westphal <fw@strlen.de>
tools/check-tree.sh

index b16d37c4651b6784ab06d1f6c7cf0a20bae02a27..4be874fcd85e28e6735b36e5caf7c92a0c36d98c 100755 (executable)
@@ -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