mediatek: backport PWM drivers
[openwrt/openwrt.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 hwclock_load
12 local maxtime="$(find_max_time)"
13 local curtime="$(date +%s)"
14 if [ $curtime -lt $maxtime ]; then
15 date -s @$maxtime
16 hwclock_save
17 fi
18 }
19
20 start() {
21 hwclock_load
22 }
23
24 stop() {
25 hwclock_save
26 }
27
28 hwclock_load() {
29 [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
30 }
31
32 hwclock_save(){
33 [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
34 logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
35 }
36
37 find_max_time() {
38 local file newest
39
40 for file in $( find /etc -type f ) ; do
41 [ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file
42 done
43 [ "$newest" ] && date -r "$newest" +%s
44 }