forked from EFForg/https-everywhere
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathremove-obsolete-references.sh
More file actions
executable file
·39 lines (31 loc) · 1.01 KB
/
remove-obsolete-references.sh
File metadata and controls
executable file
·39 lines (31 loc) · 1.01 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
#!/bin/bash
# Remove obsolete references to child rulesets which
# has been renamed/ deleted
# Change directory to git root; taken from ../test/test.sh
if [ -n "$GIT_DIR" ]
then
# $GIT_DIR is set, so we're running as a hook.
cd $GIT_DIR
else
# Git command exists? Cool, let's CD to the right place.
git rev-parse && cd "$(git rev-parse --show-toplevel)"
fi
# Run from ruleset folder to simplify the output
cd src/chrome/content/rules
# Default exit status
EXIT_CODE=0
# List of file(s) which contain at least one reference
FILES=`egrep -l '^\s*[-|+]\s*([^ ]*\.xml)\s*$' *.xml`
while read FILE; do
# List of referenced rulesets
REFS=`sed -n 's/^\s*[-|+]\s*\([^ ]*\.xml\)\s*$/\1/gp' "$FILE"`
while read REF; do
if [ ! -f "$REF" ]; then
echo >&2 "ERROR src/chrome/content/rules/$FILE: Dangling reference to $REF"
sed -i "/^\s*[-|+]\s*$REF$/d" "$FILE"
EXIT_CODE=1
fi
done <<< "$REFS"
done <<< "$FILES"
# Exit with errors, if any
exit "$EXIT_CODE"