Skip to content
ckuethe edited this page Apr 9, 2015 · 6 revisions

The UsbArmory doesn't have a battery-backed real time clock, so it forgets the time at reboot.

Some Unix-like operating systems (eg. NetBSD) are able to approximate the time from the filesystem. Debian-based systems can use fake-hwclock, and here's a way to do that by hand.

Among the additional packages that should be installed are ntpdate and ntp; these can be used to set the clock as soon as network is available, and then maintain time as long as power is available.

#cat > init.d/fstime.sh <<EOF
#!/bin/sh
# fstime.sh	Set and adjust the CMOS clock.
#
# Version:	@(#)fstime.sh  1.00  04-Dec-2014 [email protected]
#

### BEGIN INIT INFO
# Provides:          fstime
# Required-Start:    $local_fs
# Required-Stop:
# Default-Start:     S 1 2 3 4 5
# Default-Stop:      0 6
### END INIT INFO

# We only want to use the system timezone or else we'll get
# potential inconsistency at startup.
unset TZ

fstime()
{
    [ ! -r /etc/default/rcS ] || . /etc/default/rcS
    [ ! -r /etc/default/hwclock ] || . /etc/default/hwclock

    . /lib/lsb/init-functions
    verbose_log_action_msg() { [ "$VERBOSE" = no ] || log_action_msg "$@"; }
    F=/var/lib/fstime

    case "$1" in
	start)
		if [ -f $F ] ; then
			date $(cat $F) 2>&1 >/dev/null
			verbose_log_action_msg "System Clock set to: `date -u`"
		else
			log_warning_msg "Unable to set System Clock"
		fi
	;;
	show)
		if [ -f $F ] ; then
			verbose_log_action_msg "Saved time: `cat $F`"
		else
			log_warning_msg "No saved time"
		fi
	;;
	reload)
		fstime stop
		fstime start
	;;
	stop)
		log_action_msg "Saving the system clock: `date -u`"
		T=$(mktemp ${F}.XXXXXXX)
		date "+%m%d%H%M%Y.%S" > $T
		mv $T $F
	;;
	*)
		log_success_msg "Usage: fstime.sh {start|stop|reload|show}"
		log_success_msg "       start sets kernel clock from filesystem time"
		log_success_msg "       stop and reload set filesytem time from kernel clock"
		return 1
	;;
    esac
}

fstime "$@"

EOF

#chmod 0755 /etc/init.d/fstime
#root@usbarmory:~# ls -l /etc/*/*fstime*
-rwxr-xr-x 1 root root 1489 Jan  1  1970 /etc/init.d/fstime
lrwxrwxrwx 1 root root   16 Jan  1  1970 /etc/rc0.d/K01fstime -> ../init.d/fstime
lrwxrwxrwx 1 root root   16 Jan  1  1970 /etc/rc2.d/S03fstime -> ../init.d/fstime
lrwxrwxrwx 1 root root   16 Jan  1  1970 /etc/rc6.d/K01fstime -> ../init.d/fstime
lrwxrwxrwx 1 root root   16 Jan  1  1970 /etc/rcS.d/S10fstime -> ../init.d/fstime
Clone this wiki locally