Advertisement
rabreu

alarmpi-0.3.sh

Feb 18th, 2014
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.98 KB | None | 0 0
  1. #!/bin/bash
  2. #
  3. # alarmpi-0.3
  4. #
  5. # Alarm script for working along with crond, MPD and tty-clock on a Raspberry Pi board  plugged in a HDTV through HDMI/CEC.
  6. # Deps: cec-client, mpd, mpc, tty-clock
  7. #
  8. # Rodrigo Abreu <rodrigo@ilostmyself.org>
  9. #
  10.  
  11. TERM=xterm
  12. export TERM
  13.  
  14. PLAYLIST='alarmpi'              # Set your playlist for waking up
  15. ENABLE_OUTPUTS=(2)                              # Enable output by index # i.e. ENABLE_OUTPUTS=(2 3). Run '$ mpc outputs' to check it out.
  16. DISABLE_OUTPUTS=(1)             # Disable output by index # i.e. DISABLE_OUTPUTS=(1 4). Run '$ mpc outputs' to check it out again.
  17. TIME=90                     # Alarm runtime period (in minutes)
  18.  
  19. # Prepare the screen for tty-clock
  20. echo "on 0" | cec-client -s > /dev/null
  21. echo -ne '\033[9;0]' > /dev/tty1
  22. setterm -blank 0 -powerdown 0 > /dev/tty1
  23.  
  24. # Take a snapshot of the current outputs
  25. SNAPSHOT_OUTPUTS=$(mpc outputs | awk '{ print $2 " " $(NF) }')
  26.  
  27. # Prepare the current queue for loading the alarmpi playlist and a previous restoration
  28. mpc save tmp > /dev/null
  29. mpc clear > /dev/null
  30. mpc load $PLAYLIST > /dev/null
  31.  
  32. # Enable and disable the selected outputs defined at ENABLE_OUTPUTS and DISABLE_OUTPUTS variables
  33. for output in ${DISABLE_OUTPUTS[@]}
  34. do
  35.     mpc disable $output  > /dev/null
  36. done
  37. for output in ${ENABLE_OUTPUTS[@]}
  38. do
  39.         mpc enable $output  > /dev/null
  40. done
  41.  
  42. # Enable repeat
  43. mpc repeat on > /dev/null
  44.  
  45. # Core
  46. mpc play > /dev/null
  47. tty-clock -S -c -t -d 3 > /dev/tty1 &
  48. sleep $[$TIME*60]
  49. TTY_CLOCK_PID=$(pidof tty-clock)
  50. kill -9 $TTY_CLOCK_PID > /dev/null
  51. mpc stop > /dev/null
  52. clear > /dev/tty1
  53. # echo "standby 0" | cec-client -s > /dev/null  # Turns off the TV. See if this line works isolatedly before to uncomment.
  54.  
  55. # Restore the previous audio outputs and queue like it has never been touched
  56. arr=($(echo $SNAPSHOT_OUTPUTS | tr " " "\n"))
  57. for (( i = 0 ; i < ${#arr[@]} ; i=$i+2 ))
  58. do
  59.         mpc ${arr[$i+1]%?} ${arr[$i]} > /dev/null
  60. done
  61. mpc clear > /dev/null
  62. mpc load tmp > /dev/null
  63. mpc rm tmp > /dev/null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement