|  | 
| 7 | 7 | 
 | 
| 8 | 8 | readonly DNSMASQ_ADDRESS=127.52.52.52 | 
| 9 | 9 | 
 | 
|  | 10 | +declare hostname | 
|  | 11 | +declare -a addresses=() | 
|  | 12 | +declare host_record= | 
|  | 13 | + | 
| 10 | 14 | bashio::log.info "Starting dnsmasq..." | 
| 11 | 15 | 
 | 
| 12 |  | -# This is a dummy DNS to suppress tailscaled warnings about not configured upstream on each DNS query | 
| 13 |  | -# It answers REFUSED for everything | 
|  | 16 | +# Resolve login_server | 
|  | 17 | +if bashio::config.has_value "login_server"; then | 
|  | 18 | +  # We have to be able to resolve this address | 
|  | 19 | +  if ! hostname=$(awk -F[/:] '{print $4}' <<<$(bashio::config "login_server")) || \ | 
|  | 20 | +    ! bashio::var.has_value "${hostname}" | 
|  | 21 | +  then | 
|  | 22 | +    bashio::log.error "Determining host name from '$(bashio::config "login_server")' has failed" | 
|  | 23 | +    bashio::exit.nok | 
|  | 24 | +  fi | 
|  | 25 | +  if ! readarray -t addresses < <(dig ${hostname} A ${hostname} AAAA +short) || \ | 
|  | 26 | +    (( 0 == ${#addresses[@]} )) | 
|  | 27 | +  then | 
|  | 28 | +    bashio::log.error "Resolving '${hostname}' has failed" | 
|  | 29 | +    bashio::exit.nok | 
|  | 30 | +  fi | 
|  | 31 | +else | 
|  | 32 | +  # This is a best effort, if we fail, let tailscale use it's derp servers as fallback bootstrap DNS servers | 
|  | 33 | +  hostname="controlplane.tailscale.com" | 
|  | 34 | +  readarray -t addresses < <(dig ${hostname} A ${hostname} AAAA +short) || true | 
|  | 35 | +fi | 
|  | 36 | +if (( 0 < ${#addresses[@]} )); then | 
|  | 37 | +  host_record="--host-record=${hostname}$(printf ",%s" "${addresses[@]}"),0" | 
|  | 38 | +fi | 
|  | 39 | + | 
|  | 40 | +# This is a dummy DNS to provide bootstrap DNS resolution for the login_server option, otherwise answers REFUSED for everything | 
|  | 41 | +# It is also required to suppress tailscaled warnings about not configured upstream on each DNS query | 
| 14 | 42 | # It must run on port 53 to be able to specify it in a resolv.conf | 
| 15 | 43 | echo "nameserver ${DNSMASQ_ADDRESS}" > /etc/resolv.dnsmasq.conf | 
| 16 |  | -exec dnsmasq --no-hosts --no-resolv --keep-in-foreground --log-facility='-' --listen-address=${DNSMASQ_ADDRESS} --port=53 --bind-interfaces | 
|  | 44 | +exec dnsmasq --no-hosts --no-resolv --keep-in-foreground --log-facility='-' --listen-address=${DNSMASQ_ADDRESS} --port=53 --bind-interfaces ${host_record} | 
0 commit comments