Update shell script logic

This commit is contained in:
gently 2020-01-20 15:14:48 +08:00
parent cca0e5d592
commit 37b3fdb3bb

View File

@ -4,112 +4,77 @@ source /etc/profile
cd $(cd "$(dirname "$0")";pwd) cd $(cd "$(dirname "$0")";pwd)
echo '开始下载 easylist1...' easylist=(
curl -o ./origin-files/easylist1.txt --connect-timeout 60 \ "https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt"
-s \ "https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjx-annoyance.txt"
https://easylist-downloads.adblockplus.org/easylistchina+easylist.txt "https://easylist.to/easylist/fanboy-annoyance.txt"
"https://easylist.to/easylist/easyprivacy.txt"
)
# shellcheck disable=SC2181 hosts=(
if [ $? -ne 0 ];then "https://raw.githubusercontent.com/neoFelhz/neohosts/gh-pages/full/hosts.txt"
echo '下载失败,请重试' "https://raw.githubusercontent.com/vokins/yhosts/master/hosts"
exit 1 "https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts"
fi )
echo '开始下载 easylist2...' strict_hosts=(
curl -o ./origin-files/easylist2.txt --connect-timeout 60 \ "https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/hosts.txt"
-s \ )
https://raw.githubusercontent.com/cjx82630/cjxlist/master/cjx-annoyance.txt
# shellcheck disable=SC2181 rm -f ./origin-files/easylist*
if [ $? -ne 0 ];then rm -f ./origin-files/hosts*
echo '下载失败,请重试' rm -f ./origin-files/strict-hosts*
exit 1
fi
echo '开始下载 easylist3...' for i in "${!easylist[@]}"
curl -o ./origin-files/easylist3.txt --connect-timeout 60 \ do
-s \ echo "开始下载 easylist${i}..."
https://easylist.to/easylist/fanboy-annoyance.txt curl -o "./origin-files/easylist${i}.txt" --connect-timeout 60 -s "${easylist[$i]}"
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
done
# shellcheck disable=SC2181 for i in "${!hosts[@]}"
if [ $? -ne 0 ];then do
echo '下载失败,请重试' echo "开始下载 hosts${i}..."
exit 1 curl -o "./origin-files/hosts${i}.txt" --connect-timeout 60 -s "${hosts[$i]}"
fi # shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
done
for i in "${!strict_hosts[@]}"
do
echo "开始下载 strict-hosts${i}..."
curl -o "./origin-files/strict-hosts${i}.txt" --connect-timeout 60 -s "${strict_hosts[$i]}"
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
done
echo '开始下载 easylist4...'
curl -o ./origin-files/easylist4.txt --connect-timeout 60 \
-s \
https://easylist.to/easylist/easyprivacy.txt
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
echo '开始下载 hosts1...'
curl -o ./origin-files/hosts1 --connect-timeout 60 \
-s \
https://raw.githubusercontent.com/neoFelhz/neohosts/gh-pages/full/hosts.txt
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
echo '开始下载 hosts2...'
curl -o ./origin-files/hosts2 --connect-timeout 60 \
-s \
https://raw.githubusercontent.com/vokins/yhosts/master/hosts
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
echo '开始下载 hosts3...'
curl -o ./origin-files/hosts3 --connect-timeout 60 \
-s \
https://raw.githubusercontent.com/jdlingyu/ad-wars/master/hosts
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
echo '开始下载 strict-hosts1...'
curl -o ./origin-files/strict-hosts1 --connect-timeout 60 \
-s \
https://raw.githubusercontent.com/hoshsadiq/adblock-nocoin-list/master/hosts.txt
# shellcheck disable=SC2181
if [ $? -ne 0 ];then
echo '下载失败,请重试'
exit 1
fi
cd origin-files cd origin-files
cat hosts* | grep -v -E "^((#.*)|(\s*))$" \ cat hosts*.txt | grep -v -E "^((#.*)|(\s*))$" \
| grep -v -E "^[0-9\.:]+\s+(ip6\-)?(localhost|loopback)$" \ | grep -v -E "^[0-9\.:]+\s+(ip6\-)?(localhost|loopback)$" \
| sed s/0.0.0.0/127.0.0.1/g | sed s/::/127.0.0.1/g | sort \ | sed s/0.0.0.0/127.0.0.1/g | sed s/::/127.0.0.1/g | sort \
| uniq >base-src-hosts.txt | uniq >base-src-hosts.txt
cat strict-hosts* | grep -v -E "^((#.*)|(\s*))$" \ cat strict-hosts*.txt | grep -v -E "^((#.*)|(\s*))$" \
| grep -v -E "^[0-9\.:]+\s+(ip6\-)?(localhost|loopback)$" \ | grep -v -E "^[0-9\.:]+\s+(ip6\-)?(localhost|loopback)$" \
| sed s/0.0.0.0/127.0.0.1/g | sed s/::/127.0.0.1/g | sort \ | sed s/0.0.0.0/127.0.0.1/g | sed s/::/127.0.0.1/g | sort \
| uniq >base-src-strict-hosts.txt | uniq >base-src-strict-hosts.txt
cat easylist*.txt | grep -E "^\|\|[^\*\^]+?\^" | sort | uniq >base-src-easylist.txt cat easylist*.txt | grep -E "^\|\|[^\*\^]+?\^" | sort | uniq >base-src-easylist.txt
cat easylist*.txt | grep -E "^\|\|?[^\^=\/:]+?\*[^\^=\/:]+?\^" | sort | uniq >wildcard-src-easylist.txt cat easylist*.txt | grep -E "^\|\|?([^\^=\/:]+)?\*([^\^=\/:]+)?\^" | sort | uniq >wildcard-src-easylist.txt
cat easylist*.txt | grep -E "^@@\|\|?[^\^=\/:]+?\^[^\/=\*]+?$" | sort | uniq >whiterule-src-easylist.txt cat easylist*.txt | grep -E "^@@\|\|?[^\^=\/:]+?\^([^\/=\*]+)?$" | sort | uniq >whiterule-src-easylist.txt
cd ../ cd ../