forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmerge-rulesets.sh
More file actions
50 lines (42 loc) · 1.58 KB
/
merge-rulesets.sh
File metadata and controls
50 lines (42 loc) · 1.58 KB
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
#!/bin/sh
# Merge all the .xml rulesets into a single "default.rulesets" file -- this
# prevents inodes from wasting disk space, but more importantly, works around
# the fact that zip does not perform well on a pile of small files.
cd src
RULESETS=chrome/content/rules/default.rulesets
echo "Creating ruleset library..."
# Under git bash, sed -i issues errors and sets the file "read only". Thanks.
[ -f "$RULESETS" ] && chmod u+w $RULESETS
echo "<rulesetlibrary gitcommitid=\"${GIT_COMMIT_ID}\">" > $RULESETS
# Include the filename.xml as the "f" attribute
for file in chrome/content/rules/*.xml; do
xmlInsertString="<ruleset"
fileName=$(basename "$file")
fileContent=$(sed "s/${xmlInsertString}/${xmlInsertString} f=\"${fileName}\"/" "chrome/content/rules/${fileName}")
echo "$fileContent" >> $RULESETS
done
echo "</rulesetlibrary>" >> $RULESETS
echo "Removing whitespaces and comments..."
rulesize() {
echo `wc -c $RULESETS | cut -d \ -f 1`
}
CRUSH=`rulesize`
sed -i -e :a -re 's/<!--.*?-->//g;/<!--/N;//ba' $RULESETS
sed -i ':a;N;$!ba;s/\n//g;s/>[ ]*</></g;s/[ ]*to=/ to=/g;s/[ ]*from=/ from=/g;s/ \/>/\/>/g' $RULESETS
echo "Crushed $CRUSH bytes of rulesets into `rulesize`"
if [ -x $(which xmllint) ]
then
if xmllint --noout $RULESETS
then
echo "$RULESETS passed XML validity test."
else
echo "ERROR: $RULESETS failed XML validity test."
exit 2
fi
else
echo "WARNING: xmllint not present; validation of $RULESETS skipped."
fi
# We make default.rulesets at build time, but it shouldn't have a variable
# timestamp
touch -r chrome/content/rules $RULESETS
cd ..