44 lines
1.3 KiB
Bash
44 lines
1.3 KiB
Bash
#!/bin/sh
|
|
set -e
|
|
|
|
log() {
|
|
# send messages to stderr so Docker logs capture them even if stdout is used by CoreDNS
|
|
echo "[$(date '+%Y-%m-%d %H:%M:%S')] $1" >&2
|
|
}
|
|
|
|
# Attempt to fetch .alt root hints from known sources
|
|
generate_alt_forwards() {
|
|
# try hostnames first
|
|
log "Fetching .alt hints from alt.root-servers.org (may require external DNS)"
|
|
hints=$(curl --connect-timeout 5 --max-time 8 -fsSL https://alt.root-servers.org/hints.txt 2>/dev/null || true)
|
|
if [ -z "$hints" ]; then
|
|
log "hostname fetch failed, trying hard-coded IP fallback"
|
|
hints=$(curl --connect-timeout 5 --max-time 8 -fsSL http://185.121.177.177/hints.txt 2>/dev/null || true)
|
|
fi
|
|
if [ -z "$hints" ]; then
|
|
log "no hints available, leaving placeholder intact"
|
|
return
|
|
fi
|
|
echo "$hints" | awk '{print " forward . " $1 ":53"}'
|
|
}
|
|
|
|
# Replace placeholder in Corefile with actual forwards (or leave empty)
|
|
update_corefile() {
|
|
forwards=$(generate_alt_forwards)
|
|
if [ -n "$forwards" ]; then
|
|
log "updating Corefile alt forwards"
|
|
awk -v fwd="$forwards" '
|
|
/#ALT_FORWARDS/ {
|
|
print fwd; next
|
|
}
|
|
{ print }
|
|
' /Corefile > /Corefile.new && mv /Corefile.new /Corefile
|
|
fi
|
|
}
|
|
|
|
log "running entrypoint"
|
|
update_corefile
|
|
|
|
# Exec CoreDNS with provided arguments
|
|
exec /coredns "$@"
|