1 #!/bin/bash
3 ####################
4 # Copyright (C) 2008 by Raphael Geissert <atomo64@gmail.com>
5 #
6 #
7 # This file is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # This file is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with this file. If not, see <http://www.gnu.org/licenses/>.
19 ####################
21 if ! cb="$(which checkbashisms)"; then
22 echo "Couldn't find checkbashisms in $PATH, please install it!"
23 exit 1
24 fi
26 set -e
28 base=$(basename "$0")
29 origDir="$PWD"
30 file=
32 cleanup() {
33 cd "$origDir"
34 [ ! -d "$workDir" ] || rm -rf "$workDir"
35 [ -z "$file" ] && echo || echo -e "\nQuiting while processing $file..."
36 }; trap cleanup EXIT
38 [ ! -z "$1" ] || {
39 echo "$base foo.deb [bar.deb [...]]"
40 echo "Simple script to run checkbashisms on files inside a .deb, v0.0.3"
41 echo "Copyright 2008 Raphael Geissert <atomo64@gmail.com>"
42 exit
43 }
45 for bfile in $@; do
46 echo -en "\nProcessing $bfile..."
47 nl=0
49 rfile="$(readlink -f "$bfile")"
50 file="$(basename "$bfile")"
52 workDir="$(mktemp -t -d "${base}_XXXXXX")" || exit 1
54 cd "$workDir"
56 # use fakeroot when unpacking fails because of mknode and similar are called by tar
57 dpkg-deb -x "$rfile" . || fakeroot dpkg-deb -x "$rfile" .
58 dpkg-deb -e "$rfile" DEBIAN || fakeroot dpkg-deb -e "$rfile" DEBIAN
59 chmod -R u+rwX .
61 find . -type f |
62 while read _file; do
63 case ${_file} in
64 ./etc/default/*|./etc/X11/Xsession.d/*)
65 true
66 ;;
67 *)
68 if ! file -- "${_file}" | grep POSIX | grep -q "shell script"; then
69 continue
70 fi
71 ;;
72 esac
73 es=0
74 msg="$(checkbashisms $opts "${_file}" 2>&1)" || es=$?
76 if [ $es -eq 1 ] && grep -qv "does not appear to be a /bin/sh script;" <<< "$msg" ; then
77 [ $nl -gt 0 ] || { echo; nl=1; }
78 [ -z "$msg" ] || echo "$msg"
79 fi
80 done
82 cd "$origDir"
83 rm -rf "$workDir"
85 file=
87 echo -n "done"
88 done
