forked from kristjanvalur/soft-hwclock
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsoft-hwclock
49 lines (41 loc) · 957 Bytes
/
soft-hwclock
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/sh
# Get the saved time (or empty) and clock time, in RFC399 format
# This format sorts lexicographically
CLOCKFILE="/opt/soft-hwclock/soft-hwclock.data"
CTIME=$(date +'%Y-%m-%d %H:%M:%S')
FTIME=$(test -f "${CLOCKFILE}" && cat "${CLOCKFILE}")
# if the file time is in the future, use that
setclock() {
if expr "${FTIME}" \> "${CTIME}" ; then
echo "loading saved time ${FTIME} over ${CTIME}"
date --set="${FTIME}"
#date --date="${FTIME}"
#echo would set clock to $FTIME
else
echo "ignoring saved time ${FTIME} over ${CTIME}"
fi
}
# if current time is greater than what is in the file, save it
saveclock() {
if expr "${CTIME}" \> "${FTIME}" ; then
echo "saving time ${CTIME} over ${FTIME}"
echo "${CTIME}" > "${CLOCKFILE}"
else
echo "not saving time ${CTIME} over ${FTIME}"
fi
}
case "$1" in
load)
setclock
;;
save)
saveclock
;;
tick)
saveclock
;;
*)
echo "Usage: $0 {load|save|tick}"
exit 1
;;
esac