Created
January 7, 2019 19:24
-
-
Save bjoerns1983/c3be5c9cd825cfa50614462cf003e631 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# set ACPI Wakeup alarm | |
# safe_margin - minutes to start up system before the earliest timer | |
# script does not check if recording is in progress | |
# | |
# | |
echo 1 > /timer | |
# bootup system 60 sec. before timer | |
safe_margin=120 | |
# modyfy if different location for tvheadend dvr/log path | |
cd /mnt/cache/.appdata/tvheadend/dvr/log | |
###################### | |
start_date=0 | |
stop_date=0 | |
current_date=`date +%s` | |
for i in $( ls ); do | |
tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","` | |
tmp_stop=`cat $i | grep '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","` | |
# check for outdated timer | |
if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -gt $((current_date)) ]; then | |
# take lower value (tmp_start or start_date) | |
if [ $((start_date)) -eq 0 -o $((tmp_start)) -lt $((start_date)) ]; then | |
start_date=$tmp_start | |
stop_date=$tmp_stop | |
fi | |
fi | |
done | |
wake_date=$((start_date-safe_margin)) | |
echo $start_date >> /timer | |
echo $wake_date >> /timer | |
# set up waleup alarm | |
if [ $((start_date)) -ne 0 ]; then | |
echo 2 >> /timer | |
echo 0 > /sys/class/rtc/rtc0/wakealarm | |
echo $wake_date > /sys/class/rtc/rtc0/wakealarm | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment