| 1 | #!/bin/bashscip-shell filesystem . . `/bin/bash`. |
| 2 | |
| 3 | # |
| 4 | # check-files |
| 5 | # |
| 6 | scriptname=check-files |
| 7 | if ! MYTMP=$(mktempscip-shell system . . mktemp. -d -t $scriptname-XXXXXX) |
| 8 | then |
| 9 | echoscip-shell system . . echo. >&2 |
| 10 | echoscip-shell system . . echo. >&2 |
| 11 | echoscip-shell system . . echo. >&2 "Cannot create temporary directory." |
| 12 | echoscip-shell system . . echo. >&2 |
| 13 | exit 1 |
| 14 | fi |
| 15 | |
| 16 | cleanupscip-shell shell firehol 3.1.8+ds-1 cleanup().() { |
| 17 | status=$? |
| 18 | rmscip-shell system . . rm. -rf "${MYTMP}" |
| 19 | exit $status |
| 20 | } |
| 21 | |
| 22 | # clean up if we get stopped by Crtl-C or forced logout or normal exit |
| 23 | trap cleanup INT |
| 24 | trap cleanup HUP |
| 25 | trap cleanup 0 |
| 26 | |
| 27 | set -e |
| 28 | if [scip-shell system . . `[`. "$1" = "--debug" ] |
| 29 | then |
| 30 | set -x |
| 31 | shift |
| 32 | fi |
| 33 | |
| 34 | if [scip-shell system . . `[`. $# -lt 1 ] |
| 35 | then |
| 36 | echoscip-shell system . . echo. "check-files [--debug] -|filenames" |
| 37 | echoscip-shell system . . echo. "e.g." |
| 38 | echoscip-shell system . . echo. " git diff | ./packaging/check-files -" |
| 39 | echoscip-shell system . . echo. "for a complete check (v.s. empty repo):" |
| 40 | echoscip-shell system . . echo. " git diff 4b825dc642cb6eb9a060e54bf8d69288fbee4904 | ./packaging/check-files -" |
| 41 | echoscip-shell system . . echo. "or in .git/hooks/pre-commit:" |
| 42 | echoscip-shell system . . echo. " exec git diff --cached | ./packaging/check-files -" |
| 43 | exit 1 |
| 44 | fi |
| 45 | |
| 46 | if [scip-shell system . . `[`. ! -x packaging/check-files ] |
| 47 | then |
| 48 | echoscip-shell system . . echo. "Must be run from base directory" |
| 49 | exit 1 |
| 50 | fi |
| 51 | |
| 52 | if [scip-shell system . . `[`. "$1" = "-" ] |
| 53 | then |
| 54 | from_cache=Y |
| 55 | f="" |
| 56 | else |
| 57 | from_cache= |
| 58 | for f in "$@" |
| 59 | do |
| 60 | if [scip-shell system . . `[`. ! -f "$f" ] |
| 61 | then |
| 62 | echoscip-shell system . . echo. "$f: no such file" |
| 63 | exit 1 |
| 64 | fi |
| 65 | done |
| 66 | |
| 67 | gitscip-shell system . . git. status --porcelain "$@" | grepscip-shell system . . grep. "^?" | cutscip-shell system . . cut. -c4- > $MYTMP/missing.lst |
| 68 | |
| 69 | while read missing |
| 70 | do |
| 71 | gitscip-shell system . . git. update-index --add --cacheinfo \ |
| 72 | 100644 e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 $missing |
| 73 | done < $MYTMP/missing.lst |
| 74 | |
| 75 | empty_tree=4b825dc642cb6eb9a060e54bf8d69288fbee4904 |
| 76 | gitscip-shell system . . git. diff $empty_tree -- "$@" > $MYTMP/diff.full |
| 77 | f=$MYTMP/diff.full |
| 78 | |
| 79 | while read missing |
| 80 | do |
| 81 | gitscip-shell system . . git. update-index --force-remove $missing |
| 82 | done < $MYTMP/missing.lst |
| 83 | fi |
| 84 | |
| 85 | > $MYTMP/diff.lst sedscip-shell system . . sed. -e "/^+++ b/{p;s:^+++ b/::;w $MYTMP/files.lst" -e "d;}" $f |
| 86 | |
| 87 | #cat $MYTMP/diff.lst |
| 88 | #cat $MYTMP/files.lst |
| 89 | |
| 90 | dirname="${0%/*}" |
| 91 | if [scip-shell system . . `[`. "$dirname" = "$0" ]; then dirname="."; fi |
| 92 | |
| 93 | for i in $dirname/*.functions $dirname/*/*.functions |
| 94 | do |
| 95 | if [scip-shell system . . `[`. -f "$i" ] |
| 96 | then |
| 97 | source $i |
| 98 | echoscip-shell system . . echo. $i | sedscip-shell system . . sed. -e 's:.*/::' -e 's/\.functions$//' -e 's/\./_/g' >> $MYTMP/fns |
| 99 | fi |
| 100 | done |
| 101 | |
| 102 | status=0 |
| 103 | while read fn |
| 104 | do |
| 105 | "${fn}_check_init" $filename || status=1 |
| 106 | done < $MYTMP/fns |
| 107 | |
| 108 | while read filename |
| 109 | do |
| 110 | #echo Checking $filename |
| 111 | while read fn |
| 112 | do |
| 113 | if [scip-shell system . . `[`. $status -eq 0 ] |
| 114 | then |
| 115 | "${fn}_check_file" $filename || status=1 |
| 116 | fi |
| 117 | done < $MYTMP/fns |
| 118 | done < $MYTMP/files.lst |
| 119 | |
| 120 | if [scip-shell system . . `[`. $status -eq 0 ] |
| 121 | then |
| 122 | while read fn |
| 123 | do |
| 124 | "${fn}_check_fin" $filename || status=1 |
| 125 | done < $MYTMP/fns |
| 126 | fi |
| 127 | |
| 128 | exit $status |