root/trunk/omnipitr/bin/sanity-check.sh

Revision 120, 3.0 kB (checked in by depesz, 4 years ago)

fix problem with 'useful' at the beginning of line in comment in .pm - it's treated the same way like 'use ful;' and sanity check was trying to find module 'ful'.

  • Property svn:executable set to *
Line 
1 #!/bin/bash
2
3 BIN_DIR=$( perl -le 'use Cwd qw(realpath); print realpath(shift)' "$( dirname $0 )" )
4 LIB_DIR=$( perl -le 'use Cwd qw(realpath); print realpath(shift)' "$( dirname $0 )/../lib" )
5
6 echo "Checking:"
7 echo "- $BIN_DIR"
8 echo "- $LIB_DIR"
9
10 BIN_COUNT=0
11 for x in "$BIN_DIR"/omnipitr-*
12 do
13     BIN_COUNT=$(( $BIN_COUNT + 1 ))
14 done
15
16 LIB_COUNT=$( find "$LIB_DIR" -name '*.pm' -print | wc -l )
17
18 echo "$BIN_COUNT programs, $LIB_COUNT libraries."
19
20 declare -a WARNINGS ERRORS
21 WARNINGS_COUNT=0
22 ERRORS_COUNT=0
23
24 # Base checks
25
26 if [[ -z $( which ssh 2> /dev/null ) ]]
27 then
28     WARNINGS_COUNT=$(( 1 + $WARNINGS_COUNT ))
29     WARNINGS[$WARNINGS_COUNT]="you don't have ssh program available"
30 fi
31 if [[ -z $( which rsync 2> /dev/null ) ]]
32 then
33     ERRORS_COUNT=$(( 1 + $ERRORS_COUNT ))
34     ERRORS[$ERRORS_COUNT]="you don't have rsync program available"
35 fi
36
37 if [[ -z $( which perl 2> /dev/null ) ]]
38 then
39     ERRORS_COUNT=$(( 1 + $ERRORS_COUNT ))
40     ERRORS[$ERRORS_COUNT]="you don't have Perl?!"
41 else
42     PERLVEROK=$( perl -e 'print $] >= 5.008 ? "ok" : "nok"' )
43     if [[ "$PERLVEROK" == "nok" ]]
44     then
45         WARNINGS_COUNT=$(( 1 + $WARNINGS_COUNT ))
46         WARNINGS[$WARNINGS_COUNT]="your Perl is old (we support only 5.8 or newer. OmniPITR might work, but was not tested on your version of Perl)"
47     fi
48 fi
49
50 # perl code checks
51
52 for x in "$BIN_DIR"/omnipitr-* $( find "$LIB_DIR" -name '*.pm' -print )
53 do
54     if ! perl -I"$LIB_DIR" -wc "$x" &>/dev/null
55     then
56         ERRORS_COUNT=$(( 1 + $ERRORS_COUNT ))
57         ERRORS[$ERRORS_COUNT]="can't compile $x ?!"
58     fi
59 done
60
61 # modules check
62
63 for MODULE in $( egrep "^use[[:space:]]" "$BIN_DIR"/omnipitr-* $( find "$LIB_DIR" -name '*.pm' -print ) | perl -pe 's/^[^:]+:use\s+//; s/[;\s].*//' | egrep -v '^OmniPITR' | sort | uniq )
64 do
65     if ! perl -I"$LIB_DIR" -e "use $MODULE" &>/dev/null
66     then
67         ERRORS_COUNT=$(( 1 + $ERRORS_COUNT ))
68         ERRORS[$ERRORS_COUNT]="you don't have $MODULE Perl library (should be installed together with Perl)"
69     fi
70 done
71
72 for MODULE in Time::HiRes
73 do
74     if ! perl -I"$LIB_DIR" -e "use $MODULE" &>/dev/null
75     then
76         WARNINGS_COUNT=$(( 1 + $WARNINGS_COUNT ))
77         WARNINGS[$WARNINGS_COUNT]="you don't have $MODULE Perl library - it's optional, but it could help"
78     fi
79 done
80
81 # Report of status
82
83 if [[ $WARNINGS_COUNT -gt 0 ]]
84 then
85     echo "Warnings:"
86     for WARNING in "${WARNINGS[@]}"
87     do
88         echo "- $WARNING"
89     done
90 fi
91 if [[ $ERRORS_COUNT -gt 0 ]]
92 then
93     echo "Errors:"
94     for ERROR in "${ERRORS[@]}"
95     do
96         echo "- $ERROR"
97     done
98 fi
99 if [[ "$WARNINGS_COUNT" -eq 0 && "$ERRORS_COUNT" -eq 0 ]]
100 then
101     echo "All checked, and looks ok."
102     exit
103 fi
104 echo -n "All checked. "
105 if [[ "$WARNINGS_COUNT" -eq 0 ]]
106 then
107     echo -n "No warnings. "
108 elif [[ "$WARNINGS_COUNT" -eq 1 ]]
109 then
110     echo -n "1 warning. "
111 else
112     echo -n "${WARNINGS_COUNT} warnings. "
113 fi
114 if [[ "$ERRORS_COUNT" -eq 0 ]]
115 then
116     echo -n "No errors."
117 elif [[ "$ERRORS_COUNT" -eq 1 ]]
118 then
119     echo -n "1 error."
120 else
121     echo -n "${ERRORS_COUNT} errors."
122 fi
123 echo
Note: See TracBrowser for help on using the browser.