-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
df61741
commit 4db0d0e
Showing
2 changed files
with
95 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
#!/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 | ||
} | ||
|
||
# TODO(e.burkov): Deal with custom configuration file name. | ||
filename='./AdGuardHome.yaml' | ||
readonly filename | ||
|
||
if ! [ -f "$filename" ] | ||
then | ||
log "AdGuard Home is probably not set up yet" | ||
|
||
exit 0 | ||
fi | ||
|
||
hosts=$(awk -f './docker/get_bind_hosts.awk' "$filename") | ||
readonly hosts | ||
|
||
if [ "$hosts" == '' ] | ||
then | ||
log "No hosts could be retrieved from $filename" | ||
|
||
exit 1 | ||
fi | ||
|
||
case "$hosts" | ||
in | ||
("0.0.0.0:"*|"[::]:"*) | ||
# TODO(e.burkov): Deal with unspecified addresses. | ||
log "The unspecified address isn't supported by healthcheck" | ||
|
||
exit 1 | ||
;; | ||
(*) | ||
# Go on. | ||
;; | ||
esac | ||
|
||
echo "$hosts" | while read -r host | ||
do | ||
echo $host | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
BEGIN { | ||
naddrs = 0 | ||
} | ||
bind_subsection { | ||
# Subsection of bind_hosts field lasts as long as there are array elements. | ||
bind_subsection = /[[:space:]+]- /; | ||
if (bind_subsection) { | ||
addr = $2 | ||
if (addr == "0.0.0.0" || addr == "::") { | ||
# Only return the unspecified address if it's set at least once. | ||
addrs[0] = addr; naddrs = 1; | ||
bind_subsection = 0; | ||
} else { | ||
addrs[naddrs++] = addr | ||
} | ||
} | ||
} | ||
dns_subsection && !bind_subsection { | ||
bind_subsection = /[[:space:]+]bind_hosts:/; | ||
if (/^[[:space:]]+port:/) { | ||
port = $2; | ||
}; | ||
next | ||
} | ||
/^[^[:space:]]/ { | ||
dns_subsection = /^dns:/; | ||
next | ||
} | ||
END { | ||
for (i = 0; i < naddrs; i++) { | ||
addr = addrs[i]; | ||
if (match(addr, ":")) { | ||
# It's an IPv6. | ||
print "[" addr "]:" port; | ||
} else { | ||
# It's an IPv4. | ||
print addr ":" port; | ||
} | ||
} | ||
} |