adguardhome广告规则生成脚本

第一步、新建adguardhome.sh文件填入下面的内容

#!/bin/bash
cd /opt/adguardhome/dns_hosts          #脚本的路径
# 下载广告规则源
wget -O i1.txt https://anti-ad.net/easylist.txt
wget -O i2.txt https://gitee.com/halflife/list/raw/master/ad.txt
wget -O i3.txt https://www.kbsml.com/wp-content/uploads/adblock/adguard/adg-kall-dns.txt
wget -O i4.txt https://www.kbsml.com/wp-content/uploads/adblock/adguard/ADgk.txt
wget -O i5.txt https://cats-team.coding.net/p/adguard/d/AdRules/git/raw/main/dns.txt
wget -O i6.txt https://neodev.team/adblocker
wget -O i7.txt https://hblock.molinero.dev/hosts_adblock.txt
wget -O i8.txt https://abp.oisd.nl/
# 合并与删除重复项
cat i*.txt > mergd.txt
cat mergd.txt | grep '^|' > block.txt
cat mergd.txt | grep '^@' > allow.txt
cat mergd.txt | grep '^/' > test1.txt
cat test1.txt block.txt allow.txt > tmpp.txt
sort -n tmpp.txt | uniq > tmp.txt

# 计数规则
num=`cat tmp.txt | wc -l`
# 添加标题与日期
echo "! Version: `date +"%Y-%m-%d %H:%M:%S" `" >> tpdate.txt
echo "! Total count: $num" >> tpdate.txt
cat file_header.name tpdate.txt tmp.txt > final.txt

mv final.txt ../../dns.txt
rm *.txt
cd ../../
exit

第二步、新建file_header.name文件填入下面的内容

[adguardhome_dns]
! Title: adguardhome_dns
! Powerd by adguardhome
! Expires: 24 Hours

第三步、使用注意事项

①将file_header.name文件放入/opt/adguardhome/dns_hosts文件夹中,没有的话自己新建一个

②广告源可自行添加,添加新的广告源时要把i后面的数字改一下

第四步、运行脚本

cd /opt/adguardhome/dns_hosts
bash adguardhome.sh

上一篇
下一篇