summaryrefslogtreecommitdiffstats
path: root/t/recipes/checks/scripts/scripts-bashisms
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:42:30 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-14 13:42:30 +0000
commit75808db17caf8b960b351e3408e74142f4c85aac (patch)
tree7989e9c09a4240248bf4658a22208a0a52d991c4 /t/recipes/checks/scripts/scripts-bashisms
parentInitial commit. (diff)
downloadlintian-75808db17caf8b960b351e3408e74142f4c85aac.tar.xz
lintian-75808db17caf8b960b351e3408e74142f4c85aac.zip
Adding upstream version 2.117.0.upstream/2.117.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 't/recipes/checks/scripts/scripts-bashisms')
-rw-r--r--t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/postinst87
-rw-r--r--t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/prerm186
-rw-r--r--t/recipes/checks/scripts/scripts-bashisms/build-spec/fill-values4
-rw-r--r--t/recipes/checks/scripts/scripts-bashisms/eval/desc2
-rw-r--r--t/recipes/checks/scripts/scripts-bashisms/eval/hints14
5 files changed, 293 insertions, 0 deletions
diff --git a/t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/postinst b/t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/postinst
new file mode 100644
index 0000000..7004ffc
--- /dev/null
+++ b/t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/postinst
@@ -0,0 +1,87 @@
+#! /bin/sh -e
+
+# valid
+. /usr/share/lintian/shell || exit 0
+. /usr/share/lintian/shell >/dev/null
+. /usr/share/lintian/shell 2>/dev/null
+. /usr/share/lintian/shell </dev/null
+. "$(dirname $0)/shell" ; bar
+# invalid
+. /usr/share/lintian/shell foo
+. "$(dirname $0)/shell" bar
+
+print "Hit enter to continue"
+read
+
+H[0]='this is a string'
+echo ${H[0]}
+echo "Index 0's length is ${#H[0]}"
+echo "All of the array is: ${H[@]}"
+
+# This too is a heredoc.
+some-program > /etc/config-file <<'EOF'
+echo "All of the array is: ${H[@]}"
+EOF
+
+# But this isn't.
+cat '<<EOF'
+echo "All of the array is: ${H[@]}"
+EOF
+
+# This is a heredoc
+cat <<-EOF
+echo "All of the array is ${H[@]}"
+EOF
+
+# As is this
+cat <<';'
+echo "All of the array is ${H[@]}"
+;
+
+# and this
+cat <<foo
+echo "All of the array is ${H[@]}"
+foobar
+echo $HOSTNAME
+foo
+
+# and again
+cat <<\bar
+echo "All of the array is ${H[@]}"
+bar
+
+# yet another
+cat <<"x++"
+echo "All of the array is ${H[@]}"
+x++
+
+# Recognize single quotes even if they start at the beginning of a line.
+echo not a bashism \
+'/{ptex,tex}/{amstex,plain,generic,}'
+
+# More bashisms.
+echo -e 'foo\n'
+echo "${!foo}"
+cat $(\< file)
+select foo in a b ; do echo $foo ; done
+cnt=$((cnt + 1))
+if false ; then
+ exec -l /bin/sh
+ exec -c /bin/sh
+ exec -a foo /bin/sh
+fi
+let cnt++
+if test -a /etc/default ; then
+ echo "$RANDOM|stuff"
+fi
+
+# Some comment checking
+# This should flag $RANDOM
+test $# -gt 2 && echo $RANDOM
+# But these shouldn't
+test 1=1 # echo $RANDOM
+(test 1=1)# echo $RANDOM
+test 1=1;# echo $RANDOM
+backgroundtask &#echo $RA
+
+#DEBHELPER#
diff --git a/t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/prerm b/t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/prerm
new file mode 100644
index 0000000..84098f7
--- /dev/null
+++ b/t/recipes/checks/scripts/scripts-bashisms/build-spec/debian/prerm
@@ -0,0 +1,186 @@
+#!/bin/sh
+
+set -e
+
+cat <<EOF
+This is all really bad bash specific code!!!
+read
+source /bar/baz/bat foo
+EOF
+
+# ok, back to checking
+if [ "$2" == "purge" ]; then
+ rm -r /bar/baz
+fi
+
+function foo( ) {
+ # but not here: local
+ local bar
+ echo "foo" &>/dev/null
+}
+
+source $FOO
+
+trap "echo hi" EXIT HUP 3
+
+if [[ "$2" = "purge" ]]; then
+ kill -HUP $$
+fi
+
+#this is ok though
+if test -n $(echo foo | perl -pe 's/[[:space:]]//go'); then
+ echo 1
+fi
+
+# More false positives for bashism checks. None of these are errors.
+echo "$line" | grep -q '{fonts/map,}/{\$progname,pdftex,dvips,}//'
+echo "$line" | grep -q "${fonts},${foo}"
+echo '$[1+2]'
+printf "foo |& bar"
+perl -e "print q( kill -HUP $? )"
+
+# Still catch disallowed expansions in double-quotes, though.
+echo "${line:3:1}"
+
+# More bashisms checks
+
+read -x foo
+read -x
+read -r foo
+read foo
+read
+
+echo "a\\b"
+echo 'a\nb'
+
+echo "${UID}"
+echo "$EUID"
+echo "$SHLVL"
+echo "$DIRSTACK"
+echo "$SECONDS"
+echo "$BASH"
+echo "$BASH_FOO"
+echo "$SHELLOPTS"
+echo "$PIPESTATUS"
+
+bar="$(cut '-d|' -f2 <<< "$foo")"
+
+VAR=1
+VAR+=a
+
+echos() {
+ echo -n -e "bar"
+ echo -e -n "bar"
+ echo -en "bar"
+ echo -ne "bar"
+ echo "bar"
+ echo "echo -e foo"
+}
+
+ech.os() {
+ echo foo >& 2
+ echo foo >&bar
+ echo foo >& bar
+}
+
+echoes() {
+ echo "abc\nxyz"
+ echo 'xyz\rabc'
+ echo foo\cbar
+
+ echo -e "abc\nxyz"
+ echo -net 'xyz\rabc'
+ echo -e foo\cbar
+}
+
+foobar.() {
+ suspend x
+ suspended x
+ caller x
+ complete x
+ compgen x
+ declare -a foo
+}
+
+.foobar() {
+ typeset -x bar
+ disown 1
+ builtin foo
+ set -B
+ alias -p
+ unalias -a
+}
+
+IFS="()"
+
+ulimit
+shopt
+type -v bar
+time ls
+dirs
+diff <(tac a) <(tac b)
+
+pushd
+
+local foo=bar
+local -x foo
+
+popd
+
+readonly -f
+
+echo bar > /dev/tcp
+export x
+export -x x
+export -p x
+
+sh -x
+sh -D
+sh --foo
+sh +O
+
+# Brace expansion checks
+echo {a,b}
+echo {abc},{bcd}
+
+foobar()
+{
+ # This is a function
+}
+
+ foo.bar()
+(
+ # This is a function with a bad name
+)
+
+foobar@() # foo
+{
+ # As is this
+}
+
+# This is ok
+read -r foo
+# but these aren't
+read -r
+read -p "Would you like to restart the service?" foo bar
+read --fish
+
+source "$BAR"
+source '$BAR'
+source ~/bar
+source a
+
+# An example from the X maintainer scripts that used to trigger the trap
+# bashism check.
+trap "message;\
+ message \"Received signal. Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
+ message;\
+ exit 1" HUP INT QUIT TERM
+
+# Also allow for extended single quotes containing double quotes.
+trap 'message;
+ message "Received signal. Aborting $THIS_PACKAGE package $THIS_SCRIPT script.";
+ message;
+ exit 1' HUP INT QUIT TERM
+
+#DEBHELPER#
diff --git a/t/recipes/checks/scripts/scripts-bashisms/build-spec/fill-values b/t/recipes/checks/scripts/scripts-bashisms/build-spec/fill-values
new file mode 100644
index 0000000..ab87d45
--- /dev/null
+++ b/t/recipes/checks/scripts/scripts-bashisms/build-spec/fill-values
@@ -0,0 +1,4 @@
+Skeleton: upload-native
+Testname: scripts-bashisms
+Description: Check bashism detection
+Extra-Build-Depends: dash (>= 0.5.10.2)
diff --git a/t/recipes/checks/scripts/scripts-bashisms/eval/desc b/t/recipes/checks/scripts/scripts-bashisms/eval/desc
new file mode 100644
index 0000000..6063543
--- /dev/null
+++ b/t/recipes/checks/scripts/scripts-bashisms/eval/desc
@@ -0,0 +1,2 @@
+Testname: scripts-bashisms
+Check: scripts
diff --git a/t/recipes/checks/scripts/scripts-bashisms/eval/hints b/t/recipes/checks/scripts/scripts-bashisms/eval/hints
new file mode 100644
index 0000000..34b6f31
--- /dev/null
+++ b/t/recipes/checks/scripts/scripts-bashisms/eval/hints
@@ -0,0 +1,14 @@
+scripts-bashisms (binary): read-in-maintainer-script [prerm:7]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:51]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:50]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:49]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:48]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:47]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:166]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:165]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:164]
+scripts-bashisms (binary): read-in-maintainer-script [prerm:162]
+scripts-bashisms (binary): read-in-maintainer-script [postinst:14]
+scripts-bashisms (binary): maintainer-script-without-set-e [postinst]
+scripts-bashisms (binary): maintainer-script-interpreter /bin/sh [prerm]
+scripts-bashisms (binary): maintainer-script-interpreter /bin/sh [postinst]