Adhosts-block/update_action.sh

175 lines
6.0 KiB
Bash
Raw Permalink Normal View History

2022-06-22 10:54:06 +08:00
#!/usr/bin/env bash
2023-12-01 12:24:57 +08:00
set -e
#set -x
2022-05-25 17:33:15 +08:00
# 下载去广告hosts合并并去重
2023-06-08 15:28:38 +08:00
# 开启curl代理
2023-12-18 09:22:25 +08:00
#mv ~/.curlrc.bak ~/.curlrc
if [ ! -f ~/.curlrc ]; then
if [ -f ~/.curlrc.bak ]; then
mv ~/.curlrc.bak ~/.curlrc
echo "Renamed ~/.curlrc.bak to ~/.curlrc"
else
echo "No ~/.curlrc.bak file found"
fi
else
echo "File ~/.curlrc already exists"
fi
2023-06-08 15:28:38 +08:00
2022-05-25 17:33:15 +08:00
t=host hn=hosts an=adguard
f=host-full hf=hosts-full af=adguard-full
# 转换为 adguard 格式函数
adguard() {
sed "1d;s/^/||/g;s/$/^/g" $1
}
# 去除误杀函数
manslaughter(){
sed -i "/tencent\|c\.pc\|xmcdn\|googletagservices\|zhwnlapi\|samizdat/d" $1
}
# 海阔影视 hosts 导入成功
#curl -s https://gitee.com/qiusunshine233/hikerView/raw/master/ad_v1.txt > $t
#sed -i 's/\&\&/\n/g' $t
#curl -s https://gitee.com/qiusunshine233/hikerView/raw/master/ad_v2.txt >> $t
#sed -i '/\(\/\|@\|\*\|^\.\|\:\)/d;s/^/127.0.0.1 /g' $t && echo "海阔影视 hosts 导入成功"
2022-06-21 14:13:46 +08:00
# 导入hosts格式
2023-12-01 13:55:24 +08:00
while read i;do curl -s "$i">>$t&&echo "$i 下载成功"||echo "$i 下载失败";done<<EOF
2023-02-17 10:34:40 +08:00
https://gitlab.com/rainmor/Adhosts-block/-/raw/master/sqwei/hosts
2022-05-25 17:33:15 +08:00
https://raw.githubusercontent.com/francis-zhao/quarklist/master/dist/hosts
2023-02-17 11:16:19 +08:00
https://raw.githubusercontent.com/jdlingyu/ad-wars/master/sha_ad_hosts
https://raw.githubusercontent.com/ilpl/ad-hosts/master/hosts
2023-12-18 09:27:26 +08:00
https://raw.githubusercontent.com/lingeringsound/10007/main/all
2024-01-19 14:34:49 +08:00
https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts
2022-05-25 17:33:15 +08:00
EOF
2023-12-21 16:00:26 +08:00
#https://raw.githubusercontent.com/Cats-Team/AdRules/main/hosts.txt
2023-12-21 15:55:36 +08:00
#https://hblock.molinero.dev/hosts
#https://raw.githubusercontent.com/neodevpro/neodevhost/master/lite_host
#https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/hosts.txt
2023-12-18 21:27:41 +08:00
#https://raw.githubusercontent.com/StevenBlack/hosts/master/alternates/fakenews-gambling-social-only/hosts
2023-11-30 08:40:07 +08:00
#https://hosts.ubuntu101.co.za/hosts
2022-07-11 16:22:04 +08:00
#https://raw.githubusercontent.com/neodevpro/neodevhost/master/lite_host
#https://raw.githubusercontent.com/Goooler/1024_hosts/master/hosts
#https://raw.githubusercontent.com/VeleSila/yhosts/master/hosts
2022-06-21 15:40:03 +08:00
#https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts
2022-06-21 13:52:10 +08:00
#https://raw.githubusercontent.com/BlackJack8/iOSAdblockList/master/Regular%20Hosts.txt
2022-06-21 11:53:07 +08:00
#https://hblock.molinero.dev/hosts
#https://raw.githubusercontent.com/badmojr/1Hosts/master/Xtra/hosts.txt
2022-06-21 11:06:36 +08:00
#https://raw.githubusercontent.com/E7KMbb/AD-hosts/master/system/etc/hosts
2022-05-25 17:33:15 +08:00
2024-01-19 14:45:56 +08:00
2022-06-21 14:13:46 +08:00
# 域名加速hosts
2024-01-25 13:48:03 +08:00
#curl -s https://raw.githubusercontent.com/521xueweihan/GitHub520/master/hosts | sed "/#/d;s/ \{2,\}/ /g" > gh
2023-11-29 15:24:27 +08:00
curl -s https://gitlab.com/ineo6/hosts/-/raw/master/hosts | sed "/#/d;s/ \{2,\}/ /g" >> gh
2023-09-12 14:02:20 +08:00
#curl -s https://raw.githubusercontent.com/Cats-Team/AdRules/main/rules/fasthosts.txt | sed "/#/d;s/ \{2,\}/ /g" > gh
2023-12-22 09:12:26 +08:00
#curl -s https://gitlab.com/rainmor/Adhosts-block/-/raw/master/sqwei/hosts_rewrite | sed "/#/d;s/ \{2,\}/ /g" >> gh
cat sqwei/hosts_rewrite | sed "/#/d;s/ \{2,\}/ /g" >> gh
2022-05-25 17:33:15 +08:00
# EnergizedProtection 域名白名单
#curl -s https://raw.githubusercontent.com/EnergizedProtection/unblock/master/basic/formats/domains.txt | sed "/#/d;s/ \{2,\}/ /g" > wlist
# 自己维护的域名白名单
2023-12-22 09:12:26 +08:00
#curl -s https://gitlab.com/rainmor/Adhosts-block/-/raw/master/hosts_allow | sed "/#/d;s/ \{2,\}/ /g" >> wlist
cat hosts_allow | sed "/#/d;s/ \{2,\}/ /g" >> wlist
2022-05-25 17:33:15 +08:00
# keytoolazy
2023-02-03 14:29:08 +08:00
#curl -s https://keytoolazy.coding.net/p/hms-core/d/HMS-CORE/git/raw/master/ads/allow.prop | sed "/#/d;s/ \{2,\}/ /g" >> wlist
2022-08-10 10:53:02 +08:00
# 泛域名白名单
2023-12-22 09:14:54 +08:00
#curl -s https://gitlab.com/rainmor/Adhosts-block/-/raw/master/hosts_allow_g | sed "/#/d;s/ \{2,\}/ /g" >> g_wlist
cat hosts_allow_g | sed "/#/d;s/ \{2,\}/ /g" >> g_wlist
2022-08-10 10:53:02 +08:00
2022-05-25 17:33:15 +08:00
# 冷莫 hosts
# curl -s https://file.trli.club/dns/ad-hosts.txt | sed "/==/d;/^$/d;1d;s/0.0.0.0 /127.0.0.1 /g;/^\:\|^\*/d" > $f
# curl -s https://file.trli.club/dns/ad-domains.txt | sed "/^#/d" | awk '{print "127.0.0.1 "$0}' > $f
# 转换换行符
2023-12-01 13:55:24 +08:00
#dos2unix *
#dos2unix */*
2022-05-25 17:33:15 +08:00
# 保留必要 host
# 只保留 127、0 开头的行
sed -i "/^\s*\(127\|0\)/!d" $t
# 删除空白符和 # 及后
sed -i "s/\s\|#.*//g" $t
# 删除 127.0.0.1 、 0.0.0.0 、 空行、第一行
sed -i "s/^\(127.0.0.1\|0.0.0.0\)//g" $t
2022-06-21 13:52:10 +08:00
2024-10-25 16:32:08 +08:00
curl -s https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt | sed "/#/d;s/ \{2,\}/ /g" >> $t
2024-01-19 14:45:56 +08:00
curl -s https://bitbucket.org/hacamer/adrules/raw/main/mosdns_adrules.txt | sed 's/domain://' >> $t
2022-06-21 14:08:42 +08:00
2024-01-19 14:45:56 +08:00
dos2unix $t gh wlist g_wlist
2022-06-21 14:13:46 +08:00
# 导入domain list格式
2023-12-21 16:34:55 +08:00
#while read i;do curl -s "$i">>$t&&echo "$i 下载成功"||echo "$i 下载失败";done<<EOF
#https://raw.githubusercontent.com/privacy-protection-tools/anti-AD/master/anti-ad-domains.txt
#EOF
2022-06-21 14:08:42 +08:00
2023-12-21 16:34:55 +08:00
#dos2unix $t
2022-06-21 13:52:10 +08:00
2022-06-21 14:08:42 +08:00
sed -i "s/\s\|#.*//g" $t
2022-07-11 16:00:19 +08:00
# 删除 . 或 * 或||开头的
2022-07-11 16:14:40 +08:00
sed -i "/^\.\|^\*\|^|/d" $t
2022-05-25 17:33:15 +08:00
# 使用声明
2023-11-30 09:55:34 +08:00
statement="# 更新时间:$(date '+%Y-%m-%d %T')\n# hosts获取https://gitlab.com/rainmor/Adhosts-block/-/raw/master/hosts\n# 邮箱: sqwei2012@gmail.com\n# 如果存在误杀情况请通过邮件把被误杀的APP或者域名发给我谢谢\n\n"
2022-05-25 17:33:15 +08:00
# 获得标准去重版 host
sort -u $t -o $t
sed -i "/^127.0.0.1$/d;/^0.0.0.0$/d;/^\s*$/d" $t
# 去除误杀
#manslaughter $t
# 获得标准版 hosts
#(echo -e $statement && sed "s/^/127.0.0.1 /g" $t && cat gh) > $hn
(echo -e $statement && sed "s/^/0.0.0.0 /g" $t && cat gh) > $hn
#(echo -e $statement && sed "s/^/127.0.0.1 /g" $t) > $hn
# 配置域名白名单
for i in `cat wlist`;do
sed -i "/0.0.0.0 $i$/d" $hn
done
2022-08-10 10:53:02 +08:00
for i in `cat g_wlist`;do
sed -i "/0.0.0.0 .*.$i$/d" $hn
done
2022-05-25 17:33:15 +08:00
# 获得标准 adguard 版规则
2022-06-22 14:27:54 +08:00
#adguard $t > $an
2022-05-25 17:33:15 +08:00
# 获得拓展去重版 host
# cat $t $f | sort -u -o $f
# sed -i "/^127.0.0.1$/d;/^0.0.0.0$/d;/^\s*$/d" $f
# manslaughter $f
# 删除 . 或 * 开头的
# sed -i "/^\.\|^\*/d" $f
# 获得拓展版 hosts
# (echo -e $statement && sed "s/^/127.0.0.1 /g" $f && cat gh) > $hf
# (echo -e $statement && sed "s/^/127.0.0.1 /g" $f) > $hf
# 清洗 127.0.0.1 127.0.0.1
# sed -i 's+127.0.0.1 127.0.0.1 +127.0.0.1 +g' $hf
# cat $hf | sort -u -o $hf
# 获得拓展 adguard 版规则
# adguard $f > $af
#rm $t $f gh
#rm $t $f
2023-02-03 17:31:41 +08:00
rm $t gh wlist g_wlist
#rm $t gh
2023-06-08 15:28:38 +08:00
# 关闭curl代理
mv ~/.curlrc ~/.curlrc.bak