-
-
Notifications
You must be signed in to change notification settings - Fork 223
/
Copy pathsort.sh
53 lines (44 loc) · 1.51 KB
/
sort.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
#!/usr/bin/env bash
## This script should be placed in pre-commit-hooks
set -e
GIT_DIR="$(git rev-parse --show-toplevel)"
if [ -d "$GIT_DIR" ]; then
if cd "${GIT_DIR}"; then # Maked the dir change a IF do to bad experience in @matrix
echo "Change dir Ok"
echo "Print working directory: $PWD"
echo
else
echo "This is not a git repo. Exiting"
exit 1
fi
HIERARCHICALLY=(
"add-domain" # Sorting hierarchically do to sub-domains
"falsepositive.list"
"falsepositive_regex.list"
"falsepositive_rzd.list"
"falsepositive_all.list"
)
for (( h=0; h<${#HIERARCHICALLY[@]}; h++ )); do
python3 "$GIT_DIR/tools/domain-sort.py" <"${HIERARCHICALLY[$h]}" \
>"${HIERARCHICALLY[$h]}.tmp" && \
sed "/^$/d" "${HIERARCHICALLY[$h]}.tmp" \
>"${HIERARCHICALLY[$h]}"
echo "Sorting: ${HIERARCHICALLY[$h]}"
done
ALPHABETICALLY=(
"add-wildcard-domain"
"add-link"
"IP-addr.cidr.in-addr.arpa"
"IP-addr.cidr.list"
"IP-addr.in-addr.arpa"
"IP-addr.list"
)
for (( a=0; a<${#ALPHABETICALLY[@]}; a++ )); do
sort -u --parallel="$(nproc --ignore=1)" "${ALPHABETICALLY[$a]}" \
-o "${ALPHABETICALLY[$a]}"
sed -i "/^$/d" "${ALPHABETICALLY[$a]}"
echo "Sorting: ${ALPHABETICALLY[$a]}"
done
# Remove all *.tmp files in root folder
find . -maxdepth 1 -mindepth 1 -type f -iname '*.tmp' -delete
fi