Skip to content

Commit

Permalink
all: finish scripts, imp names
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Mar 23, 2023
1 parent 4db0d0e commit a094a44
Show file tree
Hide file tree
Showing 8 changed files with 96 additions and 97 deletions.
12 changes: 12 additions & 0 deletions docker/dns-bind.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
BEGIN { num = 0; prev_line = 0; }
/^[^[:space:]]/ { is_dns = /^dns:/; }
/^[[:space:]]+bind_hosts:/ { is_dns_bh = 1; if (is_dns_bh && is_dns) prev_line = FNR; }
/^[[:space:]]+- .+/ {
if ((FNR - prev_line) == 1 && is_dns_bh) { addrs[num++] = $2; prev_line = FNR; }
}
/^[[:space:]]+port:/ { if (is_dns) port = $2; }
END {
for (i = 0; i < num; i++) {
if (match(addrs[i], ":")) print "[" addrs[i] "]:" port; else print addrs[i] ":" port;
}
}
55 changes: 0 additions & 55 deletions docker/docker-healthcheck.sh

This file was deleted.

40 changes: 0 additions & 40 deletions docker/get_bind_hosts.awk

This file was deleted.

70 changes: 70 additions & 0 deletions docker/healthcheck.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/sh

# AdGuard Home Docker healthcheck script

# Exit the script if a pipeline fails (-e), prevent accidental filename
# expansion (-f), and consider undefined variables as errors (-u).
set -e -f -u

# Function log is an echo wrapper that writes to stderr if the caller requested
# verbosity level greater than 0. Otherwise, it does nothing.
log() {
# if [ "$VERBOSE" -gt '0' ]
# then
echo "$1" 1>&2
# fi
}

home_dir="/opt/adguardhome"
readonly home_dir

filename="${home_dir}/conf/AdGuardHome.yaml"
readonly filename

if ! [ -f "$filename" ]
then
wget "http://127.0.0.1:3000" -O /dev/null || exit 1

exit 0
fi

# Parse.

help_dir="${home_dir}/scripts"
readonly help_dir

web_host=$(awk -f "${help_dir}/web-bind.awk" "$filename")
readonly web_host

dns_hosts=$(awk -f "${help_dir}/dns-bind.awk" "$filename")
readonly dns_hosts

if [ "$dns_hosts" == '' ]
then
log "No DNS bindings could be retrieved from $filename"

exit 1
fi

# TODO(e.burkov): Deal with 0 port.
first=$(echo $dns_hosts | head -n 1)
case $first
in
(*":0")
log "0 port is not supported"

exit 1
;;
(*)
# Go on.
;;
esac

# Check

wget "http://${web_host}" -O /dev/null || exit 1

echo "$dns_hosts" | while read -r host
do
nslookup -type=a localhost $host || exit 1
done
3 changes: 3 additions & 0 deletions docker/web-bind.awk
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/^bind_host:/ { host = $2 }
/^bind_port:/ { port = $2 }
END { if (match(host, ":")) print "[" host "]:" port; else print host ":" port; }
2 changes: 0 additions & 2 deletions internal/dnsforward/dns64.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ func (s *Server) setupDNS64() {
// valid IPv4. It panics, if there are no configured DNS64 prefixes, because
// synthesis should not be performed unless DNS64 function enabled.
func (s *Server) mapDNS64(ip netip.Addr) (mapped net.IP) {
// Don't mask the address here since it should have already been masked on
// initialization stage.
pref := s.dns64Pref.Masked().Addr().As16()
ipData := ip.As4()

Expand Down
7 changes: 7 additions & 0 deletions scripts/make/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,15 @@ EXPOSE 53/tcp 53/udp 67/udp 68/udp 80/tcp 443/tcp 443/udp 784/udp\

WORKDIR /opt/adguardhome/work

# Install helpers for healthcheck.
COPY --chown=nobody:nogroup\
./${DIST_DIR}/docker/scripts\
/opt/adguardhome/scripts

ENTRYPOINT ["/opt/adguardhome/AdGuardHome"]

HEALTHCHECK --interval=30s --timeout=10s --retries=3 CMD [ "/opt/adguardhome/scripts/healthcheck.sh" ]

CMD [ \
"--no-check-update", \
"-c", "/opt/adguardhome/conf/AdGuardHome.yaml", \
Expand Down
4 changes: 4 additions & 0 deletions scripts/make/build-docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ cp "${dist_dir}/AdGuardHome_linux_arm_7/AdGuardHome/AdGuardHome"\
cp "${dist_dir}/AdGuardHome_linux_ppc64le/AdGuardHome/AdGuardHome"\
"${dist_docker}/AdGuardHome_linux_ppc64le_"

# TODO(e.burkov): !! do better
cp -R "./docker"\
"${dist_docker}/scripts"

# Don't use quotes with $docker_tags and $debug_flags because we want word
# splitting and or an empty space if tags are empty.
$sudo_cmd docker\
Expand Down

0 comments on commit a094a44

Please sign in to comment.