#! /bin/sh # # Written by Craig Huff # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2 of the License, or # (at your option) any later version. # ## $2 is the time in seconds since the epoch started that Myth wants ## to wake up the system in preparation for the next recording event. # # Constants: # Seconds system is expected to take from wakeup alarm until ready to do processing # (5 minutes x 60 seconds = 300) offset=300 # ## Define where this script should log it's activities. # logfile=/var/log/mythtv/alarm.log # ## Insert blank lines in logfile to separate alarm setting events # echo "" >> ${logfile} echo "" >> ${logfile} # ## What time was passed by Myth as the wake up time for the next recording? # mythtime=`date -u -d "1970-01-01 ${2} seconds" --rfc-3339="seconds" | cut -c1-19` echo "Mythtime=${mythtime}" >> ${logfile} # ## Get (from the fill log) the time zap2it requested the next update be made ## and put it in a /bin/date compatible format. # nexttime=`cat /var/log/mythtv/mythfilldatabase.log.1 /var/log/mythtv/mythfilldatabase.log | grep NextSuggestedTime | tail -1 | awk '{print $NF}' | sed -e 's/T/ /'` echo "Filltime=${nexttime}" >> ${logfile} # ## To ease time comparisons and time adjustments, get the value of nexttime in ## seconds since the start of the epoch (1/1/1970 @ 00:00:00 am). # epochtime=`date -u -d "${nexttime}" +%s` # ## Since the time supplied by zap2it is the time to update the database, we need ## to wake up the system prior to that and allow time to get up to speed, so ## subtract ${advance} seconds from epochtime. # epochtime=`expr ${epochtime} - ${offset}` # ## Convert epochtime into alarm time format # filltime=`date -u -d "1970-01-01 ${epochtime} seconds" --rfc-3339="seconds" | cut -c1-19` # ## Which is sooner? # if [ ${2} -lt ${epochtime} ]; then waketime=${mythtime} else waketime=${filltime} fi # ## There is a finite chance that the selected wakeup time is EXACTLY ## midnight UTC. ## In /etc/init.d/halt, we have made the assumption that when ## /proc/acpi/alarm is set for this specific time of day that we DO NOT want to ## wake up when that time arrives. ## Therefore, test waketime to see if the time of day it contains is ## midnight UTC and if it is, tweak the time to be five seconds earlier ## (00:00:00 -> 23:59:55). # if [ "`echo ${waketime} | awk '{print $NF}'`" == "00:00:00" ]; then epochtime=`date -u -d "${waketime}" +%s` offsettime=`expr ${epochtime} - 5` waketime=`date -u -d "1970-01-01 ${offsettime} seconds" --rfc-3339="seconds" | cut -c1-19` fi localtime=`date -d "${waketime} UTC" +"%a, %b %d, %Y at %r %Z"` # ## Now set the ACPI alarm and log the details on this wakeup setting event # echo "${waketime}" > /proc/acpi/alarm echo "On `date +"%a, %b %d, %Y"` at `date +"%r %Z"`," >> ${logfile} echo " alarm set to ${waketime} `date -u +%Z`" >> ${logfile} echo " which is ${localtime} local time." >> ${logfile}