summaryrefslogtreecommitdiff
path: root/save-time.in
diff options
context:
space:
mode:
Diffstat (limited to 'save-time.in')
-rwxr-xr-xsave-time.in22
1 files changed, 22 insertions, 0 deletions
diff --git a/save-time.in b/save-time.in
new file mode 100755
index 0000000..dd634b8
--- /dev/null
+++ b/save-time.in
@@ -0,0 +1,22 @@
+#!/bin/bash
+
+# save-time version #VERSION#
+
+# Save the time upon shutdown for seeding system clock on next boot.
+# This is intended to give roughly correct system time on machines
+# without rtc, but which are powered on most of the time.
+
+case "$1" in
+ 'start')
+ if [ -f '#CACHEDIR#/time' ]; then
+ date -s@"$(cat '#CACHEDIR#/time')"
+ fi
+ ;;
+ 'stop')
+ date +%s > '#CACHEDIR#/time'
+ ;;
+ *)
+ >&2 echo "usage: ${0##*/} (start|stop)"
+ exit 1
+ ;;
+esac