summaryrefslogtreecommitdiff
path: root/save-time.in
blob: dd634b86e7e55c0889744c2807f1c22394f4c97b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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