Guest User

Untitled

a guest
May 17th, 2017
1,252
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.15 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # set ACPI Wakeup alarm
  4. # safe_margin - minutes to start up system before the earliest timer
  5. # script does not check if recording is in progress
  6. #
  7. #
  8.  
  9. echo 1 > /timer
  10.  
  11. # bootup system 60 sec. before timer
  12. safe_margin=720
  13.  
  14. # modyfy if different location for tvheadend dvr/log path
  15. cd /mnt/cache/.appdata/tvheadend-stable/dvr/log
  16.  
  17. ######################
  18.  
  19. start_date=0
  20. stop_date=0
  21.  
  22. current_date=`date +%s`
  23.  
  24. for i in $( ls ); do
  25. tmp_start=`cat $i | grep '"start":' | cut -f 2 -d " " | cut -f 1 -d ","`
  26. tmp_stop=`cat $i | grep '"stop":' | cut -f 2 -d " " | cut -f 1 -d ","`
  27.  
  28. # check for outdated timer
  29. if [ $((tmp_stop)) -gt $((current_date)) -a $((tmp_start)) -gt $((current_date)) ]; then
  30.  
  31. # take lower value (tmp_start or start_date)
  32. if [ $((start_date)) -eq 0 -o $((tmp_start)) -lt $((start_date)) ]; then
  33. start_date=$tmp_start
  34. stop_date=$tmp_stop
  35. fi
  36. fi
  37. done
  38.  
  39. wake_date=$((start_date-safe_margin))
  40.  
  41. echo $start_date >> /timer
  42. echo $wake_date >> /timer
  43.  
  44. # set up waleup alarm
  45. if [ $((start_date)) -ne 0 ]; then
  46. echo 2 >> /timer
  47. echo 0 > /sys/class/rtc/rtc0/wakealarm
  48. echo $wake_date > /sys/class/rtc/rtc0/wakealarm
  49. fi
Add Comment
Please, Sign In to add comment