ab946f6518f6f6eb373313a897ca47c9682d5cca
[openwrt/staging/hauke.git] / package / base-files / files / etc / init.d / sysfixtime
1 #!/bin/sh /etc/rc.common
2 # Copyright (C) 2013-2014 OpenWrt.org
3
4 START=00
5 STOP=90
6
7 RTC_DEV=/dev/rtc0
8 HWCLOCK=/sbin/hwclock
9
10 boot() {
11 start && exit 0
12
13 local curtime="$(date +%s)"
14 local maxtime="$(find /etc -type f -exec date -r {} +%s \; | sort -nr | head -n1)"
15 [ $curtime -lt $maxtime ] && date -s @$maxtime
16 }
17
18 start() {
19 [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -f $RTC_DEV
20 }
21
22 stop() {
23 [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -f $RTC_DEV && \
24 logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
25 }