1
0

sysfixtime 662 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/sh /etc/rc.common
  2. # Copyright (C) 2013-2014 OpenWrt.org
  3. START=00
  4. STOP=90
  5. RTC_DEV=/dev/rtc0
  6. HWCLOCK=/sbin/hwclock
  7. boot() {
  8. start && exit 0
  9. local maxtime="$(maxtime)"
  10. local curtime="$(date +%s)"
  11. [ $curtime -lt $maxtime ] && date -s @$maxtime
  12. }
  13. start() {
  14. [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -s -u -f $RTC_DEV
  15. }
  16. stop() {
  17. [ -e "$RTC_DEV" ] && [ -e "$HWCLOCK" ] && $HWCLOCK -w -u -f $RTC_DEV && \
  18. logger -t sysfixtime "saved '$(date)' to $RTC_DEV"
  19. }
  20. maxtime() {
  21. local file newest
  22. for file in $( find /etc -type f ) ; do
  23. [ -z "$newest" -o "$newest" -ot "$file" ] && newest=$file
  24. done
  25. [ "$newest" ] && date -r "$newest" +%s
  26. }