forked from user1121114685/koolproxyR
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·384 lines (319 loc) · 14.1 KB
/
build.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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
#!/bin/sh
MODULE=koolproxyR
VERSION="2.2.4"
TITLE=koolproxyR
DESCRIPTION="至 善 至 美"
HOME_URL="Module_koolproxyR.asp"
CHANGELOG="维护阶段的kpr"
# 查看内核日志
# dmesg | less 或者 dmesg
# 转化DOS格式到unix 需要 apt-get install dos2unix
find . -type f -exec dos2unix {} \;
#get latest rules
rm -rf ./koolproxyR/koolproxyR/data/rules/*.txt
rm -rf ./koolproxyR/koolproxyR/data/rules/*.md5
rm -rf ./koolproxyR/koolproxyR/data/rules/*.dat
rm -rf ./koolproxyR/koolproxyR/data/source.list
# rm -rf ./koolproxyR/koolproxyR/koolproxy
cd koolproxyR/koolproxyR/data/rules
# mkdir oridata
# cd oridata
# 下载三方规则
# 从 https://filterlists.com/ 找规则
# https://tgc.cloud/downloads/hosts.txt 36万DNS规则,kpr 生产出来是72万
wget https://easylist-downloads.adblockplus.org/easylistchina.txt
# https://dev.tencent.com/u/shaoxia1991/p/cjxlist/git/raw/master/cjx-annoyance.txt
wget https://dev.tencent.com/u/shaoxia1991/p/cjxlist/git/raw/master/cjx-annoyance.txt
wget https://secure.fanboy.co.nz/fanboy-annoyance.txt
# ADGUARD-DNS过滤规则
# wget -O yhosts.txt https://filters.adtidy.org/extension/chromium/filters/15.txt
# yhosts过滤规则
# https://dev.tencent.com/u/shaoxia1991/p/yhosts/git/raw/master/data/tvbox.txt
wget -O yhosts.txt https://dev.tencent.com/u/shaoxia1991/p/yhosts/git/raw/master/hosts
wget -O tvbox.txt https://dev.tencent.com/u/shaoxia1991/p/yhosts/git/raw/master/data/tvbox.txt
cat tvbox.txt >> yhosts.txt
# ad.txt:合并EasylistChina、EasylistLite、CJX'sAnnoyance,以及补充的一些规则;
# ad2.txt:仅合并EasylistChina、EasylistLite、CJX'sAnnoyance;
# ad3.txt:合并EasylistChina、EasylistLite、CJX'sAnnoyance、EasyPrivacy;
# wget https://gitee.com/halflife/list/raw/master/ad.txt
# 分割三方规则
# # split -l 1 easylistchina.txt ./../easylistchina_
# split -l 1 yhosts.txt ./../chengfeng_
# # split -l 999 fanboy-annoyance.txt ./../fanboy_
# cd ..
# 同步kp官方规则
# wget https://kprules.b0.upaiyun.com/koolproxy.txt
# wget https://kprules.b0.upaiyun.com/daily.txt
# 暂时先用临时的替代
# wget https://kprules.b0.upaiyun.com/kp.dat
# wget https://kprules.b0.upaiyun.com/user.txt
# 同步Kpr视频规则及md5
wget https://dev.tencent.com/u/shaoxia1991/p/koolproxyR_rule_list/git/raw/master/kp.dat
wget https://dev.tencent.com/u/shaoxia1991/p/koolproxyR_rule_list/git/raw/master/kp.dat.md5
wget https://dev.tencent.com/u/shaoxia1991/p/koolproxyr/git/raw/master/koolproxyR/koolproxyR/data/rules/user.txt
## ---------------------------------------------------fanboy处理开始------------------------------------------------------
## 删除导致KP崩溃的规则
sed -i '/^\$/d' fanboy-annoyance.txt
sed -i '/\*\$/d' fanboy-annoyance.txt
# 给三大视频网站放行 由kp.dat负责
sed -i '/youku.com/d' fanboy-annoyance.txt
sed -i '/g.alicdn.com/d' fanboy-annoyance.txt
sed -i '/tudou.com/d' fanboy-annoyance.txt
sed -i '/iqiyi.com/d' fanboy-annoyance.txt
sed -i '/qq.com/d' fanboy-annoyance.txt
sed -i '/gtimg.cn/d' fanboy-annoyance.txt
# 给知乎放行
sed -i '/zhihu.com/d' fanboy-annoyance.txt
# 将规则转化成kp能识别的https
cat fanboy-annoyance.txt | grep "^||" | sed 's#^||#||https://#g' >> fanboy-annoyance_https.txt
# 移出https不支持规则domain=
sed -i 's/\(,domain=\).*//g' fanboy-annoyance_https.txt
sed -i 's/\(\$domain=\).*//g' fanboy-annoyance_https.txt
sed -i 's/\(domain=\).*//g' fanboy-annoyance_https.txt
sed -i '/\^$/d' fanboy-annoyance_https.txt
sed -i '/\^\*\.gif/d' fanboy-annoyance_https.txt
sed -i '/\^\*\.jpg/d' fanboy-annoyance_https.txt
cat fanboy-annoyance.txt | grep "^||" | sed 's#^||#||http://#g' >> fanboy-annoyance_https.txt
cat fanboy-annoyance.txt | grep -i '^[0-9a-z]'| grep -v '^http'| sed 's#^#https://#g' >> fanboy-annoyance_https.txt
cat fanboy-annoyance.txt | grep -i '^[0-9a-z]'| grep -v '^http'| sed 's#^#http://#g' >> fanboy-annoyance_https.txt
cat fanboy-annoyance.txt | grep -i '^[0-9a-z]'| grep -i '^http' >> fanboy-annoyance_https.txt
# 给github的https放行
sed -i '/github/d' fanboy-annoyance_https.txt
# 给apple的https放行
sed -i '/apple.com/d' fanboy-annoyance_https.txt
sed -i '/mzstatic.com/d' fanboy-annoyance_https.txt
# 给api.twitter.com的https放行
sed -i '/twitter.com/d' fanboy-annoyance_https.txt
# 给facebook.com的https放行
sed -i '/facebook.com/d' fanboy-annoyance_https.txt
sed -i '/fbcdn.net/d' fanboy-annoyance_https.txt
# 给 instagram.com 放行
sed -i '/instagram.com/d' fanboy-annoyance_https.txt
# 删除可能导致Kpr变慢的Https规则
sed -i '/\.\*\//d' fanboy-annoyance_https.txt
# 给国内三大电商平台放行
sed -i '/jd.com/d' fanboy-annoyance_https.txt
sed -i '/taobao.com/d' fanboy-annoyance_https.txt
sed -i '/tmall.com/d' fanboy-annoyance_https.txt
# 删除不必要信息重新打包 15 表示从第15行开始 $表示结束
sed -i '15,$d' fanboy-annoyance.txt
# 合二归一
cat fanboy-annoyance_https.txt >> fanboy-annoyance.txt
# 删除可能导致kpr卡死的神奇规则
sed -i '/https:\/\/\*/d' fanboy-annoyance.txt
# 给 netflix.com 放行
sed -i '/netflix.com/d' fanboy-annoyance.txt
# 给 tvbs.com 放行
sed -i '/tvbs.com/d' fanboy-annoyance.txt
sed -i '/googletagmanager.com/d' fanboy-annoyance.txt
# 给 microsoft.com 放行
sed -i '/microsoft.com/d' fanboy-annoyance.txt
# 终极 https 卡顿优化 grep -n 显示行号 awk -F 分割数据 sed -i "${del_rule}d" 需要""" 和{}引用变量
# 当 koolproxyR_del_rule 是1的时候就一直循环,除非 del_rule 变量为空了。
koolproxyR_del_rule=1
while [ $koolproxyR_del_rule = 1 ];do
del_rule=`cat fanboy-annoyance.txt | grep -n 'https://' | grep '\*' | grep -v '/\*'| grep -v '\^\*' | grep -v '\*\=' | grep -v '\$s\@' | grep -v '\$r\@'| awk -F":" '{print $1}' | sed -n '1p'`
if [[ "$del_rule" != "" ]]; then
sed -i "${del_rule}d" fanboy-annoyance.txt
else
koolproxyR_del_rule=0
fi
done
## -------------------------------------------------------fanboy处理结束------------------------------------------------------
## ---------------------------------------------------------KPR 中国简易规则处理开始 -------------------------------------------------------
cat cjx-annoyance.txt >> easylistchina.txt
sed -i '/^\$/d' easylistchina.txt
sed -i '/\*\$/d' easylistchina.txt
# 给btbtt.替换过滤规则。
sed -i 's#btbtt.\*#\*btbtt.\*#g' easylistchina.txt
# 给手机百度图片放行
sed -i '/baidu.com\/it\/u/d' easylistchina.txt
# # 给手机百度放行
# sed -i '/mbd.baidu.com/d' easylistchina.txt
# 给知乎放行
sed -i '/zhihu.com/d' easylistchina.txt
# 将规则转化成kp能识别的https
cat easylistchina.txt | grep "^||" | sed 's#^||#||https://#g' >> easylistchina_https.txt
# 移出https不支持规则domain=
sed -i 's/\(,domain=\).*//g' easylistchina_https.txt
sed -i 's/\(\$domain=\).*//g' easylistchina_https.txt
sed -i 's/\(domain=\).*//g' easylistchina_https.txt
sed -i '/\^$/d' easylistchina_https.txt
sed -i '/\^\*\.gif/d' easylistchina_https.txt
sed -i '/\^\*\.jpg/d' easylistchina_https.txt
cat easylistchina.txt | grep "^||" | sed 's#^||#||http://#g' >> easylistchina_https.txt
cat easylistchina.txt | grep -i '^[0-9a-z]'| grep -v '^http'| sed 's#^#https://#g' >> easylistchina_https.txt
# 源文件替换成http
cat easylistchina.txt | grep -i '^[0-9a-z]'| grep -v '^http'| sed 's#^#http://#g' >> easylistchina_https.txt
cat easylistchina.txt | grep -i '^[0-9a-z]'| grep -i '^http' >> easylistchina_https.txt
cat easylistchina.txt | grep -i '^[0-9a-z]'| grep -i '^|http' >> easylistchina_https.txt
# 给facebook.com的https放行
sed -i '/facebook.com/d' easylistchina_https.txt
sed -i '/fbcdn.net/d' easylistchina_https.txt
# 删除可能导致Kpr变慢的Https规则
sed -i '/\.\*\//d' easylistchina_https.txt
# 腾讯视频真的没办法了。找大佬帮我把
# 删除不必要信息重新打包 15 表示从第15行开始 $表示结束
sed -i '6,$d' easylistchina.txt
# 合二归一
# https://dev.tencent.com/u/shaoxia1991/p/koolproxyR_rule_list/git/raw/master/kpr_our_rule.txt
wget https://dev.tencent.com/u/shaoxia1991/p/koolproxyR_rule_list/git/raw/master/kpr_our_rule.txt
cat easylistchina_https.txt >> easylistchina.txt
# 给三大视频网站放行 由kp.dat负责
sed -i '/youku.com/d' easylistchina.txt
sed -i '/iqiyi.com/d' easylistchina.txt
sed -i '/g.alicdn.com/d' easylistchina.txt
sed -i '/tudou.com/d' easylistchina.txt
sed -i '/gtimg.cn/d' easylistchina.txt
# 给https://qq.com的html规则放行
sed -i '/qq.com/d' easylistchina.txt
# 删除可能导致kpr卡死的神奇规则
sed -i '/https:\/\/\*/d' easylistchina.txt
# 给国内三大电商平台放行
sed -i '/jd.com/d' easylistchina.txt
sed -i '/taobao.com/d' easylistchina.txt
sed -i '/tmall.com/d' easylistchina.txt
# 给 tvbs.com 放行
sed -i '/tvbs.com/d' easylistchina.txt
sed -i '/googletagmanager.com/d' easylistchina.txt
# 给 netflix.com 放行
sed -i '/netflix.com/d' easylistchina.txt
# 给 microsoft.com 放行
sed -i '/microsoft.com/d' easylistchina.txt
# 给apple的https放行
sed -i '/apple.com/d' easylistchina.txt
sed -i '/mzstatic.com/d' easylistchina.txt
# 终极 https 卡顿优化 grep -n 显示行号 awk -F 分割数据 sed -i "${del_rule}d" 需要""" 和{}引用变量
# 当 koolproxyR_del_rule 是1的时候就一直循环,除非 del_rule 变量为空了。
koolproxyR_del_rule=1
while [ $koolproxyR_del_rule = 1 ];do
del_rule=`cat easylistchina.txt | grep -n 'https://' | grep '\*' | grep -v '/\*'| grep -v '\^\*' | grep -v '\*\=' | grep -v '\$s\@' | grep -v '\$r\@'| awk -F":" '{print $1}' | sed -n '1p'`
if [[ "$del_rule" != "" ]]; then
sed -i "${del_rule}d" easylistchina.txt
else
koolproxyR_del_rule=0
fi
done
cat kpr_our_rule.txt >> easylistchina.txt
# -----------------------------------------KPR 中国简易规则处理结束------------------------------------------------
# -------------------------------------- 补充规则处理开始----------------------------------------------------------
# 删除不必要信息重新打包 0-11行 表示从第15行开始 $表示结束
# sed -i '1,11d' yhosts.txt
# 开始Kpr规则化处理
cat yhosts.txt > yhosts_https.txt
sed -i 's/^127.0.0.1\ /||https:\/\//g' yhosts_https.txt
cat yhosts.txt >> yhosts_https.txt
sed -i 's/^127.0.0.1\ /||http:\/\//g' yhosts_https.txt
# 处理tvbox.txt本身规则。
sed -i 's/^127.0.0.1\ /||/g' tvbox.txt
# 给国内三大电商平台放行
sed -i '/jd.com/d' yhosts_https.txt
sed -i '/taobao.com/d' yhosts_https.txt
sed -i '/tmall.com/d' yhosts_https.txt
# 合二归一
cat yhosts_https.txt > yhosts.txt
cat tvbox.txt >> yhosts.txt
# 此处对yhosts进行单独处理
sed -i 's/^@/!/g' yhosts.txt
sed -i 's/^#/!/g' yhosts.txt
sed -i '/localhost/d' yhosts.txt
sed -i '/broadcasthost/d' yhosts.txt
sed -i '/broadcasthost/d' yhosts.txt
sed -i '/cn.bing.com/d' yhosts.txt
# 给三大视频网站放行 由kp.dat负责
sed -i '/youku.com/d' yhosts.txt
sed -i '/iqiyi.com/d' yhosts.txt
sed -i '/g.alicdn.com/d' yhosts.txt
sed -i '/tudou.com/d' yhosts.txt
sed -i '/gtimg.cn/d' yhosts.txt
# 给知乎放行
sed -i '/zhihu.com/d' yhosts.txt
# 给qq.com放行
sed -i '/qq.com/d' yhosts.txt
# 给github的https放行
sed -i '/github/d' yhosts.txt
# 给apple的https放行
sed -i '/apple.com/d' yhosts.txt
sed -i '/mzstatic.com/d' yhosts.txt
# 给api.twitter.com的https放行
sed -i '/twitter.com/d' yhosts.txt
# 给facebook.com的https放行
sed -i '/facebook.com/d' yhosts.txt
sed -i '/fbcdn.net/d' yhosts.txt
# 给 instagram.com 放行
sed -i '/instagram.com/d' yhosts.txt
# 删除可能导致kpr卡死的神奇规则
sed -i '/https:\/\/\*/d' yhosts.txt
# 给 tvbs.com 放行
sed -i '/tvbs.com/d' yhosts.txt
sed -i '/googletagmanager.com/d' yhosts.txt
# 给 netflix.com 放行
sed -i '/netflix.com/d' yhosts.txt
# 给 microsoft.com 放行
sed -i '/microsoft.com/d' yhosts.txt
# 终极 https 卡顿优化 grep -n 显示行号 awk -F 分割数据 sed -i "${del_rule}d" 需要""" 和{}引用变量
# 当 koolproxyR_del_rule 是1的时候就一直循环,除非 del_rule 变量为空了。
koolproxyR_del_rule=1
while [ $koolproxyR_del_rule = 1 ];do
del_rule=`cat yhosts.txt | grep -n 'https://' | grep '\*' | grep -v '/\*'| grep -v '\^\*' | grep -v '\*\=' | grep -v '\$s\@' | grep -v '\$r\@'| awk -F":" '{print $1}' | sed -n '1p'`
if [[ "$del_rule" != "" ]]; then
sed -i "${del_rule}d" yhosts.txt
else
koolproxyR_del_rule=0
fi
done
# ---------------------------------------------补充规则处理结束----------------------------------------------
## 删除临时文件
rm *_https.txt
rm kpr_our_rule.txt
rm cjx-annoyance.txt
rm tvbox.txt
# 测试专用
# split -l 1 yhosts.txt chengfeng_
# ls|grep chengfeng_|xargs -n1 -i{} mv {} {}.txt
cd ..
find -name *.txt |sed 's#.*/##' > source.list
# find -name chengfeng* |sed 's#.*/##' >> source.list
# find -name fanboy_* |sed 's#.*/##' >> source.list
sed -i 's/^/0|/' source.list
sed -i 's/$/|0|0/' source.list
sed -i '/user.txt/d' source.list
echo "1|user.txt|0|0" >> source.list
echo "0|kp.dat|0|0" >> source.list
# source.list的格式命名
# 开关 0表示关闭 1表示开启
# 开关|规则名字|规则网址|规则备注名字
# 不支持规则
# 1 小于2个字符的 例如 ab
# ~开头的
# $webrtc,domain=avgle.com
# @@*$stylesheet
cd ..
# 现在在\koolproxyR\koolproxyR\koolproxyR
# wget https://raw.githubusercontent.com/koolshare/ledesoft/master/koolproxy/koolproxy/koolproxy/koolproxy
cd ../..
# 现在在 Y:\koolproxyR 也就是主目录
# # Check and include base
# DIR="$( cd "$( dirname "$BASH_SOURCE[0]" )" && pwd )"
# # now include build_base.sh
# . $DIR/../softcenter/build_base.sh
# # change to module directory
# cd $DIR
# # do something here
#
do_build_result() {
rm -f koolproxyR.tar.gz
tar -zcvf koolproxyR.tar.gz koolproxyR
md5value=`md5sum koolproxyR.tar.gz | cut -d \ -f1`
echo "$VERSION" > version
echo "$md5value" >> version
}
do_build_result
sh backup.sh koolproxyR
cd koolproxyR/koolproxyR/data/rules
# ls | grep .txt | sed 's/^/md5sum /g' | >> rules_md5.sh
md5sum easylistchina.txt|awk '{print $1}' > easylistchina.txt.md5
md5sum kp.dat|awk '{print $1}' > kp.dat.md5
md5sum user.txt|awk '{print $1}' > user.txt.md5
md5sum fanboy-annoyance.txt|awk '{print $1}' > fanboy-annoyance.txt.md5
md5sum yhosts.txt|awk '{print $1}' > yhosts.txt.md5