| 1 |
# |
| 2 |
# VDR shutdown hook for nvram-wakeup - Tobias Grimm <[email protected]> |
| 3 |
# ---------------------------------- |
| 4 |
# |
| 5 |
# This shutdown hook sets the wakeup time for the next timer using |
| 6 |
# nvram-wakeup. If necessary the shutdown command is modified to |
| 7 |
# use a special shutdown strategy. |
| 8 |
# |
| 9 |
|
| 10 |
NVRAMCMD=/usr/sbin/nvram-wakeup |
| 11 |
|
| 12 |
# read arguments for nvram-wakeup from conf-file |
| 13 |
. /etc/vdr/vdr-nvram-wakeup.conf |
| 14 |
|
| 15 |
# Defaults: |
| 16 |
[ -z "$ENABLED" ] && export ENABLED="no" |
| 17 |
[ -z "$COMMANDLINE" ] && export COMMANDLINE="" |
| 18 |
[ -z "$SPECIALSHUTDOWN" ] && export SPECIALSHUTDOWN="" |
| 19 |
[ -z "$REGULAR_DAYS" ] && export REGULAR_DAYS=0 |
| 20 |
[ -z "$REGULAR_TIME" ] && export REGULAR_TIME=0 |
| 21 |
[ -z "$FORCE_REBOOT" ] && export FORCE_REBOOT="no" |
| 22 |
|
| 23 |
LOG="logger -t vdr-nvram-wakeup" |
| 24 |
|
| 25 |
if [ $ENABLED = "no" ] ; then |
| 26 |
$LOG "nvram-wakeup functionality is disabled" |
| 27 |
exit 0 |
| 28 |
fi |
| 29 |
|
| 30 |
request_reboot() |
| 31 |
{ |
| 32 |
if [ -z "$SPECIALSHUTDOWN" ] ; then |
| 33 |
$LOG "nvram-wakeup: A special shutdown strategy is required but not configured." |
| 34 |
echo "ABORT_MESSAGE=\"no special shutdown configured\"" |
| 35 |
exit 1 |
| 36 |
else |
| 37 |
echo "SHUTDOWNCMD=\"$SPECIALSHUTDOWN\"" |
| 38 |
exit 0 |
| 39 |
fi |
| 40 |
} |
| 41 |
|
| 42 |
# calculate, at what time the machine should be powered on: |
| 43 |
|
| 44 |
TIMER=$1 |
| 45 |
|
| 46 |
if [ $REGULAR_DAYS -gt 0 ]; then |
| 47 |
REGULAR_TIMER=$((`date -d "$REGULAR_TIME" +%s` + $REGULAR_DAYS * 24 * 60 * 60)) |
| 48 |
|
| 49 |
# when no vdr timer is set or vdr timer starts later than regular timer: |
| 50 |
if [ $TIMER -eq 0 ] || [ $TIMER -gt 0 -a $REGULAR_TIMER -lt $TIMER ] ; then |
| 51 |
TIMER=$REGULAR_TIMER |
| 52 |
fi |
| 53 |
fi |
| 54 |
|
| 55 |
# set wakeup time and check nvram-wakeup and check result: |
| 56 |
|
| 57 |
$LOG "$NVRAMCMD -ls $TIMER $COMMANDLINE" |
| 58 |
|
| 59 |
$NVRAMCMD -ls $TIMER $COMMANDLINE |
| 60 |
|
| 61 |
case $? in |
| 62 |
0) # all went ok - new date and time set |
| 63 |
$LOG "nvram-wakeup: everything ok" |
| 64 |
|
| 65 |
if [ $FORCE_REBOOT = "yes" ] ; then |
| 66 |
$LOG "nvram-wakeup: reboot not needed but forced" |
| 67 |
request_reboot |
| 68 |
fi |
| 69 |
|
| 70 |
exit 0 |
| 71 |
;; |
| 72 |
1) # all went ok - new date and time set. |
| 73 |
# |
| 74 |
# *** but we need to reboot. *** |
| 75 |
# |
| 76 |
# for some boards this is needed after every change. |
| 77 |
# |
| 78 |
# for some other boards, we only need this after changing the |
| 79 |
# status flag, i.e. from enabled to disabled or the other way. |
| 80 |
|
| 81 |
|
| 82 |
# For plan A - (Plan A is not supported anymore---see README) |
| 83 |
# |
| 84 |
# For plan B - (don't forget to install the modified kernel image first) |
| 85 |
# |
| 86 |
|
| 87 |
$LOG "nvram-wakeup: everything ok - need to reboot first" |
| 88 |
request_reboot |
| 89 |
|
| 90 |
;; |
| 91 |
*) # something went wrong |
| 92 |
# don't do anything - just exit with status 1 |
| 93 |
|
| 94 |
$LOG "nvram-wakeup: could not set time, shutdown will be aborted" |
| 95 |
echo "ABORT_MESSAGE=\"nvram-wakeup could not set time\"" |
| 96 |
exit 1 |
| 97 |
;; |
| 98 |
esac |