参考:https://help.ubnt.com/hc/en-us/articles/205223340-EdgeRouter-Ad-blocking-content-filtering-using-EdgeRouter
第一步,获取并生成conf配置文件:
#!/bin/bash
# define variables
host_version=0
host_new=0
host_url="https://raw.githubusercontent.com/vokins/yhosts/master/hosts"
cd /root/hosts
echo
date
echo
echo +++ Delete old files...
echo
rm -f temp1 temp2 temp3 result host
rm -f hosts*
echo +++ Download new hosts file...
echo
wget $host_url
echo +++ Check if download succeeded...
echo
if [ ! -f hosts ]; then
echo --- Download failed... Exit.
exit
fi
host_version=$(sed -n '1p' version | awk -F"=" '{print $2}')
cat hosts|grep version|sed -n 1p > version
host_new=$(sed -n '1p' version | awk -F"=" '{print $2}')
echo +++ Version check:
echo +++ Old: $host_version, New: $host_new
# check hosts version
if [ "$host_version"x = "$host_new"x ]; then
echo --- No update for hosts. Exit
exit
fi
########################################################
# following lines are just shell learning, ignore.
# get column 2, space as delimiter.
# cat hosts|cut -d ' ' -f 2
#
# compress extra space
# cat hosts|tr -s ' '
#
# compress extra space and get column 2, space as delimiter
# cat hosts|tr -s ' '|cut -d ' ' -f 2
#
# remove comment line start with "#"
# cat hosts| grep -v ^# | grep -v ^$
########################################################
echo
echo +++ Split hosts file to two column file.
cat hosts| grep -v ^# | grep -v ^$|tr -s ' '|cut -d ' ' -f 1 >temp1
cat hosts| grep -v ^# | grep -v ^$|tr -s ' '|cut -d ' ' -f 2 >temp2
# combine two files and add "address=/" at beginning of each line
echo +++ Combine two column file to one.
paste temp2 temp1 -d "/" | sed 's/^/address=\/&/g' >temp3
echo +++ Add self defined hosts
cat self temp3 > result
# remove ipv6 address and useless hosts
echo +++ Remove useless hosts.
sed -e '/\:/d' result | sed -e '/XiaoQiang/d' | sed -e '/localhost/d' > conf
echo +++ Delete temp files.
rm -f temp1 temp2 temp3 result
echo
echo +++ Copy files to web folder
cp -f ./version /usr/share/nginx/html/hosts/
cp -f ./conf /usr/share/nginx/html/hosts/
echo --- Hosts conf file updated.
将上述脚本设置为Linux开机启动。
第二步,配置EdgeRouter
第一步,获取并生成conf配置文件:
#!/bin/bash
# define variables
host_version=0
host_new=0
host_url="https://raw.githubusercontent.com/vokins/yhosts/master/hosts"
cd /root/hosts
echo
date
echo
echo +++ Delete old files...
echo
rm -f temp1 temp2 temp3 result host
rm -f hosts*
echo +++ Download new hosts file...
echo
wget $host_url
echo +++ Check if download succeeded...
echo
if [ ! -f hosts ]; then
echo --- Download failed... Exit.
exit
fi
host_version=$(sed -n '1p' version | awk -F"=" '{print $2}')
cat hosts|grep version|sed -n 1p > version
host_new=$(sed -n '1p' version | awk -F"=" '{print $2}')
echo +++ Version check:
echo +++ Old: $host_version, New: $host_new
# check hosts version
if [ "$host_version"x = "$host_new"x ]; then
echo --- No update for hosts. Exit
exit
fi
########################################################
# following lines are just shell learning, ignore.
# get column 2, space as delimiter.
# cat hosts|cut -d ' ' -f 2
#
# compress extra space
# cat hosts|tr -s ' '
#
# compress extra space and get column 2, space as delimiter
# cat hosts|tr -s ' '|cut -d ' ' -f 2
#
# remove comment line start with "#"
# cat hosts| grep -v ^# | grep -v ^$
########################################################
echo
echo +++ Split hosts file to two column file.
cat hosts| grep -v ^# | grep -v ^$|tr -s ' '|cut -d ' ' -f 1 >temp1
cat hosts| grep -v ^# | grep -v ^$|tr -s ' '|cut -d ' ' -f 2 >temp2
# combine two files and add "address=/" at beginning of each line
echo +++ Combine two column file to one.
paste temp2 temp1 -d "/" | sed 's/^/address=\/&/g' >temp3
echo +++ Add self defined hosts
cat self temp3 > result
# remove ipv6 address and useless hosts
echo +++ Remove useless hosts.
sed -e '/\:/d' result | sed -e '/XiaoQiang/d' | sed -e '/localhost/d' > conf
echo +++ Delete temp files.
rm -f temp1 temp2 temp3 result
echo
echo +++ Copy files to web folder
cp -f ./version /usr/share/nginx/html/hosts/
cp -f ./conf /usr/share/nginx/html/hosts/
echo --- Hosts conf file updated.
将上述脚本设置为Linux开机启动。
第二步,配置EdgeRouter
iq019 Kickscrew israel,flight club shipping to nz,clarks shoes canada,riekerbootsaustralia,klekt review,lowa túrabakancs,keds canada,joya shoes canada,melissacanada iw045
回复删除