-
Notifications
You must be signed in to change notification settings - Fork 0
/
check-xmllint
executable file
·61 lines (53 loc) · 1013 Bytes
/
check-xmllint
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
60
61
#!/bin/sh
XMLLINT=xmllint
if [ -t 1 ]; then
R=$(tput setaf 1)
G=$(tput setaf 2)
Y=$(tput setaf 3)
N=$(tput sgr0)
fi
args=$(getopt i $*)
if [ $? -ne 0 ]; then
echo "Usage: check-xmllint [-i] <files..>
-i overwrite files with xmllint formatted content
"
exit 2
fi
set -- $args
inplace=0
while true; do
case "$1" in
-i)
inplace=1
;;
--)
shift
break
;;
esac
shift
done
retval=0
for FILE in $*; do
tmpfile=$(mktemp)
if ! $XMLLINT --format $FILE > $tmpfile; then
echo "XML check for $FILE: ${R}cannot parse${N}"
retval=1
else
if ! diff $tmpfile $FILE; then
if [ $inplace -eq 0 ]; then
echo "XML check for $FILE: ${R}failed${N}"
retval=2
else
tmpfile=$(mktemp)
$XMLLINT --format $FILE > $tmpfile
cp $tmpfile $FILE
echo "XML check for $FILE: ${Y}reformatted${N}"
fi
else
echo "XML check for $FILE: ${G}OK${N}"
fi
fi
rm -f $tmpfile
done
exit $retval