#!/bin/sh
#
# Trivial script to load/save current contents of the kernel clock
# from/to a file. Helpful as a *bootstrap* clock on machines where
# there isn't a useful RTC driver (e.g. on development boards). Using
# NTP is still recommended on these machines to get to real time sync
# once more of the system is up and running.
#
# Copyright 2012 Steve McIntyre <93sam@debian.org>
#
# License: GPLv2, see COPYING

if [ "$FILE"x = ""x ] ; then
    FILE=/etc/fake-hwclock.data
fi

COMMAND=$1
if [ "$COMMAND"x = ""x ] ; then
    COMMAND="save"
fi

case $COMMAND in
    save)
        date -u '+%Y-%m-%d %H:%M:%S' > $FILE;;
    load)
        if [ -e $FILE ] ; then
            date -u -s "`cat $FILE`"
        else
            echo "Unable to read saved clock information: $FILE does not exist"
        fi;;
    *)
        echo $0: Unknown command $COMMAND
        exit 1;;
esac
