-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathAutoCommit.sh
executable file
·268 lines (233 loc) · 13.5 KB
/
AutoCommit.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#!/bin/bash
repos_root='/github'
curl() {
# It is OK for the system which has cURL's version greater than `7.76.0` to use `--fail-with-body` instead of `-f`.
## Refer to: https://superuser.com/a/1626376
$(type -P curl) -LRq --retry 5 --retry-delay 10 --retry-max-time 60 -f "$@"
}
cd "$repos_root/4Share/" || exit 1
# 清理当前目录下所有将由脚本更新的文件,确保不会保留任何旧文件
find . -type f -iname route.sh -print0 | xargs -0 rm --
find . -type f -iname china_ip_list.txt -print0 | xargs -0 rm --
find . -type f -iname china-ipv4.txt -print0 | xargs -0 rm --
find . -type f -iname china-ipv6.txt -print0 | xargs -0 rm --
find . -type f -iregex ".*ip.*_list_.?.txt" -print0 | xargs -0 rm --
find . -type f -iname accelerated-domains.china.conf -print0 | xargs -0 rm --
# 拷贝最新文件
/bin/cp -f "$repos_root/dnsmasq-china-list/accelerated-domains.china.conf" ./
# /bin/cp -f "$repos_root/china_ip_list/china_ip_list.txt" ./
curl -s 'https://raw.githubusercontent.com/felixonmars/chnroutes-alike/master/chnroutes-alike.txt' | sed -E '/^[^0-9]|^\s*$/d' | sort -V > 'chnroutes-alike.txt'
curl -s 'https://raw.githubusercontent.com/misakaio/chnroutes2/master/chnroutes.txt' | sed -E '/^[^0-9]|^\s*$/d' | sort -V > 'chnroutes.txt'
(
cd "$repos_root/china-operator-ip/" || exit 1
# cat cernet.txt chinanet.txt cmcc.txt cstnet.txt drpeng.txt googlecn.txt tietong.txt unicom.txt > "$repos_root/4Share/china-ipv4.txt"
cat cernet6.txt chinanet6.txt cmcc6.txt cstnet6.txt drpeng6.txt googlecn6.txt tietong6.txt unicom6.txt > "$repos_root/4Share/china-ipv6.txt"
)
dos2unix chnroutes-alike.txt chnroutes.txt china-ipv6.txt accelerated-domains.china.conf
# 针对北京大学校园网划分网段进行特殊处理
# sed -i -E '/^115\.27\.0\.0.*/d' china_ip_list.txt china-ipv4.txt
# sed -i -E '/^162\.105\.0\.0.*/d' china_ip_list.txt china-ipv4.txt
# sed -i -E '/^202\.112\.7\.0.*/d' china_ip_list.txt china-ipv4.txt
# sed -i -E '/^202\.112\.8\.0.*/d' china_ip_list.txt china-ipv4.txt
# sed -i -E '/^222\.29\.0\.0.*/d' china_ip_list.txt china-ipv4.txt
# sed -i -E '/^222\.29\.128\.0.*/d' china_ip_list.txt china-ipv4.txt
# sed -i -E '/^2001:da8:201::.*/d' china-ipv6.txt
# 创建用于写入 Proxifier 规则的 IP 白名单列表
# 1. Proxifier 规则暂不支持 CIDR 格式的 IP 地址,因此需要做格式上的转换
# 2. Proxifier 一条规则内最大能写入 32767 个字符,远远小于格式转换后的 IP 列表字符长,
# 因此需要将 china_ip_list 拆分为多个规则。
dos2unix Proxifier/IPConvert.py Proxifier/IPv6Convert.py
python3 Proxifier/IPConvert.py
python3 Proxifier/IPv6Convert.py
sed -i '1i\''payload:' Clash/ICN/CHINA_IP_LIST.yaml
/bin/mv -f ip_list_?.txt ipv6_list_?.txt Proxifier
/bin/cp -f china_ip_list.txt geoip_china/china_ip_list.txt
/bin/rm -f 'chnroutes-alike.txt' 'chnroutes.txt'
# 通过 sed 命令处理之
sed -i -E -e '/^#|^$/d' -e '/Disable/d' accelerated-domains.china.conf
sed -i -E -e 's/114.114.114.114/223.5.5.5/g' -e '/^server=\/tsdm/d' accelerated-domains.china.conf
sed -i -E -e "s/^/route\ \${OPS}\ -net\ &/g" -e "s/$/&\ \${ROUTE_GW}/g" china_ip_list.txt
# 建立 route.sh 文件
cat > route.sh << 'END_TEXT'
#/bin/bash
#export PATH="/bin:/sbin:/usr/sbin:/usr/bin"
ROUTE_GW="gw `nvram get wan0_gateway`"
if [ $# -ne 1 ]; then
echo $0 add/delete
exit
fi
if [ "$1" != "add" ] && [ "$1" != "delete" ]; then
echo $0 add/delete
exit
fi
if [ "$1" == "delete" ]; then
ROUTE_GW=""
fi
OPS=$1
# route $OPS -net ${IP_SEGMENT} ${ROUTE_GW}
# Generate:
# wget -qo- https://raw.githubusercontent.com/17mon/china_ip_list/master/china_ip_list.txt
# sed -i -E -e 's/^/route\ \${OPS}\ -net\ &/g' -e 's/$/&\ \${ROUTE_GW}/g' china_ip_list.txt
# 另一边要用到的命令:
# wget -qo- https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf
# sed -i -E 's/114.114.114.114/223.5.5.5/g' accelerated-domains.china.conf
END_TEXT
cat china_ip_list.txt >> route.sh
cat >> route.sh << 'END_TEXT'
# https://its.pku.edu.cn/faq.jsp --获得北大IP网段
# 162.105.0.0/16
# 202.112.7.0/24
# 202.112.8.0/24
# 222.29.0.0/17
# 222.29.128.0/19
# 115.27.0.0/16
# 2001:da8:201::/48
route ${OPS} -net 115.27.0.0/16 ${ROUTE_GW}
route ${OPS} -net 162.105.0.0/16 ${ROUTE_GW}
route ${OPS} -net 202.112.7.0/24 ${ROUTE_GW}
route ${OPS} -net 202.112.8.0/24 ${ROUTE_GW}
route ${OPS} -net 222.29.0.0/17 ${ROUTE_GW}
route ${OPS} -net 222.29.128.0/19 ${ROUTE_GW}
route ${OPS} -A inet6 2001:da8:201::/48 ${ROUTE_GW}
END_TEXT
# 更新 4Share 库 router 目录
/bin/cp -f accelerated-domains.china.conf router
/bin/rm -f china_ip_list.txt china-ipv4.txt china-ipv6.txt
dos2unix route.sh
/bin/mv -f route.sh router
# 在已有 accelerated-domains.china.conf 文件的基础上做二次修改,使符合 DNSCrypt 配置格式
sed -i -E -e 's/server=\///g' -e '/^#|^$/d' -e '/Disable/d' -e 's/\// /g' accelerated-domains.china.conf
sed -i -E 's/223.5.5.5/162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29/g' accelerated-domains.china.conf
# 建立 forwarding-rules.txt 文件
cat > forwarding-rules.txt << 'END_TEXT'
##################################
# Forwarding rules #
##################################
## This is used to route specific domain names to specific servers.
## The general format is:
## <domain> <server address>[:port] [, <server address>[:port]...]
## IPv6 addresses can be specified by enclosing the address in square brackets.
## In order to enable this feature, the "forwarding_rules" property needs to
## be set to this file name inside the main configuration file.
## Blocking IPv6 may prevent local devices from being discovered.
## If this happens, set `block_ipv6` to `false` in the main config file.
## Forward *.lan, *.local, *.home, *.internal and *.localdomain to 192.168.1.1
# lan 192.168.1.1
# local 192.168.1.1
# home 192.168.1.1
# internal 192.168.1.1
# localdomain 192.168.1.1
## Forward queries for example.com and *.example.com to 9.9.9.9 and 8.8.8.8
# example.com 9.9.9.9,8.8.8.8
# To generate:
# sed -i -E -e 's/server=\///g' -e '/^#|^$/d' -e '/Disable/d' -e 's/\// /g' accelerated-domains.china.conf
lan 192.168.50.1
local 192.168.50.1
home 192.168.50.1
internal 192.168.50.1
localdomain 192.168.50.1
workgroup 192.168.50.1
# 10.in-addr.arpa 192.168.50.1
192.in-addr.arpa 192.168.50.1
# 254.169.in-addr.arpa 192.168.50.1
# 16.172.in-addr.arpa 192.168.50.1
# 17.172.in-addr.arpa 192.168.50.1
# 18.172.in-addr.arpa 192.168.50.1
# 19.172.in-addr.arpa 192.168.50.1
# 20.172.in-addr.arpa 192.168.50.1
# 21.172.in-addr.arpa 192.168.50.1
# 22.172.in-addr.arpa 192.168.50.1
# 23.172.in-addr.arpa 192.168.50.1
# 24.172.in-addr.arpa 192.168.50.1
# 25.172.in-addr.arpa 192.168.50.1
# 26.172.in-addr.arpa 192.168.50.1
# 27.172.in-addr.arpa 192.168.50.1
# 28.172.in-addr.arpa 192.168.50.1
# 29.172.in-addr.arpa 192.168.50.1
# 30.172.in-addr.arpa 192.168.50.1
# 31.172.in-addr.arpa 192.168.50.1
altmetric.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
apabi.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
clarivate.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
doi.org 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
els-cdn.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
elsevier-ae.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
elsevier.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
evise.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
japanknowledge.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
jbe-platform.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
jstor.org 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
literatumonline.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
mywconline.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
oup.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
pkuhelper.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
pnas.org 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
proquest.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
researchgate.net 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
rgstatic.net 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
sciencedirect.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
sciencedirectassets.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
scopus.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
serialssolutions.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
silverchair-cdn.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
springer.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
springernature.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
tandfonline.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
thomsonreuters.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
tuna.moe 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
webofknowledge.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
webofscience.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
wiley.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
wkap.nl 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
npupt.com 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
byr.cn 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
pku.edu.cn 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
edu.cn 162.105.129.122,162.105.129.88,162.105.129.27,162.105.129.26,101.6.6.6:5353
ac.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
com.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
org.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
net.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
gov.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
mil.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
ah.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
bj.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
cq.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
fj.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
gd.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
gs.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
gz.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
gx.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
ha.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
hb.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
he.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
hi.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
hl.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
hn.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
jl.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
js.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
jx.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
ln.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
nm.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
nx.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
qh.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
sc.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
sd.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
sh.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
sn.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
sx.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
tj.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
yn.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
zj.cn 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
xn--fiqs8s 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
xn--fiqz9s 162.105.129.122,162.105.129.88,101.6.6.6:5353,223.5.5.5,119.29.29.29
END_TEXT
cat accelerated-domains.china.conf >> forwarding-rules.txt
# 更新 4Share 库 DNSCrypt 目录
/bin/rm -f accelerated-domains.china.conf
dos2unix forwarding-rules.txt
/bin/mv -f forwarding-rules.txt DNSCrypt
# 推送更新到 GitHub
git add -- *
git commit -a -m "Auto Commit"
git push