]>
Commit | Line | Data |
---|---|---|
5af29fb3 MT |
1 | #!/bin/bash |
2 | ||
3 | ntpconf=/etc/ntp.conf | |
4 | ntpstep=/etc/ntp/step-tickers | |
5 | ||
6 | [ "$EUID" != "0" ] && exit 4 | |
7 | [ -x /usr/sbin/ntpdate ] || exit 5 | |
8 | [ -f /etc/sysconfig/ntpdate ] || exit 6 | |
9 | . /etc/sysconfig/ntpdate | |
10 | ||
11 | [ -f $ntpstep ] && tickers=$(sed 's/#.*//' $ntpstep) || tickers= | |
12 | ||
13 | if ! echo "$tickers" | grep -qi '[a-z0-9]' && [ -f $ntpconf ]; then | |
14 | # the step-tickers file doesn't specify a server, | |
15 | # use servers from ntp.conf instead | |
16 | tickers=$(awk '$1=="peer"||$1=="server"{print $2}' $ntpconf | \ | |
17 | grep -Ev '127\.127\.[0-9]+\.[0-9]+') | |
18 | fi | |
19 | ||
20 | if ! echo "$tickers" | grep -qi '[a-z0-9]'; then | |
21 | echo "NTP server not specified in $ntpstep or $ntpconf" | |
22 | exit 6 | |
23 | fi | |
24 | ||
25 | [ -z "$RETRIES" ] && RETRIES=2 | |
26 | retry=0 | |
27 | while true; do | |
28 | /usr/sbin/ntpdate -U ntp -s -b $OPTIONS $tickers &> /dev/null | |
29 | RETVAL=$? | |
30 | [ $RETVAL -eq 0 ] || [ $retry -ge "$RETRIES" ] && break | |
31 | sleep $[10 * (1 << $retry)] | |
32 | retry=$[$retry + 1] | |
33 | done | |
34 | ||
35 | [ $RETVAL -eq 0 ] && [ "$SYNC_HWCLOCK" = "yes" ] && /sbin/hwclock --systohc | |
36 | exit $RETVAL |