3 # Trivial script to load/save current contents of the kernel clock
4 # from/to a file. Helpful as a *bootstrap* clock on machines where
5 # there isn't a useful RTC driver (e.g. on development boards). Using
6 # NTP is still recommended on these machines to get to real time sync
7 # once more of the system is up and running.
9 # Copyright 2012 Steve McIntyre <93sam@debian.org>
11 # License: GPLv2, see COPYING
13 if [ "$FILE"x = ""x ] ; then
14 FILE=/etc/fake-hwclock.data
18 if [ "$COMMAND"x = ""x ] ; then
23 if [ "$2"x = "force"x ] ; then
29 date -u '+%Y-%m-%d %H:%M:%S' > $FILE
32 if [ -e $FILE ] ; then
34 SAVED_SEC=$(date -u -d "$SAVED" '+%s')
35 NOW_SEC=$(date -u '+%s')
36 if $FORCE || [ $NOW_SEC -le $SAVED_SEC ] ; then
39 echo "Current system time: $(date -u '+%Y-%m-%d %H:%M:%S')"
40 echo "fake-hwclock saved clock information is in the past: $SAVED"
41 echo "To set system time to this saved clock anyway, use \"force\""
44 echo "Unable to read saved clock information: $FILE does not exist"
48 echo $0: Unknown command $COMMAND