Skip to content

Instantly share code, notes, and snippets.

@inC3ASE
Created October 14, 2016 02:03
Show Gist options
  • Save inC3ASE/d3fd35aa81dca47a138e162f6688f1b2 to your computer and use it in GitHub Desktop.
Save inC3ASE/d3fd35aa81dca47a138e162f6688f1b2 to your computer and use it in GitHub Desktop.
libexec
#!/bin/sh
# Cribbed from /usr/libexec/ntpd-wrapper. Will wait for DNS to be available before
# invoking sntp, but does not need to handle starting a server, or any configurability.
# Intended for use in the BaseSystem only.
PATH=/usr/sbin:/usr/bin:/bin
TIMEOUT=30
KEY=State:/Network/Global/DNS
DNS=/var/run/resolv.conf
# sentinel to special case DNS readiness at boot
LOG=/var/run/sntp.log
ipconfig waitall
if [[ ! -f ${LOG} ]]; then
DEADLINE=$((SECONDS+TIMEOUT))
for (( CURTIMEOUT=TIMEOUT; SECONDS < DEADLINE; CURTIMEOUT=DEADLINE-SECONDS )); do
if scutil -w ${KEY} -t ${CURTIMEOUT}; then
if [[ -f ${DNS} ]]; then
break;
fi # else retry false alarms
else
logger -p daemon.err "$0: scutil key ${KEY} not present after ${TIMEOUT} seconds"
break;
fi
done
fi
sntp -s time.apple.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment