diff --git a/board/common/overlay/etc/date.conf b/board/common/overlay/etc/date.conf index b76b9a7400..35f15070e1 100644 --- a/board/common/overlay/etc/date.conf +++ b/board/common/overlay/etc/date.conf @@ -2,4 +2,5 @@ date_timeout=10 date_method=http date_host="google.com" date_interval=900 +date_ntp_server="" diff --git a/board/common/overlay/etc/init.d/S50date b/board/common/overlay/etc/init.d/S50date index 0f25df310e..10e90483c5 100755 --- a/board/common/overlay/etc/init.d/S50date +++ b/board/common/overlay/etc/init.d/S50date @@ -4,6 +4,10 @@ sys_conf="/etc/date.conf" boot_conf="/boot/date.conf" conf="/data/etc/date.conf" +sys_ntp_conf="/etc/ntp.conf" +boot_ntp_conf="/boot/ntp.conf" +ntp_conf="/data/etc/ntp.conf" + if ! [ -f $conf ]; then if [ -f $boot_conf ]; then cp $boot_conf $conf @@ -12,6 +16,14 @@ if ! [ -f $conf ]; then fi fi +if ! [ -f $ntp_conf ]; then + if [ -f $boot_ntp_conf ]; then + cp $boot_ntp_conf $ntp_conf + elif [ -f $sys_ntp_conf ]; then + cp $sys_ntp_conf $ntp_conf + fi +fi + test -f $conf || exit 0 test -n "$os_version" || source /etc/init.d/base @@ -42,7 +54,7 @@ set_current_date_http() { } set_current_date_ntp() { - cat /etc/ntp.conf | grep server | head -n 1 | cut -d ' ' -f 2 | xargs ntpdate -t $date_timeout -s + cat $ntp_conf | grep server | head -n 1 | cut -d ' ' -f 2 | xargs ntpdate -t $date_timeout -s } start_http() { @@ -60,13 +72,24 @@ start_http() { start_ntp() { mkdir -p /var/lib/ntp - + + cat $ntp_conf | grep -v iburst > ${ntp_conf}.tmp + + if [ -n "$date_ntp_server" ]; then + echo "server $date_ntp_server iburst" > $ntp_conf + else + cat $sys_ntp_conf | grep iburst > $ntp_conf + fi + + cat ${ntp_conf}.tmp >> $ntp_conf + rm ${ntp_conf}.tmp + msg_begin "Setting current date using ntp" set_current_date_ntp test $? == 0 && msg_done "$(date)" || msg_fail msg_begin "Starting ntpd" - ntpd -g -c /etc/ntp.conf + ntpd -g -c $ntp_conf test $? == 0 && msg_done || msg_fail }