blob: 9977020b8b28d9862f74512e9a4723431016b00b [file] [log] [blame]
#!/bin/sh
ANTIROLLBACK=/config/ar_clock
TIME_FILE=/tmp/time.synced
case "$1" in
start)
cp /etc/ntpd.conf.default /tmp/ntpd.conf
echo "UTC" > /tmp/TZ
if [ -s $ANTIROLLBACK ]; then
toolbox date +%s -s "$(cat $ANTIROLLBACK)"
fi
toolbox dmesg | grep ' T: ' | (
lasttime=0
while IFS='[] ' read level uptime service version \
timestamp humandate humantime ntpsync junk; do
if [ "$service" = "T:" ] && [ "$ntpsync" = "ntp=1" ]; then
lasttime=$timestamp
fi
done
if [ "$lasttime" -gt 0 ]; then
echo "Approximate time carried from last boot: $lasttime"
toolbox date +%s -s $lasttime
fi
#TODO(irinams): create the TIME_FILE only when we have a way to approximate
# how much time was spent during reboot to add it to to lasttime
#echo >"TIME_FILE"
)
(
wait-until-created /tmp/ntp.synced
echo : >"$TIME_FILE"
) &
babysit 60 antirollback -u bin -p $ANTIROLLBACK 2>&1 | logos rollback &
;;
stop)
pkillwait -x antirollback
rm -f "$TIME_FILE"
;;
restart|reload)
$0 stop; $0 start
;;
*)
echo "Usage: $0 {start|stop|restart}"
exit 1
esac