diff --git a/.github/custom.txt b/.github/custom.txt new file mode 100644 index 0000000..0685f3a --- /dev/null +++ b/.github/custom.txt @@ -0,0 +1,204 @@ +## 自定义规则优先级 - 开始 + +# 移除(!) > 添加(@) > 排除(*) + +## 自定义规则优先级 - 结束 + +## 自定义规则语法 - 开始 + +# (@@@) | 向 C 及 G 列表添加域名 +(@@@)example.org + +# (!!!) | 向 C 及 G 列表移除域名 +(!!!)example.org + +# (***) | 向 C 及 G 列表排除域名 (*.example.org & example.org) +(***)example.org + +# (!**) | 向 C 及 G 列表排除关键词 (*example.org*) +(!**)example.org + +# (@%@) | 仅向 C 列表添加域名 +(@%@)example.org + +# (!%!) | 仅向 C 列表移除域名 +(!%!)example.org + +# (*%*) | 仅向 C 列表排除域名 (*.example.org & example.org) +(*%*)example.org + +# (!%*) | 仅向 C 列表排除关键词 (*example.org*) +(!%*)example.org + +# (@&@) | 仅向 G 列表添加域名 +(@&@)example.org + +# (!&!) | 仅向 G 列表移除域名 +(!&!)example.org + +# (*&*) | 仅向 G 列表排除域名 (*.example.org & example.org) +(*&*)example.org + +# (!&*) | 仅向 G 列表排除关键词 (*example.org*) +(!&*)example.org + +# (@%!) | 向 C 列表添加域名并将其从 G 列表中移除 +(@%!)example.org + +# (!%@) | 向 C 列表移除域名并将其从 G 列表中添加 +(!%@)example.org + +# (@&!) | 向 G 列表添加域名并将其从 C 列表中移除 +(@&!)example.org + +# (!&@) | 向 G 列表移除域名并将其从 C 列表中添加 +(!&@)example.org + +## 自定义规则语法 - 结束 + +## 自定义规则 - 开始 + +# COM.CN +(*&*)com.cn + +# AcgnX +(@&!)share.acgnx.net +(@&!)share.acgnx.se +(@&!)www.acgnx.se + +# AniDB +(@&!)anidb.net + +# AniX.Moe +(@&!)www.anix.moe + +# Apple +(@%!)18-courier.push.apple.com +(@%!)amp-api-edge.music.apple.com +(@%!)apple-dns.cn +(@%!)apple-dns.net +(@%!)apple.com +(@%!)apple.com.cn +(@%!)apps.mzstatic.com.mwcname.com +(@%!)cl3.apple.com.mwcname.com +(@%!)cl5.apple.com.mwcname.com +(@%!)client-api.itunes.apple.com.mwcname.com +(@%!)gsa.apple.com.akadns.net +(@%!)icloud.com +(@%!)init-p01md.apple.com +(@%!)init-p01md.apple.com.mwcname.com +(@%!)init.ess.apple.com +(@%!)init.itunes.apple.com +(@%!)init.itunes.apple.com.mwcname.com +(@%!)iphone-ld.apple.com.mwcname.com +(@%!)mesu.apple.com.mwcname.com +(@%!)pd.itunes.apple.com.mwcname.com +(@%!)play.itunes.apple.com.mwcname.com +(@%!)se-edge.itunes-apple.com +(@%!)se-edge.itunes.apple.com.mwcname.com +(@%!)search.itunes.apple.com.mwcname.com +(@%!)securemetrics.apple.com.cn +(@%!)www-cdn.icloud.com.akadns.net +(@%!)www.apple.com.cn +(@%!)www.icloud.com + +# 阿里云 +(@%!)alibabadns.com +(@%!)dns.alidns.com + +# 必应 +(@%!)cn.bing.com +(@%!)cn.bing.net +(@%!)www.bing.com + +# Cloudflare +(@&!)1dot1dot1dot1.cloudflare-dns.com +(@&!)cloudflare-dns.com +(@&!)dash.cloudflare.com +(@&!)dns.cloudflare.com + +# Cloudflare Workers +(@&!)workers.dev + +# DNSPod +(@%!)dns.pub +(@%!)doh.pub +(@%!)dot.pub + +# Denpasoft +(@&!)denpasoft.com + +# 抖音 #10 +(@%!)douyincdn.com + +# fanart.tv +(@&!)assets.fanart.tv +(@&!)fanart.tv + +# FastGit +(@&!)archive.fastgit.org +(@&!)assets.fastgit.org +(@&!)customer-stories-feed.fastgit.org +(@&!)download.fastgit.org +(@&!)fastgit.org +(@&!)hub.fastgit.org +(@&!)raw.fastgit.org + +# GitHub +(@&!)github.com +(@&!)githubusercontent.com +(@&!)desktop.githubusercontent.com + +# Google +(@&!)dns.google +(@&!)google.com +(@&!)redirector.googlevideo.com + +# it-global.cn #8 +(@%!)it-global.cn + +# jsDelivr +(@&!)cdn.jsdelivr.net +(@&!)jsdelivr.net + +# Miro +(@&!)miro.com + +# OpenDNS +(@&!)dns.opendns.com +(@&!)doh.opendns.com + +# ServiceNow +(@&!)service-now.com + +# SmartSheet +(@&!)app.smartsheet.com +(@&!)smartsheet.com + +# UUP dump +(@&!)uupdump.net + +# 钱美流量 #8 +(@%!)ssnm.xyz + +# 上海闪耀信息科技有限公司 / 闪耀科技 #8 +(@%!)global-ict.cn +(@%!)global-idc.net + +# UC 浏览器 #8 +(@%!)uc.cn + +# VCB-S +(@&!)bbs.acgrip.com + +# Vercel +(@%!)cname.vercel-dns.com +(@%!)vercel.com + +# 支付宝 +(@%!)mobilegw.alipay.com + +# 治杰 Online +(@&!)zhijie.online + +## 自定义规则 - 结束 diff --git a/.github/release.sh b/.github/release.sh new file mode 100644 index 0000000..627d842 --- /dev/null +++ b/.github/release.sh @@ -0,0 +1,527 @@ +#!/bin/bash + +# Current Version: 1.2.9 3dfd469 + +## How to get and use? +# git clone "https://github.com/hezhijie0327/GFWList2AGH.git" && bash ./GFWList2AGH/release.sh + +## Function +# Get Data +function GetData() { + cnacc_domain=( + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/apple-cn.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/google-cn.txt" + "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/China/China_Domain.list" + ) + cnacc_trusted=( + "https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf" + "https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf" + "https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/google.china.conf" + ) + gfwlist_base64=( + "https://raw.githubusercontent.com/Loukky/gfwlist-by-loukky/master/gfwlist.txt" + "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt" + "https://raw.githubusercontent.com/poctopus/gfwlist-plus/master/gfwlist-plus.txt" + ) + gfwlist_domain=( + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/greatfire.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/proxy-list.txt" + "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/Global/Global_Domain.list" + "https://raw.githubusercontent.com/pexcn/gfwlist-extras/master/gfwlist-extras.txt" + ) + gfwlist2agh_modify=( + "https://raw.githubusercontent.com/Moexin/AdGuardHome-ByPass/Files/.github/custom.txt" + ) + rm -rf ./gfwlist2* ./Temp && mkdir ./Temp && cd ./Temp + for cnacc_domain_task in "${!cnacc_domain[@]}"; do + curl -s --connect-timeout 15 "${cnacc_domain[$cnacc_domain_task]}" | sed "s/^\.//g" >> ./cnacc_domain.tmp + done + for cnacc_trusted_task in "${!cnacc_trusted[@]}"; do + curl -s --connect-timeout 15 "${cnacc_trusted[$cnacc_trusted_task]}" >> ./cnacc_trusted.tmp + done + for gfwlist_base64_task in "${!gfwlist_base64[@]}"; do + curl -s --connect-timeout 15 "${gfwlist_base64[$gfwlist_base64_task]}" | base64 -d >> ./gfwlist_base64.tmp + done + for gfwlist_domain_task in "${!gfwlist_domain[@]}"; do + curl -s --connect-timeout 15 "${gfwlist_domain[$gfwlist_domain_task]}" | sed "s/^\.//g" >> ./gfwlist_domain.tmp + done + for gfwlist2agh_modify_task in "${!gfwlist2agh_modify[@]}"; do + curl -s --connect-timeout 15 "${gfwlist2agh_modify[$gfwlist2agh_modify_task]}" >> ./gfwlist2agh_modify.tmp + done +} +# Analyse Data +function AnalyseData() { + cnacc_data=($(domain_regex="^(([a-z]{1})|([a-z]{1}[a-z]{1})|([a-z]{1}[0-9]{1})|([0-9]{1}[a-z]{1})|([a-z0-9][-\.a-z0-9]{1,61}[a-z0-9]))\.([a-z]{2,13}|[a-z0-9-]{2,30}\.[a-z]{2,3})$" && lite_domain_regex="^([a-z]{2,13}|[a-z0-9-]{2,30}\.[a-z]{2,3})$" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\@\%\@\)\|\(\@\%\!\)\|\(\!\&\@\)\|\(\@\@\@\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_addition.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\%\!\)\|\(\@\&\!\)\|\(\!\%\@\)\|\(\!\!\!\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_subtraction.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\%\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./cnacc_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\%\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_cnacc_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\%\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./cnacc_keyword.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\%\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_cnacc_keyword.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\@\&\@\)\|\(\@\&\!\)\|\(\!\%\@\)\|\(\@\@\@\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./gfwlist_addition.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\&\!\)\|\(\@\%\!\)\|\(\!\&\@\)\|\(\!\!\!\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./gfwlist_subtraction.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\&\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./gfwlist_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\&\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_gfwlist_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\&\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./gfwlist_keyword.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\&\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_gfwlist_keyword.tmp" && cat "./cnacc_addition.tmp" | grep -E "${lite_domain_regex}" | sort | uniq > "./lite_cnacc_addition.tmp" && cat "./gfwlist_addition.tmp" | grep -E "${lite_domain_regex}" | sort | uniq > "./lite_gfwlist_addition.tmp" && cat "./cnacc_trusted.tmp" | sed "s/\/114\.114\.114\.114//g;s/server\=\///g" | tr "A-Z" "a-z" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_trust.tmp" && cat "./cnacc_trust.tmp" | grep -E "${lite_domain_regex}" | sort | uniq > "./lite_cnacc_trust.tmp" && cat "./cnacc_domain.tmp" | sed "s/domain\://g;s/full\://g" | tr "A-Z" "a-z" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_checklist.tmp" && cat "./gfwlist_base64.tmp" "./gfwlist_domain.tmp" | sed "s/domain\://g;s/full\://g;s/http\:\/\///g;s/https\:\/\///g" | tr -d "|" | tr "A-Z" "a-z" | grep -E "${domain_regex}" | sort | uniq > "./gfwlist_checklist.tmp" && cat "./cnacc_checklist.tmp" | rev | cut -d "." -f 1,2 | rev | sort | uniq > "./lite_cnacc_checklist.tmp" && cat "./gfwlist_checklist.tmp" | rev | cut -d "." -f 1,2 | rev | sort | uniq > "./lite_gfwlist_checklist.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_checklist.tmp" "./gfwlist_checklist.tmp" > "./gfwlist_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./gfwlist_checklist.tmp" "./cnacc_checklist.tmp" | grep -Ev "(\.($(cat './cnacc_exclusion.tmp'))$)|(^$(cat './cnacc_exclusion.tmp')$)|($(cat './cnacc_keyword.tmp'))" > "./cnacc_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./lite_cnacc_checklist.tmp" "./lite_gfwlist_checklist.tmp" > "./lite_gfwlist_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./lite_gfwlist_checklist.tmp" "./lite_cnacc_checklist.tmp" | grep -Ev "(\.($(cat './lite_cnacc_exclusion.tmp'))$)|(^$(cat './lite_cnacc_exclusion.tmp')$)|($(cat './lite_cnacc_keyword.tmp'))" > "./lite_cnacc_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_trust.tmp" "./gfwlist_raw.tmp" | grep -Ev "(\.($(cat './gfwlist_exclusion.tmp'))$)|(^$(cat './gfwlist_exclusion.tmp')$)|($(cat './gfwlist_keyword.tmp'))" > "./gfwlist_raw_new.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_trust.tmp" "./lite_gfwlist_raw.tmp" | grep -Ev "(\.($(cat './lite_gfwlist_exclusion.tmp'))$)|(^$(cat './lite_gfwlist_exclusion.tmp')$)|($(cat './lite_gfwlist_keyword.tmp'))" > "./lite_gfwlist_raw_new.tmp" && cat "./cnacc_raw.tmp" "./lite_cnacc_raw.tmp" "./cnacc_addition.tmp" "./lite_cnacc_addition.tmp" "./cnacc_trust.tmp" "./lite_cnacc_trust.tmp" | sort | uniq > "./cnacc_added.tmp" && cat "./gfwlist_raw_new.tmp" "./lite_gfwlist_raw_new.tmp" "./gfwlist_addition.tmp" "./lite_gfwlist_addition.tmp" | sort | uniq > "./gfwlist_added.tmp" && cat "./lite_cnacc_raw.tmp" "./lite_cnacc_addition.tmp" "./lite_cnacc_trust.tmp" | sort | uniq > "./lite_cnacc_added.tmp" && cat "./lite_gfwlist_raw_new.tmp" "./lite_gfwlist_addition.tmp" | sort | uniq > "./lite_gfwlist_added.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_subtraction.tmp" "./cnacc_added.tmp" > "./cnacc_data.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./gfwlist_subtraction.tmp" "./gfwlist_added.tmp" > "./gfwlist_data.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_subtraction.tmp" "./lite_cnacc_added.tmp" > "./lite_cnacc_data.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./gfwlist_subtraction.tmp" "./lite_gfwlist_added.tmp" > "./lite_gfwlist_data.tmp" && cat "./cnacc_data.tmp" "./lite_cnacc_data.tmp" | sort | uniq | awk "{ print $2 }")) + gfwlist_data=($(cat "./gfwlist_data.tmp" "./lite_gfwlist_data.tmp" | sort | uniq | awk "{ print $2 }")) + lite_cnacc_data=($(cat "./lite_cnacc_data.tmp" | sort | uniq | awk "{ print $2 }")) + lite_gfwlist_data=($(cat "./lite_gfwlist_data.tmp" | sort | uniq | awk "{ print $2 }")) +} +# Generate Rules +function GenerateRules() { + function FileName() { + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "whiteblack" ]; then + generate_temp="black" + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "blackwhite" ]; then + generate_temp="white" + else + generate_temp="debug" + fi + if [ "${software_name}" == "adguardhome" ] || [ "${software_name}" == "adguardhome_new" ] || [ "${software_name}" == "domain" ]; then + file_extension="txt" + elif [ "${software_name}" == "bind9" ] || [ "${software_name}" == "dnsmasq" ] || [ "${software_name}" == "smartdns" ] || [ "${software_name}" == "unbound" ]; then + file_extension="conf" + else + file_extension="dev" + fi + if [ ! -d "../gfwlist2${software_name}" ]; then + mkdir "../gfwlist2${software_name}" + fi + file_name="${generate_temp}list_${generate_mode}.${file_extension}" + file_path="../gfwlist2${software_name}/${file_name}" + } + function GenerateDefaultUpstream() { + case ${software_name} in + adguardhome) + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "blackwhite" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "whiteblack" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + fi + else + if [ "${generate_file}" == "black" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + fi + fi + ;; + adguardhome_new) + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "blackwhite" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "whiteblack" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + fi + else + if [ "${generate_file}" == "black" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + fi + fi + ;; + *) + exit 1 + ;; + esac + } + case ${software_name} in + adguardhome) + domestic_dns=( + # "https://dns.alidns.com:443/dns-query" + # "https://dns.ipv6dns.com:443/dns-query" + # "https://doh.360.cn:443/dns-query" + "https://doh.pub:443/dns-query" + # "tls://dns.alidns.com:853" + # "tls://dns.ipv6dns.com:853" + # "tls://dot.360.cn:853" + # "tls://dot.pub:853" + ) + foreign_dns=( + # "https://dns.google:443/dns-query" + "https://dns.opendns.com:443/dns-query" + # "https://dns11.quad9.net:443/dns-query" + # "https://dns64.dns.google:443/dns-query" + # "tls://dns.google:853" + # "tls://dns.opendns.com:853" + # "tls://dns11.quad9.net:853" + # "tls://dns64.dns.google:853" + ) + function GenerateRulesHeader() { + echo -n "[/" >> "${file_path}" + } + function GenerateRulesBody() { + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "full_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for cnacc_data_task in "${!cnacc_data[@]}"; do + echo -n "${cnacc_data[$cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo -n "${gfwlist_data[$gfwlist_data_task]}/" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ] || [ "${generate_mode}" == "lite_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo -n "${lite_cnacc_data[$lite_cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo -n "${lite_gfwlist_data[$lite_gfwlist_data_task]}/" >> "${file_path}" + done + fi + fi + } + function GenerateRulesFooter() { + if [ "${dns_mode}" == "default" ]; then + echo -e "]#" >> "${file_path}" + elif [ "${dns_mode}" == "domestic" ]; then + echo -e "]${domestic_dns[domestic_dns_task]}" >> "${file_path}" + elif [ "${dns_mode}" == "foreign" ]; then + echo -e "]${foreign_dns[foreign_dns_task]}" >> "${file_path}" + fi + } + function GenerateRulesProcess() { + GenerateRulesHeader + GenerateRulesBody + GenerateRulesFooter + } + if [ "${dns_mode}" == "default" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + elif [ "${dns_mode}" == "domestic" ]; then + FileName && GenerateDefaultUpstream && for domestic_dns_task in "${!domestic_dns[@]}"; do + GenerateRulesProcess + done + elif [ "${dns_mode}" == "foreign" ]; then + FileName && GenerateDefaultUpstream && for foreign_dns_task in "${!foreign_dns[@]}"; do + GenerateRulesProcess + done + fi + ;; + adguardhome_new) + domestic_dns=( + "223.5.5.5" + "180.184.1.1" + # "https://dns.alidns.com:443/dns-query" + # "https://dns.ipv6dns.com:443/dns-query" + # "https://doh.360.cn:443/dns-query" + # "https://doh.pub:443/dns-query" + # "tls://dns.alidns.com:853" + # "tls://dns.ipv6dns.com:853" + # "tls://dot.360.cn:853" + # "tls://dot.pub:853" + ) + foreign_dns=( + "tcp://208.67.220.220:5353" + "tcp://208.67.222.222:5353" + # "https://dns.google:443/dns-query" + # "https://dns.opendns.com:443/dns-query" + # "https://dns11.quad9.net:443/dns-query" + # "https://dns64.dns.google:443/dns-query" + # "tls://dns.google:853" + # "tls://dns.opendns.com:853" + # "tls://dns11.quad9.net:853" + # "tls://dns64.dns.google:853" + ) + function GenerateRulesHeader() { + echo -n "[/" >> "${file_path}" + } + function GenerateRulesBody() { + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "full_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for cnacc_data_task in "${!cnacc_data[@]}"; do + echo -n "${cnacc_data[$cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo -n "${gfwlist_data[$gfwlist_data_task]}/" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ] || [ "${generate_mode}" == "lite_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo -n "${lite_cnacc_data[$lite_cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo -n "${lite_gfwlist_data[$lite_gfwlist_data_task]}/" >> "${file_path}" + done + fi + fi + } + function GenerateRulesFooter() { + if [ "${dns_mode}" == "default" ]; then + echo -e "]#" >> "${file_path}" + elif [ "${dns_mode}" == "domestic" ]; then + echo -e "]${domestic_dns[*]}" >> "${file_path}" + elif [ "${dns_mode}" == "foreign" ]; then + echo -e "]${foreign_dns[*]}" >> "${file_path}" + fi + } + function GenerateRulesProcess() { + GenerateRulesHeader + GenerateRulesBody + GenerateRulesFooter + } + if [ "${dns_mode}" == "default" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + elif [ "${dns_mode}" == "domestic" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + elif [ "${dns_mode}" == "foreign" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + fi + ;; + bind9) + domestic_dns=( + "223.5.5.5 port 53" + ) + foreign_dns=( + "8.8.8.8 port 53" + ) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo -n "zone \"${gfwlist_data[$gfwlist_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo -n "${foreign_dns[$foreign_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + echo -n "zone \"${cnacc_data[$cnacc_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo -n "${domestic_dns[$domestic_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo -n "zone \"${lite_gfwlist_data[$lite_gfwlist_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo -n "${foreign_dns[$foreign_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo -n "zone \"${lite_cnacc_data[$lite_cnacc_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo -n "${domestic_dns[$domestic_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + fi + fi + ;; + dnsmasq) + domestic_dns=( + "223.5.5.5#53" + ) + foreign_dns=( + "8.8.8.8#53" + ) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "server=/${gfwlist_data[$gfwlist_data_task]}/${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "server=/${cnacc_data[$cnacc_data_task]}/${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "server=/${lite_gfwlist_data[$lite_gfwlist_data_task]}/${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "server=/${lite_cnacc_data[$lite_cnacc_data_task]}/${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + done + fi + fi + ;; + domain) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo "${gfwlist_data[$gfwlist_data_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + echo "${cnacc_data[$cnacc_data_task]}" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo "${lite_gfwlist_data[$lite_gfwlist_data_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo "${lite_cnacc_data[$lite_cnacc_data_task]}" >> "${file_path}" + done + fi + fi + ;; + smartdns) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo "nameserver /${gfwlist_data[$gfwlist_data_task]}/${foreign_group:-foreign}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + echo "nameserver /${cnacc_data[$cnacc_data_task]}/${domestic_group:-domestic}" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo "nameserver /${lite_gfwlist_data[$lite_gfwlist_data_task]}/${foreign_group:-foreign}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo "nameserver /${lite_cnacc_data[$lite_cnacc_data_task]}/${domestic_group:-domestic}" >> "${file_path}" + done + fi + fi + ;; + unbound) + domestic_dns=( + "223.5.5.5@853#dns.alidns.com" + ) + foreign_dns=( + "8.8.8.8@853#dns.google" + ) + forward_ssl_tls_upstream="yes" + function GenerateRulesHeader() { + echo "forward-zone:" >> "${file_path}" + } + function GenerateRulesFooter() { + if [ "${dns_mode}" == "domestic" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo " forward-addr: \"${domestic_dns[$domestic_dns_task]}\"" >> "${file_path}" + done + elif [ "${dns_mode}" == "foreign" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo " forward-addr: \"${foreign_dns[$foreign_dns_task]}\"" >> "${file_path}" + done + fi + echo " forward-first: \"yes\"" >> "${file_path}" + echo " forward-no-cache: \"yes\"" >> "${file_path}" + echo " forward-ssl-upstream: \"${forward_ssl_tls_upstream}\"" >> "${file_path}" + echo " forward-tls-upstream: \"${forward_ssl_tls_upstream}\"" >> "${file_path}" + } + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + GenerateRulesHeader && echo " name: \"${gfwlist_data[$gfwlist_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + GenerateRulesHeader && echo " name: \"${cnacc_data[$cnacc_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + GenerateRulesHeader && echo " name: \"${lite_gfwlist_data[$lite_gfwlist_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + GenerateRulesHeader && echo " name: \"${lite_cnacc_data[$lite_cnacc_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + fi + fi + ;; + *) + exit 1 + esac +} +# Output Data +function OutputData() { + ## AdGuard Home + # software_name="adguardhome" && generate_file="black" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome" && generate_file="black" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome" && generate_file="white" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome" && generate_file="white" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome" && generate_file="blackwhite" && generate_mode="full_combine" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome" && generate_file="blackwhite" && generate_mode="lite_combine" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome" && generate_file="whiteblack" && generate_mode="full_combine" && dns_mode="foreign" && GenerateRules + # software_name="adguardhome" && generate_file="whiteblack" && generate_mode="lite_combine" && dns_mode="foreign" && GenerateRules + # software_name="adguardhome" && generate_file="blackwhite" && generate_mode="full" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome" && generate_file="blackwhite" && generate_mode="lite" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome" && generate_file="whiteblack" && generate_mode="full" && dns_mode="foreign" && GenerateRules + # software_name="adguardhome" && generate_file="whiteblack" && generate_mode="lite" && dns_mode="foreign" && GenerateRules + ## AdGuard Home (New) + # software_name="adguardhome_new" && generate_file="black" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome_new" && generate_file="black" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome_new" && generate_file="white" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome_new" && generate_file="white" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + # software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="full_combine" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="lite_combine" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="full_combine" && dns_mode="foreign" && GenerateRules + # software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="lite_combine" && dns_mode="foreign" && GenerateRules + # software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="full" && dns_mode="domestic" && GenerateRules + software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="lite" && dns_mode="domestic" && GenerateRules + # software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="full" && dns_mode="foreign" && GenerateRules + # software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="lite" && dns_mode="foreign" && GenerateRules + ## Bind9 + # software_name="bind9" && generate_file="black" && generate_mode="full" && GenerateRules + # software_name="bind9" && generate_file="black" && generate_mode="lite" && GenerateRules + # software_name="bind9" && generate_file="white" && generate_mode="full" && GenerateRules + # software_name="bind9" && generate_file="white" && generate_mode="lite" && GenerateRules + ## DNSMasq + # software_name="dnsmasq" && generate_file="black" && generate_mode="full" && GenerateRules + # software_name="dnsmasq" && generate_file="black" && generate_mode="lite" && GenerateRules + # software_name="dnsmasq" && generate_file="white" && generate_mode="full" && GenerateRules + # software_name="dnsmasq" && generate_file="white" && generate_mode="lite" && GenerateRules + ## Domain + # software_name="domain" && generate_file="black" && generate_mode="full" && GenerateRules + # software_name="domain" && generate_file="black" && generate_mode="lite" && GenerateRules + # software_name="domain" && generate_file="white" && generate_mode="full" && GenerateRules + # software_name="domain" && generate_file="white" && generate_mode="lite" && GenerateRules + ## SmartDNS + # software_name="smartdns" && generate_file="black" && generate_mode="full" && foreign_group="foreign" && GenerateRules + # software_name="smartdns" && generate_file="black" && generate_mode="lite" && foreign_group="foreign" && GenerateRules + # software_name="smartdns" && generate_file="white" && generate_mode="full" && domestic_group="domestic" && GenerateRules + # software_name="smartdns" && generate_file="white" && generate_mode="lite" && domestic_group="domestic" && GenerateRules + ## Unbound + # software_name="unbound" && generate_file="black" && generate_mode="full" && dns_mode="foreign" && GenerateRules + # software_name="unbound" && generate_file="black" && generate_mode="lite" && dns_mode="foreign" && GenerateRules + # software_name="unbound" && generate_file="white" && generate_mode="full" && dns_mode="domestic" && GenerateRules + # software_name="unbound" && generate_file="white" && generate_mode="lite" && dns_mode="domestic" && GenerateRules + cd .. && rm -rf ./Temp + exit 0 +} + +## Process +# Call GetData +GetData +# Call AnalyseData +AnalyseData +# Call OutputData +OutputData diff --git a/.github/source.sh b/.github/source.sh new file mode 100644 index 0000000..261aee4 --- /dev/null +++ b/.github/source.sh @@ -0,0 +1,523 @@ +#!/bin/bash + +# Current Version: 1.2.9 + +## How to get and use? +# git clone "https://github.com/hezhijie0327/GFWList2AGH.git" && bash ./GFWList2AGH/release.sh + +## Function +# Get Data +function GetData() { + cnacc_domain=( + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/apple-cn.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/direct-list.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/google-cn.txt" + "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/China/China_Domain.list" + ) + cnacc_trusted=( + "https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/accelerated-domains.china.conf" + "https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/apple.china.conf" + "https://raw.githubusercontent.com/felixonmars/dnsmasq-china-list/master/google.china.conf" + ) + gfwlist_base64=( + "https://raw.githubusercontent.com/Loukky/gfwlist-by-loukky/master/gfwlist.txt" + "https://raw.githubusercontent.com/gfwlist/gfwlist/master/gfwlist.txt" + "https://raw.githubusercontent.com/poctopus/gfwlist-plus/master/gfwlist-plus.txt" + ) + gfwlist_domain=( + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/gfw.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/greatfire.txt" + "https://raw.githubusercontent.com/Loyalsoldier/v2ray-rules-dat/release/proxy-list.txt" + "https://raw.githubusercontent.com/blackmatrix7/ios_rule_script/master/rule/Surge/Global/Global_Domain.list" + "https://raw.githubusercontent.com/pexcn/gfwlist-extras/master/gfwlist-extras.txt" + ) + gfwlist2agh_modify=( + "https://raw.githubusercontent.com/hezhijie0327/GFWList2AGH/source/data/data_modify.txt" + ) + rm -rf ./gfwlist2* ./Temp && mkdir ./Temp && cd ./Temp + for cnacc_domain_task in "${!cnacc_domain[@]}"; do + curl -s --connect-timeout 15 "${cnacc_domain[$cnacc_domain_task]}" | sed "s/^\.//g" >> ./cnacc_domain.tmp + done + for cnacc_trusted_task in "${!cnacc_trusted[@]}"; do + curl -s --connect-timeout 15 "${cnacc_trusted[$cnacc_trusted_task]}" >> ./cnacc_trusted.tmp + done + for gfwlist_base64_task in "${!gfwlist_base64[@]}"; do + curl -s --connect-timeout 15 "${gfwlist_base64[$gfwlist_base64_task]}" | base64 -d >> ./gfwlist_base64.tmp + done + for gfwlist_domain_task in "${!gfwlist_domain[@]}"; do + curl -s --connect-timeout 15 "${gfwlist_domain[$gfwlist_domain_task]}" | sed "s/^\.//g" >> ./gfwlist_domain.tmp + done + for gfwlist2agh_modify_task in "${!gfwlist2agh_modify[@]}"; do + curl -s --connect-timeout 15 "${gfwlist2agh_modify[$gfwlist2agh_modify_task]}" >> ./gfwlist2agh_modify.tmp + done +} +# Analyse Data +function AnalyseData() { + cnacc_data=($(domain_regex="^(([a-z]{1})|([a-z]{1}[a-z]{1})|([a-z]{1}[0-9]{1})|([0-9]{1}[a-z]{1})|([a-z0-9][-\.a-z0-9]{1,61}[a-z0-9]))\.([a-z]{2,13}|[a-z0-9-]{2,30}\.[a-z]{2,3})$" && lite_domain_regex="^([a-z]{2,13}|[a-z0-9-]{2,30}\.[a-z]{2,3})$" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\@\%\@\)\|\(\@\%\!\)\|\(\!\&\@\)\|\(\@\@\@\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_addition.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\%\!\)\|\(\@\&\!\)\|\(\!\%\@\)\|\(\!\!\!\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_subtraction.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\%\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./cnacc_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\%\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_cnacc_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\%\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./cnacc_keyword.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\%\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_cnacc_keyword.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\@\&\@\)\|\(\@\&\!\)\|\(\!\%\@\)\|\(\@\@\@\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./gfwlist_addition.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\&\!\)\|\(\@\%\!\)\|\(\!\&\@\)\|\(\!\!\!\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | sort | uniq > "./gfwlist_subtraction.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\&\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./gfwlist_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\*\&\*\)\|\(\*\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_gfwlist_exclusion.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\&\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./gfwlist_keyword.tmp" && cat "./gfwlist2agh_modify.tmp" | grep -v "\#" | grep "\(\!\&\*\)\|\(\!\*\*\)" | tr -d "\!\%\&\(\)\*\@" | grep -E "${lite_domain_regex}" | xargs | sed "s/\ /\|/g" | sort | uniq > "./lite_gfwlist_keyword.tmp" && cat "./cnacc_addition.tmp" | grep -E "${lite_domain_regex}" | sort | uniq > "./lite_cnacc_addition.tmp" && cat "./gfwlist_addition.tmp" | grep -E "${lite_domain_regex}" | sort | uniq > "./lite_gfwlist_addition.tmp" && cat "./cnacc_trusted.tmp" | sed "s/\/114\.114\.114\.114//g;s/server\=\///g" | tr "A-Z" "a-z" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_trust.tmp" && cat "./cnacc_trust.tmp" | grep -E "${lite_domain_regex}" | sort | uniq > "./lite_cnacc_trust.tmp" && cat "./cnacc_domain.tmp" | sed "s/domain\://g;s/full\://g" | tr "A-Z" "a-z" | grep -E "${domain_regex}" | sort | uniq > "./cnacc_checklist.tmp" && cat "./gfwlist_base64.tmp" "./gfwlist_domain.tmp" | sed "s/domain\://g;s/full\://g;s/http\:\/\///g;s/https\:\/\///g" | tr -d "|" | tr "A-Z" "a-z" | grep -E "${domain_regex}" | sort | uniq > "./gfwlist_checklist.tmp" && cat "./cnacc_checklist.tmp" | rev | cut -d "." -f 1,2 | rev | sort | uniq > "./lite_cnacc_checklist.tmp" && cat "./gfwlist_checklist.tmp" | rev | cut -d "." -f 1,2 | rev | sort | uniq > "./lite_gfwlist_checklist.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_checklist.tmp" "./gfwlist_checklist.tmp" > "./gfwlist_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./gfwlist_checklist.tmp" "./cnacc_checklist.tmp" | grep -Ev "(\.($(cat './cnacc_exclusion.tmp'))$)|(^$(cat './cnacc_exclusion.tmp')$)|($(cat './cnacc_keyword.tmp'))" > "./cnacc_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./lite_cnacc_checklist.tmp" "./lite_gfwlist_checklist.tmp" > "./lite_gfwlist_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./lite_gfwlist_checklist.tmp" "./lite_cnacc_checklist.tmp" | grep -Ev "(\.($(cat './lite_cnacc_exclusion.tmp'))$)|(^$(cat './lite_cnacc_exclusion.tmp')$)|($(cat './lite_cnacc_keyword.tmp'))" > "./lite_cnacc_raw.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_trust.tmp" "./gfwlist_raw.tmp" | grep -Ev "(\.($(cat './gfwlist_exclusion.tmp'))$)|(^$(cat './gfwlist_exclusion.tmp')$)|($(cat './gfwlist_keyword.tmp'))" > "./gfwlist_raw_new.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_trust.tmp" "./lite_gfwlist_raw.tmp" | grep -Ev "(\.($(cat './lite_gfwlist_exclusion.tmp'))$)|(^$(cat './lite_gfwlist_exclusion.tmp')$)|($(cat './lite_gfwlist_keyword.tmp'))" > "./lite_gfwlist_raw_new.tmp" && cat "./cnacc_raw.tmp" "./lite_cnacc_raw.tmp" "./cnacc_addition.tmp" "./lite_cnacc_addition.tmp" "./cnacc_trust.tmp" "./lite_cnacc_trust.tmp" | sort | uniq > "./cnacc_added.tmp" && cat "./gfwlist_raw_new.tmp" "./lite_gfwlist_raw_new.tmp" "./gfwlist_addition.tmp" "./lite_gfwlist_addition.tmp" | sort | uniq > "./gfwlist_added.tmp" && cat "./lite_cnacc_raw.tmp" "./lite_cnacc_addition.tmp" "./lite_cnacc_trust.tmp" | sort | uniq > "./lite_cnacc_added.tmp" && cat "./lite_gfwlist_raw_new.tmp" "./lite_gfwlist_addition.tmp" | sort | uniq > "./lite_gfwlist_added.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_subtraction.tmp" "./cnacc_added.tmp" > "./cnacc_data.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./gfwlist_subtraction.tmp" "./gfwlist_added.tmp" > "./gfwlist_data.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./cnacc_subtraction.tmp" "./lite_cnacc_added.tmp" > "./lite_cnacc_data.tmp" && awk 'NR == FNR { tmp[$0] = 1 } NR > FNR { if ( tmp[$0] != 1 ) print }' "./gfwlist_subtraction.tmp" "./lite_gfwlist_added.tmp" > "./lite_gfwlist_data.tmp" && cat "./cnacc_data.tmp" "./lite_cnacc_data.tmp" | sort | uniq | awk "{ print $2 }")) + gfwlist_data=($(cat "./gfwlist_data.tmp" "./lite_gfwlist_data.tmp" | sort | uniq | awk "{ print $2 }")) + lite_cnacc_data=($(cat "./lite_cnacc_data.tmp" | sort | uniq | awk "{ print $2 }")) + lite_gfwlist_data=($(cat "./lite_gfwlist_data.tmp" | sort | uniq | awk "{ print $2 }")) +} +# Generate Rules +function GenerateRules() { + function FileName() { + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "whiteblack" ]; then + generate_temp="black" + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "blackwhite" ]; then + generate_temp="white" + else + generate_temp="debug" + fi + if [ "${software_name}" == "adguardhome" ] || [ "${software_name}" == "adguardhome_new" ] || [ "${software_name}" == "domain" ]; then + file_extension="txt" + elif [ "${software_name}" == "bind9" ] || [ "${software_name}" == "dnsmasq" ] || [ "${software_name}" == "smartdns" ] || [ "${software_name}" == "unbound" ]; then + file_extension="conf" + else + file_extension="dev" + fi + if [ ! -d "../gfwlist2${software_name}" ]; then + mkdir "../gfwlist2${software_name}" + fi + file_name="${generate_temp}list_${generate_mode}.${file_extension}" + file_path="../gfwlist2${software_name}/${file_name}" + } + function GenerateDefaultUpstream() { + case ${software_name} in + adguardhome) + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "blackwhite" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "whiteblack" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + fi + else + if [ "${generate_file}" == "black" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + fi + fi + ;; + adguardhome_new) + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "blackwhite" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "whiteblack" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + fi + else + if [ "${generate_file}" == "black" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + fi + fi + ;; + *) + exit 1 + ;; + esac + } + case ${software_name} in + adguardhome) + domestic_dns=( + # "https://dns.alidns.com:443/dns-query" + # "https://dns.ipv6dns.com:443/dns-query" + # "https://doh.360.cn:443/dns-query" + "https://doh.pub:443/dns-query" + # "tls://dns.alidns.com:853" + # "tls://dns.ipv6dns.com:853" + # "tls://dot.360.cn:853" + # "tls://dot.pub:853" + ) + foreign_dns=( + # "https://dns.google:443/dns-query" + "https://dns.opendns.com:443/dns-query" + # "https://dns11.quad9.net:443/dns-query" + # "https://dns64.dns.google:443/dns-query" + # "tls://dns.google:853" + # "tls://dns.opendns.com:853" + # "tls://dns11.quad9.net:853" + # "tls://dns64.dns.google:853" + ) + function GenerateRulesHeader() { + echo -n "[/" >> "${file_path}" + } + function GenerateRulesBody() { + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "full_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for cnacc_data_task in "${!cnacc_data[@]}"; do + echo -n "${cnacc_data[$cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo -n "${gfwlist_data[$gfwlist_data_task]}/" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ] || [ "${generate_mode}" == "lite_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo -n "${lite_cnacc_data[$lite_cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo -n "${lite_gfwlist_data[$lite_gfwlist_data_task]}/" >> "${file_path}" + done + fi + fi + } + function GenerateRulesFooter() { + if [ "${dns_mode}" == "default" ]; then + echo -e "]#" >> "${file_path}" + elif [ "${dns_mode}" == "domestic" ]; then + echo -e "]${domestic_dns[domestic_dns_task]}" >> "${file_path}" + elif [ "${dns_mode}" == "foreign" ]; then + echo -e "]${foreign_dns[foreign_dns_task]}" >> "${file_path}" + fi + } + function GenerateRulesProcess() { + GenerateRulesHeader + GenerateRulesBody + GenerateRulesFooter + } + if [ "${dns_mode}" == "default" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + elif [ "${dns_mode}" == "domestic" ]; then + FileName && GenerateDefaultUpstream && for domestic_dns_task in "${!domestic_dns[@]}"; do + GenerateRulesProcess + done + elif [ "${dns_mode}" == "foreign" ]; then + FileName && GenerateDefaultUpstream && for foreign_dns_task in "${!foreign_dns[@]}"; do + GenerateRulesProcess + done + fi + ;; + adguardhome_new) + domestic_dns=( + # "https://dns.alidns.com:443/dns-query" + # "https://dns.ipv6dns.com:443/dns-query" + # "https://doh.360.cn:443/dns-query" + "https://doh.pub:443/dns-query" + "tls://dns.alidns.com:853" + # "tls://dns.ipv6dns.com:853" + # "tls://dot.360.cn:853" + # "tls://dot.pub:853" + ) + foreign_dns=( + # "https://dns.google:443/dns-query" + "https://dns.opendns.com:443/dns-query" + # "https://dns11.quad9.net:443/dns-query" + # "https://dns64.dns.google:443/dns-query" + "tls://dns.google:853" + # "tls://dns.opendns.com:853" + # "tls://dns11.quad9.net:853" + # "tls://dns64.dns.google:853" + ) + function GenerateRulesHeader() { + echo -n "[/" >> "${file_path}" + } + function GenerateRulesBody() { + if [ "${generate_mode}" == "full" ] || [ "${generate_mode}" == "full_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for cnacc_data_task in "${!cnacc_data[@]}"; do + echo -n "${cnacc_data[$cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo -n "${gfwlist_data[$gfwlist_data_task]}/" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ] || [ "${generate_mode}" == "lite_combine" ]; then + if [ "${generate_file}" == "black" ] || [ "${generate_file}" == "blackwhite" ]; then + for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo -n "${lite_cnacc_data[$lite_cnacc_data_task]}/" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ] || [ "${generate_file}" == "whiteblack" ]; then + for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo -n "${lite_gfwlist_data[$lite_gfwlist_data_task]}/" >> "${file_path}" + done + fi + fi + } + function GenerateRulesFooter() { + if [ "${dns_mode}" == "default" ]; then + echo -e "]#" >> "${file_path}" + elif [ "${dns_mode}" == "domestic" ]; then + echo -e "]${domestic_dns[*]}" >> "${file_path}" + elif [ "${dns_mode}" == "foreign" ]; then + echo -e "]${foreign_dns[*]}" >> "${file_path}" + fi + } + function GenerateRulesProcess() { + GenerateRulesHeader + GenerateRulesBody + GenerateRulesFooter + } + if [ "${dns_mode}" == "default" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + elif [ "${dns_mode}" == "domestic" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + elif [ "${dns_mode}" == "foreign" ]; then + FileName && GenerateDefaultUpstream && GenerateRulesProcess + fi + ;; + bind9) + domestic_dns=( + "223.5.5.5 port 53" + ) + foreign_dns=( + "8.8.8.8 port 53" + ) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo -n "zone \"${gfwlist_data[$gfwlist_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo -n "${foreign_dns[$foreign_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + echo -n "zone \"${cnacc_data[$cnacc_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo -n "${domestic_dns[$domestic_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo -n "zone \"${lite_gfwlist_data[$lite_gfwlist_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo -n "${foreign_dns[$foreign_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo -n "zone \"${lite_cnacc_data[$lite_cnacc_data_task]}.\" {type forward; forwarders { " >> "${file_path}" + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo -n "${domestic_dns[$domestic_dns_task]}; " >> "${file_path}" + done + echo "}; };" >> "${file_path}" + done + fi + fi + ;; + dnsmasq) + domestic_dns=( + "223.5.5.5#53" + ) + foreign_dns=( + "8.8.8.8#53" + ) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "server=/${gfwlist_data[$gfwlist_data_task]}/${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "server=/${cnacc_data[$cnacc_data_task]}/${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo "server=/${lite_gfwlist_data[$lite_gfwlist_data_task]}/${foreign_dns[$foreign_dns_task]}" >> "${file_path}" + done + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo "server=/${lite_cnacc_data[$lite_cnacc_data_task]}/${domestic_dns[$domestic_dns_task]}" >> "${file_path}" + done + done + fi + fi + ;; + domain) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo "${gfwlist_data[$gfwlist_data_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + echo "${cnacc_data[$cnacc_data_task]}" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo "${lite_gfwlist_data[$lite_gfwlist_data_task]}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo "${lite_cnacc_data[$lite_cnacc_data_task]}" >> "${file_path}" + done + fi + fi + ;; + smartdns) + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + echo "nameserver /${gfwlist_data[$gfwlist_data_task]}/${foreign_group:-foreign}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + echo "nameserver /${cnacc_data[$cnacc_data_task]}/${domestic_group:-domestic}" >> "${file_path}" + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + echo "nameserver /${lite_gfwlist_data[$lite_gfwlist_data_task]}/${foreign_group:-foreign}" >> "${file_path}" + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + echo "nameserver /${lite_cnacc_data[$lite_cnacc_data_task]}/${domestic_group:-domestic}" >> "${file_path}" + done + fi + fi + ;; + unbound) + domestic_dns=( + "223.5.5.5@853#dns.alidns.com" + ) + foreign_dns=( + "8.8.8.8@853#dns.google" + ) + forward_ssl_tls_upstream="yes" + function GenerateRulesHeader() { + echo "forward-zone:" >> "${file_path}" + } + function GenerateRulesFooter() { + if [ "${dns_mode}" == "domestic" ]; then + for domestic_dns_task in "${!domestic_dns[@]}"; do + echo " forward-addr: \"${domestic_dns[$domestic_dns_task]}\"" >> "${file_path}" + done + elif [ "${dns_mode}" == "foreign" ]; then + for foreign_dns_task in "${!foreign_dns[@]}"; do + echo " forward-addr: \"${foreign_dns[$foreign_dns_task]}\"" >> "${file_path}" + done + fi + echo " forward-first: \"yes\"" >> "${file_path}" + echo " forward-no-cache: \"yes\"" >> "${file_path}" + echo " forward-ssl-upstream: \"${forward_ssl_tls_upstream}\"" >> "${file_path}" + echo " forward-tls-upstream: \"${forward_ssl_tls_upstream}\"" >> "${file_path}" + } + if [ "${generate_mode}" == "full" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for gfwlist_data_task in "${!gfwlist_data[@]}"; do + GenerateRulesHeader && echo " name: \"${gfwlist_data[$gfwlist_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + elif [ "${generate_file}" == "white" ]; then + FileName && for cnacc_data_task in "${!cnacc_data[@]}"; do + GenerateRulesHeader && echo " name: \"${cnacc_data[$cnacc_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + fi + elif [ "${generate_mode}" == "lite" ]; then + if [ "${generate_file}" == "black" ]; then + FileName && for lite_gfwlist_data_task in "${!lite_gfwlist_data[@]}"; do + GenerateRulesHeader && echo " name: \"${lite_gfwlist_data[$lite_gfwlist_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + elif [ "${generate_file}" == "white" ]; then + FileName && for lite_cnacc_data_task in "${!lite_cnacc_data[@]}"; do + GenerateRulesHeader && echo " name: \"${lite_cnacc_data[$lite_cnacc_data_task]}.\"" >> "${file_path}" && GenerateRulesFooter + done + fi + fi + ;; + *) + exit 1 + esac +} +# Output Data +function OutputData() { + ## AdGuard Home + software_name="adguardhome" && generate_file="black" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome" && generate_file="black" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome" && generate_file="white" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome" && generate_file="white" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome" && generate_file="blackwhite" && generate_mode="full_combine" && dns_mode="domestic" && GenerateRules + software_name="adguardhome" && generate_file="blackwhite" && generate_mode="lite_combine" && dns_mode="domestic" && GenerateRules + software_name="adguardhome" && generate_file="whiteblack" && generate_mode="full_combine" && dns_mode="foreign" && GenerateRules + software_name="adguardhome" && generate_file="whiteblack" && generate_mode="lite_combine" && dns_mode="foreign" && GenerateRules + software_name="adguardhome" && generate_file="blackwhite" && generate_mode="full" && dns_mode="domestic" && GenerateRules + software_name="adguardhome" && generate_file="blackwhite" && generate_mode="lite" && dns_mode="domestic" && GenerateRules + software_name="adguardhome" && generate_file="whiteblack" && generate_mode="full" && dns_mode="foreign" && GenerateRules + software_name="adguardhome" && generate_file="whiteblack" && generate_mode="lite" && dns_mode="foreign" && GenerateRules + ## AdGuard Home (New) + software_name="adguardhome_new" && generate_file="black" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome_new" && generate_file="black" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome_new" && generate_file="white" && generate_mode="full_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome_new" && generate_file="white" && generate_mode="lite_combine" && dns_mode="default" && GenerateRules + software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="full_combine" && dns_mode="domestic" && GenerateRules + software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="lite_combine" && dns_mode="domestic" && GenerateRules + software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="full_combine" && dns_mode="foreign" && GenerateRules + software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="lite_combine" && dns_mode="foreign" && GenerateRules + software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="full" && dns_mode="domestic" && GenerateRules + software_name="adguardhome_new" && generate_file="blackwhite" && generate_mode="lite" && dns_mode="domestic" && GenerateRules + software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="full" && dns_mode="foreign" && GenerateRules + software_name="adguardhome_new" && generate_file="whiteblack" && generate_mode="lite" && dns_mode="foreign" && GenerateRules + ## Bind9 + software_name="bind9" && generate_file="black" && generate_mode="full" && GenerateRules + software_name="bind9" && generate_file="black" && generate_mode="lite" && GenerateRules + software_name="bind9" && generate_file="white" && generate_mode="full" && GenerateRules + software_name="bind9" && generate_file="white" && generate_mode="lite" && GenerateRules + ## DNSMasq + software_name="dnsmasq" && generate_file="black" && generate_mode="full" && GenerateRules + software_name="dnsmasq" && generate_file="black" && generate_mode="lite" && GenerateRules + software_name="dnsmasq" && generate_file="white" && generate_mode="full" && GenerateRules + software_name="dnsmasq" && generate_file="white" && generate_mode="lite" && GenerateRules + ## Domain + software_name="domain" && generate_file="black" && generate_mode="full" && GenerateRules + software_name="domain" && generate_file="black" && generate_mode="lite" && GenerateRules + software_name="domain" && generate_file="white" && generate_mode="full" && GenerateRules + software_name="domain" && generate_file="white" && generate_mode="lite" && GenerateRules + ## SmartDNS + software_name="smartdns" && generate_file="black" && generate_mode="full" && foreign_group="foreign" && GenerateRules + software_name="smartdns" && generate_file="black" && generate_mode="lite" && foreign_group="foreign" && GenerateRules + software_name="smartdns" && generate_file="white" && generate_mode="full" && domestic_group="domestic" && GenerateRules + software_name="smartdns" && generate_file="white" && generate_mode="lite" && domestic_group="domestic" && GenerateRules + ## Unbound + software_name="unbound" && generate_file="black" && generate_mode="full" && dns_mode="foreign" && GenerateRules + software_name="unbound" && generate_file="black" && generate_mode="lite" && dns_mode="foreign" && GenerateRules + software_name="unbound" && generate_file="white" && generate_mode="full" && dns_mode="domestic" && GenerateRules + software_name="unbound" && generate_file="white" && generate_mode="lite" && dns_mode="domestic" && GenerateRules + cd .. && rm -rf ./Temp + exit 0 +} + +## Process +# Call GetData +GetData +# Call AnalyseData +AnalyseData +# Call OutputData +OutputData diff --git a/.github/workflows/Update.yml b/.github/workflows/Update.yml new file mode 100644 index 0000000..1c1bb6b --- /dev/null +++ b/.github/workflows/Update.yml @@ -0,0 +1,39 @@ +name: Update + +on: + push: + schedule: + - cron: 0,30 * * * * + +env: + TZ: Asia/Shanghai + +jobs: + Update: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: GetTime + id: date + run: echo "::set-output name=date::$(date +'%Y-%m-%d %H:%M:%S CST')" + + - name: Update + run: | + wget https://raw.githubusercontent.com/hezhijie0327/GFWList2AGH/source/release.sh -O ./.github/source.sh + wget https://raw.githubusercontent.com/hezhijie0327/GFWList2AGH/source/data/data_modify.txt -O ./.github/custom.txt + echo "Auto Update AdGuardHome-ByPass in ${{ steps.date.outputs.date }}" > README.md + + - name: Clean + run: | + git config --local user.email "github-actions[bot]@users.noreply.github.com" + git config --local user.name "github-actions[bot]" + git checkout --orphan latest_branch + git add -A + git commit -am "${{ steps.date.outputs.date }}" + git branch -D Files + git branch -m Files + + - name: Push + run: git push -f origin Files diff --git a/README.md b/README.md new file mode 100644 index 0000000..d86097e --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +Auto Update AdGuardHome-ByPass in 2024-07-07 02:17:03 CST