#!/bin/sh -e
### BEGIN INIT INFO
# Provides:          timerest
# Required-Start:    udev
# Required-Stop: 
# Default-Start:     S
# Default-Stop:      0 6
# X-Interactive:     true
# X-Start-Before:    checkroot
# Required-Stop:     $local_fs
# Short-Description: Restore time from timestamp file
### END INIT INFO

PATH="/sbin:/bin:/usr/bin"

. /lib/lsb/init-functions

case "$1" in
    start)
    log_daemon_msg "Setting time from timestamp" "timerest"
    date -s @$(stat -c %Y /etc/timerest)
    log_end_msg $?
    ;;
    stop)
    log_daemon_msg "Storing time" "timerest"
    touch /etc/timerest && sync
    log_end_msg $?
    ;;

    restart)
    $0 stop
    $0 start
    ;;

    *)
    echo "Usage: /etc/init.d/timerest {start|stop|restart}"
    exit 1
    ;;
esac
