aboutsummaryrefslogtreecommitdiff
blob: f2f0d24a18cfe2f5dea1b2a9bd361ab4840fc794 (plain)
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
# $Id$

##
# based on vdrshutdown-acpi.pl
# by Thomas Koch <tom@linvdr.org>
##

# Author:
#  Matthias Schwarzott <zzam at gmx dot de>
#
# Parameter:
#  $1 : Time to be up and running as unix-timestamp
#

RTC_ALARM="/sys/class/rtc/rtc0/wakealarm"

die() {
	echo "ERROR: $@" 1>&2
	exit 1
}

if [ ! -w "${RTC_ALARM}" ]; then
	die "Can not access rtc-clock."
fi

test $# -ge 1 || die "Wrong Parameter Count"
Next="${1}"

# clear old time
echo 0 > "${RTC_ALARM}"

if [ "${Next}" -eq 0 ]; then
	# already disabled, we are done
	exit 0
fi

# abort if recording less then 10min in future
now=$(date +%s)
[ "${Next}" -lt "$(($now+600))" ] && die "wakeup time too near, alarm not set"

# boot 5min (=300s) before recording
timestamp=$(($Next-300))

# maybe this needs to be adjusted if bios time is not in UTC
echo "${timestamp}" > "${RTC_ALARM}"

exit 0