2014-01-29 13:17:03 +00:00
|
|
|
#!/bin/sh /etc/rc.common
|
|
|
|
# Copyright (C) 2013-2014 OpenWrt.org
|
|
|
|
|
|
|
|
START=00
|
2016-02-08 08:25:53 +00:00
|
|
|
STOP=90
|
|
|
|
|
|
|
|
RTC_DEV=/dev/rtc0
|
|
|
|
HWCLOCK=/sbin/hwclock
|
2014-01-29 13:17:03 +00:00
|
|
|
|
|
|
|
boot() {
|
2020-09-14 09:19:49 +00:00
|
|
|
hwclock_load
|
|
|
|
local maxtime="$(find_max_time)"
|
2014-01-29 13:17:03 +00:00
|
|
|
local curtime="$(date +%s)"
|
2020-09-14 09:19:49 +00:00
|
|
|
if [ $curtime -lt $maxtime ]; then
|
|
|
|
date -s @$maxtime
|
|
|
|
hwclock_save
|
|
|
|
fi
|
2014-01-29 13:17:03 +00:00
|
|
|
}
|
|
|
|
|
2016-02-08 08:25:53 +00:00
|
|
|
start() {
|
2020-09-14 09:19:49 +00:00
|
|
|
hwclock_load
|
2016-02-08 08:25:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
stop() {
|
2020-09-14 09:19:49 +00:00
|
|
|
hwclock_save
|
|
|
|
}
|
|
|
|
|
|
|
|
hwclock_load() {
|
|
|
|
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
|
|
|
|
}
|
|
|
|
|
|
|
|
hwclock_save(){
|
2016-10-31 10:50:09 +00:00
|
|
|
[ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
|
2016-02-08 08:25:53 +00:00
|
|
|
logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
|
|
|
|
}
|
2016-05-05 11:34:49 +00:00
|
|
|
|
2020-09-14 09:19:49 +00:00
|
|
|
find_max_time() {
|
2016-05-05 11:34:49 +00:00
|
|
|
local file newest
|
|
|
|
|
2016-06-16 09:50:36 +00:00
|
|
|
for file in $( find /etc -type f ) ; do
|
2016-05-19 15:57:19 +00:00
|
|
|
[ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file
|
2016-05-05 11:34:49 +00:00
|
|
|
done
|
|
|
|
[ "$newest" ] && date -r "$newest" +%s
|
|
|
|
}
|