From 14c428a2a8572bfea4f0da5a7a8290e7cd7353df Mon Sep 17 00:00:00 2001 From: dnomd343 Date: Fri, 28 May 2021 22:46:24 +0800 Subject: [PATCH] update: replace smartdns as dnsproxy, multi-architecture support --- Dockerfile | 21 +++++------- asset.sh | 81 +++++++++++++++++++++++++++++++++++++++++++++ init.sh | 30 +++++++++++++---- overture/config.yml | 8 ++--- overture/update.sh | 14 ++++---- smartdns/base.conf | 8 ----- smartdns/load.sh | 27 --------------- tools.sh | 26 --------------- 8 files changed, 124 insertions(+), 91 deletions(-) create mode 100755 asset.sh delete mode 100644 smartdns/base.conf delete mode 100755 smartdns/load.sh delete mode 100755 tools.sh diff --git a/Dockerfile b/Dockerfile index 87b0952..907faa8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,12 @@ -FROM alpine as tools -COPY . /tmp/cleardns +FROM alpine as asset +COPY ./asset.sh / RUN apk --update add --no-cache curl wget && \ - sh /tmp/cleardns/tools.sh + sh /asset.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 +COPY ./init.sh / +COPY ./overture /etc/overture/ +COPY --from=asset /tmp/asset/ /usr/bin/ +RUN mkdir -p /etc/cleardns && \ + sed -i '$i\0\t2\t*\t*\t*\t/etc/overture/update.sh' /var/spool/cron/crontabs/root CMD ["sh","/init.sh"] diff --git a/asset.sh b/asset.sh new file mode 100755 index 0000000..17129a5 --- /dev/null +++ b/asset.sh @@ -0,0 +1,81 @@ +get_github_latest_version() { + VERSION=$(curl --silent "https://api.github.com/repos/$1/releases/latest" | grep '"tag_name":' | sed -E 's/.*"([^"]+)".*/\1/'); +} + +get_architecture() { + case "$(uname -m)" in + 'i386' | 'i686') + MACHINE='i386' + ;; + 'amd64' | 'x86_64') + MACHINE='amd64' + ;; + 'armv7' | 'armv7l') + MACHINE='arm' + ;; + 'armv8' | 'aarch64') + MACHINE='arm64' + ;; + *) + echo "The architecture is not supported." + exit 1 + ;; + esac +} + +ASSET_DIR="/tmp/asset" +PKG_DIR="$ASSET_DIR/pkg" +mkdir -p $PKG_DIR + +get_architecture +case "$MACHINE" in + 'i386') + AGH_PKG_NAME="AdGuardHome_linux_386.tar.gz" + OVERTURE_FILE_NAME="overture-linux-386" + OVERTURE_PKG_NAME="$OVERTURE_FILE_NAME.zip" + DNSPROXY_FOLDER_NAME="linux-386" + DNSPROXY_PKG_PREFIX="dnsproxy-$DNSPROXY_FOLDER_NAME-" + ;; + 'amd64') + AGH_PKG_NAME="AdGuardHome_linux_amd64.tar.gz" + OVERTURE_FILE_NAME="overture-linux-amd64" + OVERTURE_PKG_NAME="$OVERTURE_FILE_NAME.zip" + DNSPROXY_FOLDER_NAME="linux-amd64" + DNSPROXY_PKG_PREFIX="dnsproxy-$DNSPROXY_FOLDER_NAME-" + ;; + 'arm') + AGH_PKG_NAME="AdGuardHome_linux_armv7.tar.gz" + OVERTURE_FILE_NAME="overture-linux-arm" + OVERTURE_PKG_NAME="$OVERTURE_FILE_NAME.zip" + DNSPROXY_FOLDER_NAME="linux-arm6" + DNSPROXY_PKG_PREFIX="dnsproxy-$DNSPROXY_FOLDER_NAME-" + ;; + 'arm64') + AGH_PKG_NAME="AdGuardHome_linux_arm64.tar.gz" + OVERTURE_FILE_NAME="overture-linux-arm64" + OVERTURE_PKG_NAME="$OVERTURE_FILE_NAME.zip" + DNSPROXY_FOLDER_NAME="linux-arm64" + DNSPROXY_PKG_PREFIX="dnsproxy-$DNSPROXY_FOLDER_NAME-" + ;; + *) + exit 1 + ;; +esac + +get_github_latest_version "AdguardTeam/AdGuardHome" +wget -P $PKG_DIR "https://github.com/AdguardTeam/AdGuardHome/releases/download/$VERSION/$AGH_PKG_NAME" +tar xf $PKG_DIR/$AGH_PKG_NAME -C $PKG_DIR +mv $PKG_DIR/AdGuardHome/AdGuardHome $ASSET_DIR/ + +get_github_latest_version "shawn1m/overture" +wget -P $PKG_DIR "https://github.com/shawn1m/overture/releases/download/$VERSION/$OVERTURE_PKG_NAME" +unzip $PKG_DIR/$OVERTURE_PKG_NAME -d $PKG_DIR +mv $PKG_DIR/$OVERTURE_FILE_NAME $ASSET_DIR/overture + +get_github_latest_version "AdguardTeam/dnsproxy" +DNSPROXY_PKG_NAME="$DNSPROXY_PKG_PREFIX$VERSION.tar.gz" +wget -P $PKG_DIR "https://github.com/AdguardTeam/dnsproxy/releases/download/$VERSION/$DNSPROXY_PKG_NAME" +tar xf $PKG_DIR/$DNSPROXY_PKG_NAME -C $PKG_DIR +mv $PKG_DIR/$DNSPROXY_FOLDER_NAME/dnsproxy $ASSET_DIR + +rm -rf $PKG_DIR diff --git a/init.sh b/init.sh index 6d8ff86..392250e 100755 --- a/init.sh +++ b/init.sh @@ -1,8 +1,26 @@ -[ ! -s "/etc/cleardns/custom.sh" ] && touch /etc/cleardns/custom.sh -sh /etc/cleardns/custom.sh -sh /etc/smartdns/load.sh +[ -f "/etc/cleardns/custom.sh" ] && sh /etc/cleardns/custom.sh + +mkdir -p /etc/cleardns/list +mkdir -p /etc/cleardns/upstream +mkdir -p /etc/cleardns/AdGuardHome + +[ ! -s "/etc/cleardns/upstream/domestic.conf" ] && echo -e "223.5.5.5\n119.29.29.29\n114.114.114.114" > /etc/cleardns/upstream/domestic.conf +[ ! -s "/etc/cleardns/upstream/foreign.conf" ] && echo -e "8.8.4.4\n8.8.8.8" > /etc/cleardns/upstream/foreign.conf + +cmd="dnsproxy -p 4053" +while read -r raw +do + cmd="$cmd -u $raw" +done < /etc/cleardns/upstream/domestic.conf +eval "$cmd --cache --all-servers > /dev/null 2>&1 &" + +cmd="dnsproxy -p 6053" +while read -r raw +do + cmd="$cmd -u $raw" +done < /etc/cleardns/upstream/foreign.conf +eval "$cmd --cache --all-servers > /dev/null 2>&1 &" + 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 +/usr/bin/AdGuardHome -p 80 -w /etc/cleardns/AdGuardHome diff --git a/overture/config.yml b/overture/config.yml index e34741d..a1a7a0a 100644 --- a/overture/config.yml +++ b/overture/config.yml @@ -4,7 +4,7 @@ primaryDNS: address: 127.0.0.1:4053 protocol: udp socks5Address: - timeout: 6 + timeout: 4 ednsClientSubnet: policy: disable externalIP: @@ -24,11 +24,11 @@ ipv6UseAlternativeDNS: false alternativeDNSConcurrent: false whenPrimaryDNSAnswerNoneUse: alternativeDNS ipNetworkFile: - primary: /etc/overture/list/china_ip_list.txt + primary: /etc/cleardns/list/china_ip_list.txt alternative: /etc/overture/loopback.txt domainFile: - primary: /etc/overture/list/chinalist.txt - alternative: /etc/overture/list/gfwlist.txt + primary: /etc/cleardns/list/chinalist.txt + alternative: /etc/cleardns/list/gfwlist.txt matcher: suffix-tree hostsFile: hostsFile: /etc/overture/hosts diff --git a/overture/update.sh b/overture/update.sh index a9f621e..3bbb1d9 100755 --- a/overture/update.sh +++ b/overture/update.sh @@ -1,14 +1,14 @@ -OVERTURE_DIR="/etc/overture" -TEMP_DIR="$OVERTURE_DIR/list/temp" -[ -f "$OVERTURE_DIR/list/no_auto_update" ] && exit +LIST_DIR="/etc/cleardns/list" +TEMP_DIR="$LIST_DIR/temp" +[ -f "$LIST_DIR/no_auto_update" ] && exit rm -rf $TEMP_DIR mkdir -p $TEMP_DIR wget -P $TEMP_DIR https://res.343.re/Share/chinalist/chinalist.txt wget -P $TEMP_DIR https://res.343.re/Share/gfwlist/gfwlist.txt wget -P $TEMP_DIR https://raw.fastgit.org/17mon/china_ip_list/master/china_ip_list.txt -[ -s "$TEMP_DIR/chinalist.txt" ] && mv -f $TEMP_DIR/chinalist.txt $OVERTURE_DIR/list/ -[ -s "$TEMP_DIR/gfwlist.txt" ] && mv -f $TEMP_DIR/gfwlist.txt $OVERTURE_DIR/list/ -[ -s "$TEMP_DIR/china_ip_list.txt" ] && mv -f $TEMP_DIR/china_ip_list.txt $OVERTURE_DIR/list/ +[ -s "$TEMP_DIR/chinalist.txt" ] && mv -f $TEMP_DIR/chinalist.txt $LIST_DIR/ +[ -s "$TEMP_DIR/gfwlist.txt" ] && mv -f $TEMP_DIR/gfwlist.txt $LIST_DIR/ +[ -s "$TEMP_DIR/china_ip_list.txt" ] && mv -f $TEMP_DIR/china_ip_list.txt $LIST_DIR/ rm -rf $TEMP_DIR ps -ef | grep overture | grep -v grep | grep -v sh | awk '{print $1}' | xargs kill -9 -overture -c /etc/overture/config.yml > /dev/null 2>&1 & +/usr/bin/overture -c /etc/overture/config.yml > /dev/null 2>&1 & diff --git a/smartdns/base.conf b/smartdns/base.conf deleted file mode 100644 index 785842e..0000000 --- a/smartdns/base.conf +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100755 index 6e135ef..0000000 --- a/smartdns/load.sh +++ /dev/null @@ -1,27 +0,0 @@ -load_domestic(){ -cat>/etc/smartdns/expose/domestic.conf</etc/smartdns/expose/foreign.conf< /etc/smartdns/config.conf -cat /etc/smartdns/expose/domestic.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 deleted file mode 100755 index 89f6ae0..0000000 --- a/tools.sh +++ /dev/null @@ -1,26 +0,0 @@ -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