-
Notifications
You must be signed in to change notification settings - Fork 104
/
whitelist.sh
executable file
·52 lines (38 loc) · 1.33 KB
/
whitelist.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
#!/bin/bash -e
TMP_DIR=`mktemp -d /tmp/pac.XXXXXX`
DIST_DIR='dist/pac'
DIST_FILE='whitelist.pac'
CHINA_DOMAINS_URL='https://github.com/felixonmars/dnsmasq-china-list/raw/master/accelerated-domains.china.conf'
APPLE_DOMAINS_URL='https://github.com/felixonmars/dnsmasq-china-list/raw/master/apple.china.conf'
WHITELIST_DOMAINS='whitelist_domains.txt'
function fetch_data() {
local pac_template='template/pac/whitelist.pac'
cp ${pac_template} ${TMP_DIR}
pushd ${TMP_DIR}
curl -kLs ${CHINA_DOMAINS_URL} ${APPLE_DOMAINS_URL} | sort | uniq > ${WHITELIST_DOMAINS}
popd
}
function gen_whitelist_pac() {
pushd ${TMP_DIR}
# get domains
sed -i 's/server=\// "/g' ${WHITELIST_DOMAINS}
sed -i 's/\/114.114.114.114/": 1,/g' ${WHITELIST_DOMAINS}
# exclude comment lines
sed -i '/#/d' ${WHITELIST_DOMAINS}
# remove last ',' character: https://stackoverflow.com/questions/3576139/sed-remove-string-only-in-the-last-line-of-the-file
sed -i '$ s/": 1,/": 1/g' ${WHITELIST_DOMAINS}
sed -i "s/___CHINA_DOMAINS_PLACEHOLDER___/cat ${WHITELIST_DOMAINS}/e" ${DIST_FILE}
sed -i "s/___UPDATE_TIME_PLACEHOLDER___/$(date +'%Y-%m-%d %T')/g" ${DIST_FILE}
popd
}
function dist_release() {
mkdir -p ${DIST_DIR}
mv ${TMP_DIR}/${DIST_FILE} ${DIST_DIR}
}
function clean_up() {
rm -r ${TMP_DIR}
}
fetch_data
gen_whitelist_pac
dist_release
clean_up