Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 additions & 2 deletions files/dhcp.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,29 @@ run_dhcp_client() {
# the --nobackground is not used here because when it is used, dhcpcd doesn't honor the --timeout option
# and waits indefinitely for a response. For one shot, we want to timeout after the 30 second default.
/sbin/dhcpcd -f /dhcpcd.conf --allowinterfaces "${al}" -1 || true

# use busybox's ntpd to set the time after getting an IP address; don't fail
echo 'sleep 1 second before calling ntpd' && sleep 1
/usr/sbin/ntpd -n -q -dd -p pool.ntp.org || true
echo "sleep 1 second before calling ntpd; date: '$(date)'" && sleep 1
if ! /usr/sbin/ntpd -n -q -dd -p pool.ntp.org; then
echo "ntpd call failed; setting time manually and retrying"
# set system time to the date of the dhcpd binary file
# this should recover from ntpd failures due to time being too far off
date -s "$(stat -c %y /sbin/dhcpcd | cut -d'.' -f1)" || true
tries=1 # retry up to 5 times
while [ $tries -le 5 ]; do
echo "waiting 1 second before retrying ntpd call; try #$tries ; date is now: '$(date)'"
sleep 1
if /usr/sbin/ntpd -n -q -dd -p pool.ntp.org; then
echo "ntpd retry call succeeded on try #$tries; date is now: '$(date)'"
break
else
echo "ntpd retry call failed on try #$tries"
fi
tries=$((tries + 1))
done
else
echo "ntpd call succeeded; date is now: '$(date)'"
fi
else
/sbin/dhcpcd --nobackground -f /dhcpcd.conf --allowinterfaces "${al}"
fi
Expand Down
Loading