Browse Source

update: replace smartdns as dnsproxy, multi-architecture support

dev
dnomd343 4 years ago
parent
commit
14c428a2a8
  1. 21
      Dockerfile
  2. 81
      asset.sh
  3. 30
      init.sh
  4. 8
      overture/config.yml
  5. 14
      overture/update.sh
  6. 8
      smartdns/base.conf
  7. 27
      smartdns/load.sh
  8. 26
      tools.sh

21
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"]

81
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

30
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

8
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

14
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 &

8
smartdns/base.conf

@ -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

27
smartdns/load.sh

@ -1,27 +0,0 @@
load_domestic(){
cat>/etc/smartdns/expose/domestic.conf<<EOF
server 223.5.5.5
server 223.6.6.6
server 119.29.29.29
server 119.28.28.28
server 114.114.114.114
server 114.114.115.115
EOF
}
load_foreign(){
cat>/etc/smartdns/expose/foreign.conf<<EOF
server-tls 223.5.5.5:853
server-https https://doh.pub/dns-query
EOF
}
mkdir -p /etc/smartdns/expose/
[ ! -s "/etc/smartdns/expose/domestic.conf" ] && load_domestic
[ ! -s "/etc/smartdns/expose/foreign.conf" ] && load_foreign
cat /etc/smartdns/base.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

26
tools.sh

@ -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
Loading…
Cancel
Save