| 1 |
#!/bin/bash |
| 2 |
# |
| 3 |
# $Id: set_timer 908 2008-11-23 13:29:13Z tiber $ |
| 4 |
# |
| 5 |
# This script was made by Hans-Hermann Redenius ([email protected]) |
| 6 |
# |
| 7 |
# This file is for bioses nvram-wakeup couldn't handle, because there is |
| 8 |
# no possibility to change the Wake on RTC time in the nvram |
| 9 |
# The wake up time must be set to 23:59:59 the day must be set to 31 |
| 10 |
# if your board supports a month setting for the wakeup, set it to July |
| 11 |
# |
| 12 |
# The System should not update the hardware clock in the shutdown process. |
| 13 |
# In Debian Woody set HWCLOCKACCESS=no in /etc/default/rcS |
| 14 |
# |
| 15 |
# in vdrshutdown replace: |
| 16 |
# |
| 17 |
# $NVRAMCMD -ls $1 |
| 18 |
# |
| 19 |
# by |
| 20 |
# |
| 21 |
# $PATH_TO_SET_TIMER/set_timer $1 $2 |
| 22 |
# |
| 23 |
# and add the following line to your start script before vdr is started |
| 24 |
# |
| 25 |
# $PATH_TO_SET_TIMER/set_timer |
| 26 |
# |
| 27 |
# The time command from nvram-wakeup is needed (set the path bwlow) |
| 28 |
# |
| 29 |
# Thanks to Sergei Haller for nvram-wakeup and the time and ideas to develop |
| 30 |
# this script |
| 31 |
|
| 32 |
|
| 33 |
# programs to use: |
| 34 |
HWCLOCK=/sbin/hwclock |
| 35 |
TIME=/usr/local/sbin/time |
| 36 |
|
| 37 |
# files to use: |
| 38 |
TIME_DIFF=/video/time_diff |
| 39 |
|
| 40 |
|
| 41 |
if [ ! -x $HWCLOCK ] ; then |
| 42 |
echo "$0 needs hwclock" |
| 43 |
exit 1 |
| 44 |
fi |
| 45 |
|
| 46 |
if [ ! -x $TIME ] ; then |
| 47 |
echo "$0 needs the time command from nvram-wakeup" |
| 48 |
exit 1 |
| 49 |
fi |
| 50 |
|
| 51 |
# current time |
| 52 |
cur_time=`date +%s` |
| 53 |
|
| 54 |
# how many seconds before the next event the system should be booted |
| 55 |
boot_time=300 |
| 56 |
|
| 57 |
# if a time_diff file exists the clock is set to the wakeup time and |
| 58 |
# must be fixed before any further action |
| 59 |
# |
| 60 |
if [ -f $TIME_DIFF ] ; then |
| 61 |
|
| 62 |
# the difference stored |
| 63 |
time_diff=`cat $TIME_DIFF` |
| 64 |
|
| 65 |
# add the difference to the curent time and change it in the date format |
| 66 |
set_time=$(( $cur_time + $time_diff )) |
| 67 |
set_date=`$TIME $set_time | grep "^(local" | cut -f2- -d')' ` |
| 68 |
|
| 69 |
# restore the correct time and if all is right remove the $TIME_DIFF file |
| 70 |
# because there is no longer a difference |
| 71 |
$HWCLOCK --set --date "$set_date" && $HWCLOCK --hctosys && rm $TIME_DIFF |
| 72 |
fi |
| 73 |
|
| 74 |
# if there is a parameter given, it is assumed the system schould boot |
| 75 |
# after $boot_time seconds |
| 76 |
if [ -n "$2" ] ; then |
| 77 |
|
| 78 |
if [ $1 -eq 0 ] ; then # no timer present |
| 79 |
sleep_time=$(( 61 * 24 * 60 * 60 - 1 + $boot_time )) # 61 days - 1s |
| 80 |
# + boot_time |
| 81 |
else # timer present |
| 82 |
if [ $2 -ge $(( $boot_time + 30 )) ] ; then # need 30 seconds for shutdown |
| 83 |
sleep_time=$2 |
| 84 |
else |
| 85 |
sleep_time=$(( $boot_time + 30 )) |
| 86 |
# or exit 1 so vdrshutdown would do nothing |
| 87 |
# because the next timer is less than boot_time + 30 seconds in the future |
| 88 |
# or currently recording |
| 89 |
# I suggest a short timeout, because the user really asked for it |
| 90 |
fi |
| 91 |
fi |
| 92 |
|
| 93 |
# wakeup time |
| 94 |
wake_time=996616799 # date -d "Jul 31 23:59:59 2001" +%s |
| 95 |
|
| 96 |
# calculate the right time and the time difference |
| 97 |
set_time=$(( $wake_time - $sleep_time + $boot_time )) |
| 98 |
time_diff=$(( $cur_time - $set_time )) |
| 99 |
|
| 100 |
# convert time to date format |
| 101 |
set_date=`$TIME $set_time | grep "^(local" | cut -f2- -d')' ` |
| 102 |
|
| 103 |
# set date and if it is correct write the time_diff file |
| 104 |
# date --set="$set_date" && \ # add this if a script updates the hwclock |
| 105 |
$HWCLOCK --set --date "$set_date" && echo $time_diff > $TIME_DIFF |
| 106 |
fi |