sysfixtime 764 B

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