diff --git a/Dockerfile b/Dockerfile index ce745e0..f6390e9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -FROM alpine:3.15 +FROM alpine:3.15 as build COPY . /tmp/ClearDNS ENV OVERTURE_VERSION="v1.8" ENV DNSPROXY_VERSION="v0.41.3" @@ -30,16 +30,23 @@ mv ./AdGuardHome /tmp/release/ && \ cd /tmp/release/ && \ strip * && upx -9 * -# -#FROM alpine as asset -#COPY ./asset.sh / -#RUN apk --update add --no-cache curl wget && \ -# sh /asset.sh -# -#FROM alpine -#COPY ["./overture/", "./init.sh", "/etc/overture/"] -#COPY --from=asset /tmp/asset/ /usr/bin/ -#RUN mv /etc/overture/init.sh / && \ -# mkdir -p /etc/cleardns && \ -# sed -i '$i\0\t4\t*\t*\t*\t/etc/overture/update.sh' /var/spool/cron/crontabs/root -#CMD ["sh","/init.sh"] +FROM alpine:3.15 as asset +COPY . /tmp/ClearDNS +COPY --from=build /tmp/release /tmp/release +RUN \ +wget https://res.dnomd343.top/Share/gfwlist/gfwlist.txt && \ +wget https://res.dnomd343.top/Share/chinalist/chinalist.txt && \ +wget https://res.dnomd343.top/Share/chinalist/china_ip.txt && \ +tar czf asset.tar.gz gfwlist.txt chinalist.txt china_ip.txt && \ +mkdir -p /tmp/asset/etc/ && mkdir -p /tmp/asset/usr/ && \ +cp -r /tmp/ClearDNS/overture/ /tmp/asset/etc/ && \ +mv asset.tar.gz /tmp/asset/etc/overture/ && \ +mv /tmp/release/ /tmp/asset/usr/bin/ && \ +mv /tmp/ClearDNS/load.sh /tmp/asset/usr/bin/load + +FROM alpine:3.15 +COPY --from=asset /tmp/asset / +RUN apk add --no-cache ca-certificates glib && \ +echo -e "0\t4\t*\t*\t*\t/etc/overture/update.sh" > /var/spool/cron/crontabs/root +ENTRYPOINT ['cleardns'] +CMD ['--debug'] diff --git a/init.sh b/init.sh deleted file mode 100755 index 6baed57..0000000 --- a/init.sh +++ /dev/null @@ -1,32 +0,0 @@ -[ -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 - -cat /etc/cleardns/upstream/domestic.conf | sed 's/^[ \t]*//g' | sed 's/[ \t]*$//g' | tr -s '\n' | sed '/^#/d' | sed '/^\/\//d' > /etc/cleardns/upstream/domestic -cat /etc/cleardns/upstream/foreign.conf | sed 's/^[ \t]*//g' | sed 's/[ \t]*$//g' | tr -s '\n' | sed '/^#/d' | sed '/^\/\//d' > /etc/cleardns/upstream/foreign - -cmd="dnsproxy -p 4053" -while read -r raw -do - cmd="$cmd -u $raw" -done < /etc/cleardns/upstream/domestic -eval "$cmd --cache --cache-size=4194304 --all-servers > /dev/null 2>&1 &" - -cmd="dnsproxy -p 6053" -while read -r raw -do - cmd="$cmd -u $raw" -done < /etc/cleardns/upstream/foreign -eval "$cmd --cache --cache-size=4194304 --all-servers > /dev/null 2>&1 &" - -rm -f /etc/cleardns/upstream/domestic -rm -f /etc/cleardns/upstream/foreign - -/etc/overture/update.sh -/usr/sbin/crond -/usr/bin/AdGuardHome -p 80 -w /etc/cleardns/AdGuardHome --no-check-update diff --git a/load.sh b/load.sh new file mode 100755 index 0000000..bdb0a9e --- /dev/null +++ b/load.sh @@ -0,0 +1,42 @@ +#!/bin/sh +mkdir -p /etc/cleardns/asset/ +mkdir -p /etc/cleardns/AdGuardHome/ + +cleardns_dir="/etc/cleardns" +overture_dir="/etc/overture" +cd $overture_dir && tar xf asset.tar +[ ! -f "$cleardns_dir/gfwlist.txt" ] && cp "$overture_dir/gfwlist.txt" "$cleardns_dir/gfwlist.txt" +[ ! -f "$cleardns_dir/chinalist.txt" ] && cp "$overture_dir/chinalist.txt" "$cleardns_dir/chinalist.txt" +[ ! -f "$cleardns_dir/china_ip.txt" ] && cp "$overture_dir/china_ip.txt" "$cleardns_dir/china_ip.txt" + +upstream_file="/etc/cleardns/upstream.json" +if [ ! -f "$upstream_file" ]; then +cat > $upstream_file << EOF +{ + "domestic": { + "bootstrap": "223.5.5.5", + "primary": [ + "tls://dns.alidns.com", + "https://doh.pub/dns-query" + ], + "fallback": [ + "223.5.5.5", + "119.29.29.29" + ] + }, + "foreign": { + "bootstrap": "8.8.8.8", + "primary": [ + "tls://dns.google", + "https://dns.cloudflare.com/dns-query" + ], + "fallback": [ + "1.1.1.1", + "8.8.8.8" + ] + } +} +EOF +fi + +/etc/overture/update.sh& diff --git a/overture/update.sh b/overture/update.sh index 1b3052d..7a96f49 100755 --- a/overture/update.sh +++ b/overture/update.sh @@ -1,3 +1,4 @@ +#!/bin/sh ASSET_DIR="/etc/cleardns/asset" [ -f "$ASSET_DIR/no_auto_update" ] && exit diff --git a/src/process.c b/src/process.c index f0fac89..a36b0ab 100644 --- a/src/process.c +++ b/src/process.c @@ -127,7 +127,7 @@ void get_sub_exit() { // catch child process exit perror("[ClearDNS] Waitpid error"); server_exit(EXIT_WAIT_ERROR); } else if (ret) { // process exit - fprintf(stderr, "[ClearDNS] Catch subprocess detach or exit. (pid = %d)\n", ret); + fprintf(stderr, "[ClearDNS] Catch subprocess exit. (pid = %d)\n", ret); return; } fprintf(stderr, "[ClearDNS] Subprocess not found.\n"); // get SIGCHLD signal but not exited subprocess found