#!/bin/sh # Script to set the self power-on feature under mythtv. # The script sets the alarm to either the next time to record # or the next time mythfilldatabase runs in the evening. # The script expects $1 to be the time in seconds from # January 1, 1970, of the next recording or 0 if # no next recording exists. LOG=/var/log/mythtv/nextwakeup.log # Time of next recording in seconds from January 1, 1970 NextRecording=$1 if [ $NextRecording -gt 0 ] then echo "`date "+%c"`-MythTV reports the next recording time is `date -u -d "1970-01-01 $NextRecording secs" "+%c"`." >> $LOG else echo "`date "+%c"`-MythTV reports no recording is scheduled." >> $LOG fi #Set the Time Zone TZ=$(date +%z) # Set Current Date CurrDate=$(date +%s) # Find next mythfilldatabase instance if [ $CurrDate -lt $(date -d "02:55:00 $TZ" "+%s") ] then NextMythfilldatabase=$(date -d "02:55:00 $TZ" "+%s") else NextMythfilldatabase=$(date -d "+ 1 day 02:55:00 $TZ" "+%s") fi # echo "The next mythfilldatabase is $NextMythfilldatabase." # Set set wakeup to the NextRecording or NextMythfilldatabase if [ $NextRecording -gt 0 ] && [ $NextMythfilldatabase -gt $NextRecording ] then Wakeup=$NextRecording else Wakeup=$NextMythfilldatabase fi # mythshutdown --setwakeup `date -d "1970-01-01 $Wakeup secs" "+%FT%H:%M:%S"` echo 0 > /sys/class/rtc/rtc0/wakealarm echo $Wakeup > /sys/class/rtc/rtc0/wakealarm RETVAL=$? if [ $RETVAL ] then echo "`date "+%c"`-Next wakeup time set to `date -u -d "1970-01-01 $Wakeup secs" "+%c"`." >> $LOG touch /var/run/alarmset else echo "`date "+%c"`-Failed to set next wakeup time to `date -u -d "1970-01-01 $Wakeup secs" "+%c"`." >> $LOG fi exit $RETVAL