From a893569eb34f630a8405ade60a9dfc5d77bf25b8 Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Tue, 18 May 2021 20:01:22 +0800 Subject: [PATCH] feat: cleardns --- Dockerfile | 17 +++++++++++++++++ init.sh | 8 ++++++++ overture/config.yml | 35 +++++++++++++++++++++++++++++++++++ overture/hosts | 1 + overture/loopback.txt | 1 + overture/update.sh | 8 ++++++++ smartdns/config.conf | 8 ++++++++ smartdns/load.sh | 26 ++++++++++++++++++++++++++ tools.sh | 26 ++++++++++++++++++++++++++ 9 files changed, 130 insertions(+) create mode 100644 Dockerfile create mode 100755 init.sh create mode 100644 overture/config.yml create mode 100644 overture/hosts create mode 100644 overture/loopback.txt create mode 100755 overture/update.sh create mode 100644 smartdns/config.conf create mode 100755 smartdns/load.sh create mode 100755 tools.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..87b0952 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM alpine as tools +COPY . /tmp/cleardns +RUN apk --update add --no-cache curl wget && \ + sh /tmp/cleardns/tools.sh + +FROM alpine +COPY . /tmp/cleardns +COPY --from=tools /tmp/tools/ /usr/bin/ +RUN mv /tmp/cleardns/overture/ /etc/ && \ + mv /tmp/cleardns/smartdns/ /etc/ && \ + mkdir -p /opt/AdGuardHome && \ + mkdir -p /etc/smartdns/expose && \ + mkdir /etc/cleardns && \ + mv /tmp/cleardns/init.sh / && \ + rm -rf /tmp/cleardns && \ + sed -i '$i\0\t0\t*\t*\t*\t/etc/overture/update.sh' /var/spool/cron/crontabs/root +CMD ["sh","/init.sh"] diff --git a/init.sh b/init.sh new file mode 100755 index 0000000..6d8ff86 --- /dev/null +++ b/init.sh @@ -0,0 +1,8 @@ +[ ! -s "/etc/cleardns/custom.sh" ] && touch /etc/cleardns/custom.sh +sh /etc/cleardns/custom.sh +sh /etc/smartdns/load.sh +sh /etc/overture/update.sh +/usr/sbin/crond +smartdns -c /etc/smartdns/config.conf +overture -c /etc/overture/config.yml > /dev/null 2>&1 & +/usr/bin/AdGuardHome -w /opt/AdGuardHome diff --git a/overture/config.yml b/overture/config.yml new file mode 100644 index 0000000..d11412b --- /dev/null +++ b/overture/config.yml @@ -0,0 +1,35 @@ +bindAddress: :5353 +primaryDNS: + - name: Domestic + address: 127.0.0.1:4053 + protocol: udp + socks5Address: + timeout: 6 + ednsClientSubnet: + policy: disable + externalIP: + noCookie: true +alternativeDNS: + - name: Foreign + address: 127.0.0.1:6053 + protocol: udp + socks5Address: + timeout: 8 + ednsClientSubnet: + policy: disable + externalIP: + noCookie: true +onlyPrimaryDNS: false +ipv6UseAlternativeDNS: false +alternativeDNSConcurrent: false +whenPrimaryDNSAnswerNoneUse: alternativeDNS +ipNetworkFile: + primary: /etc/overture/china_ip_list.txt + alternative: /etc/overture/loopback.txt +domainFile: + primary: /etc/overture/chinalist.txt + alternative: /etc/overture/gfwlist.txt + matcher: suffix-tree +hostsFile: + hostsFile: /etc/overture/hosts + finder: full-map diff --git a/overture/hosts b/overture/hosts new file mode 100644 index 0000000..75721cd --- /dev/null +++ b/overture/hosts @@ -0,0 +1 @@ +127.0.0.1 localhost diff --git a/overture/loopback.txt b/overture/loopback.txt new file mode 100644 index 0000000..5a36518 --- /dev/null +++ b/overture/loopback.txt @@ -0,0 +1 @@ +127.0.0.0/8 diff --git a/overture/update.sh b/overture/update.sh new file mode 100755 index 0000000..4b9457d --- /dev/null +++ b/overture/update.sh @@ -0,0 +1,8 @@ +rm -f /etc/overture/chinalist.txt +rm -f /etc/overture/gfwlist.txt +rm -f /etc/overture/china_ip_list.txt +wget -P /etc/overture https://res.343.re/Share/chinalist/chinalist.txt +wget -P /etc/overture https://res.343.re/Share/gfwlist/gfwlist.txt +wget -P /etc/overture https://raw.fastgit.org/17mon/china_ip_list/master/china_ip_list.txt +ps -ef | grep overture | grep -v grep | awk '{print $1}' | xargs kill -9 +overture -c /etc/overture/config.yml > /dev/null 2>&1 & diff --git a/smartdns/config.conf b/smartdns/config.conf new file mode 100644 index 0000000..785842e --- /dev/null +++ b/smartdns/config.conf @@ -0,0 +1,8 @@ +bind :4053 +bind-tcp :4053 +bind :6053 -group foreign +bind-tcp :6053 -group foreign +log-level info +cache-size 65535 +log-size 32MB +log-file /etc/smartdns/expose/smartdns.log diff --git a/smartdns/load.sh b/smartdns/load.sh new file mode 100755 index 0000000..da7e883 --- /dev/null +++ b/smartdns/load.sh @@ -0,0 +1,26 @@ +load_domestic(){ +cat>/etc/smartdns/expose/domestic.conf</etc/smartdns/expose/foreign.conf<> /etc/smartdns/config.conf +while read -r raw +do + echo "$raw -group foreign -exclude-default-group" >> /etc/smartdns/config.conf +done < /etc/smartdns/expose/foreign.conf diff --git a/tools.sh b/tools.sh new file mode 100755 index 0000000..89f6ae0 --- /dev/null +++ b/tools.sh @@ -0,0 +1,26 @@ +get_github_latest_version() { + VERSION=$(curl --silent "https://api.github.com/repos/$1/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'); +} + +TARGET_DIR="/tmp/tools" +mkdir -p $TARGET_DIR + +get_github_latest_version "AdguardTeam/AdGuardHome" +wget -P /tmp/tools "https://hub.fastgit.org/AdguardTeam/AdGuardHome/releases/download/$VERSION/AdGuardHome_linux_arm64.tar.gz" +get_github_latest_version "shawn1m/overture" +wget -P /tmp/tools "https://hub.fastgit.org/shawn1m/overture/releases/download/$VERSION/overture-linux-arm64.zip" +get_github_latest_version "pymumu/smartdns" +wget -P /tmp/tools "https://hub.fastgit.org/pymumu/smartdns/releases/download/$VERSION/smartdns-aarch64" + +mkdir $TARGET_DIR/AdGuard +tar xf $TARGET_DIR/AdGuardHome_linux_arm64.tar.gz -C $TARGET_DIR/AdGuard +unzip $TARGET_DIR/overture-linux-arm64.zip -d $TARGET_DIR/overture +mv $TARGET_DIR/AdGuard/AdGuardHome/AdGuardHome $TARGET_DIR/AdGuardHome +mv $TARGET_DIR/overture/overture-linux-arm64 $TARGET_DIR/overture-linux-arm64 +rm -rf $TARGET_DIR/AdGuard +rm -rf $TARGET_DIR/overture +mv $TARGET_DIR/overture-linux-arm64 $TARGET_DIR/overture +mv $TARGET_DIR/smartdns-aarch64 $TARGET_DIR/smartdns +chmod +x $TARGET_DIR/smartdns +rm -f $TARGET_DIR/AdGuardHome_linux_arm64.tar.gz +rm -f $TARGET_DIR/overture-linux-arm64.zip