-
Notifications
You must be signed in to change notification settings - Fork 0
/
runrules.sh
executable file
·59 lines (52 loc) · 1.47 KB
/
runrules.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/bin/sh
printrule() {
. "$1"
echo '--------------------ID--------------------'
printid
echo '-------------------TITLE------------------'
printtitle
echo '-----------------SEVERITY-----------------'
printseverity
echo '----------------DESCRIPTION---------------'
printdescription
echo '--------------------FIX-------------------'
printfix
echo '------------------------------------------'
echo
echo
echo
}
TESTONLY=0
if [ "x$1" = 'x-t' ]; then
TESTONLY=1
shift
fi
export PATH="./lib:$PATH"
while [ $# -gt 0 ]; do
ruledir="$1"
shift
echo "Testing rule $ruledir"
if [ -e "$ruledir/test.sh" ]; then
if ! "$ruledir/test.sh"; then
echo "FAILED"
if [ -e "$ruledir/fix.sh" ]; then
printrule "$ruledir/vars.sh"
printf "There is a fix available, would you like to run it(y/n)? "
if [ "$TESTONLY" -eq 0 ]; then
read runfix
if [ "$runfix" = y -o "$runfix" = Y ]; then
"$ruledir/fix.sh"
fi
else
echo
fi
else
echo "There is no fix available, you must fix this yourself:"
printrule "$ruledir/vars.sh"
fi
fi
elif [ "$TESTONLY" -ne 1 ]; then
echo "Can not test. You must test manually."
printrule "$ruledir/vars.sh"
fi
done