| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | # |
| 3 | # Checks source code and data for potential problems. |
| 4 | # Meant to be executed before submitting/committing. |
| 5 | |
| 6 | |
| 7 | SELF=${0##*/} |
| 8 | |
| 9 | # optional apps |
| 10 | RLE=$(whichscip-shell system . . which. rle 2>/dev/nullscip-shell filesystem . . `/dev/null`.) # http://members.aon.at/mfranz/rle.tar.gz (depends on Qt lib) |
| 11 | AC3D_SCAN=$(whichscip-shell system . . which. ac3d-scan 2>/dev/nullscip-shell filesystem . . `/dev/null`.) # http://members.aon.at/mfranz/ac3d-scan |
| 12 | |
| 13 | |
| 14 | function ERRORscip-shell shell flightgear 1:2024.1.5+dfsg-1 ERROR(). { echoscip-shell system . . echo. -e "\e[31;1m$*\e[m"; } |
| 15 | function LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). { echoscip-shell system . . echo. -e "\e[35m$*\e[m"; } |
| 16 | function RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). { echoscip-shell system . . echo. -e "\t$*"; } |
| 17 | |
| 18 | |
| 19 | TMP=$(mktempscip-shell system . . mktemp. -d -t $SELF.XXX) || (echoscip-shell system . . echo. "$0: can't create temporary dir"; exit 1) |
| 20 | trap "rm -rf $TMP" 0 1 2 3 13 15 |
| 21 | |
| 22 | |
| 23 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for spaces in filenames ..." |
| 24 | findscip-shell system . . find. .|grepscip-shell system . . grep. " "|while read i; do RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). "$i"; done |
| 25 | |
| 26 | |
| 27 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for upper-case extensions ..." |
| 28 | findscip-shell system . . find. .|while read i; do |
| 29 | case "$i" in .|..|CVS/*|*/CVS/*|*.Opt|*.README|*.Po|*.TXT) continue ;; esac |
| 30 | base=${i##*/} |
| 31 | ext=${base##*.} |
| 32 | [scip-shell system . . `[`. "$base" == "$ext" ] && continue # has no extension |
| 33 | ext=${ext//[^a-zA-Z]/} |
| 34 | [scip-shell system . . `[`. "$ext" ] || continue # only non-letters |
| 35 | lcext=$(echoscip-shell system . . echo. $ext|sedscip-shell system . . sed. -e 's,\(.*\),\L\1,') |
| 36 | [scip-shell system . . `[`. "$ext" != "$lcext" ] && RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). "$i" |
| 37 | done |
| 38 | |
| 39 | |
| 40 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for DOS line endings ..." |
| 41 | findscip-shell system . . find. . -type f|while read i; do |
| 42 | desc=$(filescip-shell system . . file. -b "$i") |
| 43 | case "$desc" in *text*) |
| 44 | grepscip-shell system . . grep. " $" "$i" >/dev/nullscip-shell filesystem . . `/dev/null`. && RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). "$i" |
| 45 | ;; |
| 46 | esac |
| 47 | done |
| 48 | |
| 49 | |
| 50 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for uncompressed textures ..." |
| 51 | findscip-shell system . . find. . -iname \*.rgb -o -iname \*.rgba|while read i; do |
| 52 | new=$TMP/sgi.rgb |
| 53 | if [scip-shell system . . `[`. -x "$RLE" ]; then |
| 54 | cpscip-shell system . . cp. "$i" $new && "$RLE" $new 2>&1|grepscip-shell system . . grep. corrupt &>/dev/nullscip-shell filesystem . . `/dev/null`. && ERRORscip-shell shell flightgear 1:2024.1.5+dfsg-1 ERROR(). "\t$i ... FILE CORRUPTED" |
| 55 | else |
| 56 | convert "$i" -compress RLE sgi:$new |
| 57 | fi |
| 58 | perlscip-shell system . . perl. -e ' |
| 59 | my $file = shift; |
| 60 | my $old = -s $file; |
| 61 | my $new = -s shift; |
| 62 | if ($new < $old) { |
| 63 | printf "\t$file: could be %0.02f%% of current size (%d bytes less)\n", |
| 64 | 100 * $new / $old, $old - $new; |
| 65 | } |
| 66 | ' "$i" $new |
| 67 | done |
| 68 | |
| 69 | |
| 70 | if [scip-shell system . . `[`. -x "$AC3D_SCAN" ]; then |
| 71 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for AC3D sanity ..." |
| 72 | findscip-shell system . . find. . -iname \*.ac|while read i; do |
| 73 | case "$i" in configure.ac|*/configure.ac) continue ;; esac |
| 74 | result=$($AC3D_SCAN <$i 2>&1) |
| 75 | [scip-shell system . . `[`. "$result" ] && echoscip-shell system . . echo. -e "$result\n\t... in file \e[36m$i\e[m"; |
| 76 | done |
| 77 | fi |
| 78 | |
| 79 | |
| 80 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for thumbnail file size (expected JPEG 171x128)" |
| 81 | findscip-shell system . . find. . -name thumbnail.jpg|while read i; do |
| 82 | id=$(identify "$i") |
| 83 | if ! echoscip-shell system . . echo. $id|grepscip-shell system . . grep. "JPEG 171x128" >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 84 | RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). "$i ... $id" |
| 85 | fi |
| 86 | done |
| 87 | |
| 88 | |
| 89 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for 'userarchive' flags (not allowed in aircraft XML files) ..." |
| 90 | findscip-shell system . . find. . -name \*.xml|while read i; do |
| 91 | if grepscip-shell system . . grep. "userarchive" $i >/dev/nullscip-shell filesystem . . `/dev/null`.; then |
| 92 | RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). "$i" |
| 93 | fi |
| 94 | done |
| 95 | |
| 96 | |
| 97 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for XML syntax ..." |
| 98 | findscip-shell system . . find. . -name \*.xml|while read i; do |
| 99 | xmllint $i >/dev/nullscip-shell filesystem . . `/dev/null`. || RESULTscip-shell shell flightgear 1:2024.1.5+dfsg-1 RESULT(). "... in file \e[36m$i\e[m" |
| 100 | done |
| 101 | |
| 102 | |
| 103 | LOGscip-shell shell flightgear 1:2024.1.5+dfsg-1 LOG(). "checking for 'if (foo) delete foo;' ..." |
| 104 | findscip-shell system . . find. . -iregex ".*\.\([ch]\(xx\|pp\)\|cc\|h\)$"|while read i; do perlscip-shell system . . perl. -e ' |
| 105 | my $i = 0; |
| 106 | my $name = $ARGV[0]; |
| 107 | undef $/; |
| 108 | $_ = <>; |
| 109 | s/(if\s*\(([^\)]+)\)\s*delete(?:\s+|\s*\[\]\s*)\2\s*;)/print "$1\n" and $i++/ges; |
| 110 | print "\t... \033[36min file $name\033[m\n" if $i; |
| 111 | ' "$i"; done |
| 112 | |
| 113 |