Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- #
- # alarmpi-0.3
- #
- # Alarm script for working along with crond, MPD and tty-clock on a Raspberry Pi board plugged in a HDTV through HDMI/CEC.
- # Deps: cec-client, mpd, mpc, tty-clock
- #
- # Rodrigo Abreu <rodrigo@ilostmyself.org>
- #
- TERM=xterm
- export TERM
- PLAYLIST='alarmpi' # Set your playlist for waking up
- ENABLE_OUTPUTS=(2) # Enable output by index # i.e. ENABLE_OUTPUTS=(2 3). Run '$ mpc outputs' to check it out.
- DISABLE_OUTPUTS=(1) # Disable output by index # i.e. DISABLE_OUTPUTS=(1 4). Run '$ mpc outputs' to check it out again.
- TIME=90 # Alarm runtime period (in minutes)
- # Prepare the screen for tty-clock
- echo "on 0" | cec-client -s > /dev/null
- echo -ne '\033[9;0]' > /dev/tty1
- setterm -blank 0 -powerdown 0 > /dev/tty1
- # Take a snapshot of the current outputs
- SNAPSHOT_OUTPUTS=$(mpc outputs | awk '{ print $2 " " $(NF) }')
- # Prepare the current queue for loading the alarmpi playlist and a previous restoration
- mpc save tmp > /dev/null
- mpc clear > /dev/null
- mpc load $PLAYLIST > /dev/null
- # Enable and disable the selected outputs defined at ENABLE_OUTPUTS and DISABLE_OUTPUTS variables
- for output in ${DISABLE_OUTPUTS[@]}
- do
- mpc disable $output > /dev/null
- done
- for output in ${ENABLE_OUTPUTS[@]}
- do
- mpc enable $output > /dev/null
- done
- # Enable repeat
- mpc repeat on > /dev/null
- # Core
- mpc play > /dev/null
- tty-clock -S -c -t -d 3 > /dev/tty1 &
- sleep $[$TIME*60]
- TTY_CLOCK_PID=$(pidof tty-clock)
- kill -9 $TTY_CLOCK_PID > /dev/null
- mpc stop > /dev/null
- clear > /dev/tty1
- # echo "standby 0" | cec-client -s > /dev/null # Turns off the TV. See if this line works isolatedly before to uncomment.
- # Restore the previous audio outputs and queue like it has never been touched
- arr=($(echo $SNAPSHOT_OUTPUTS | tr " " "\n"))
- for (( i = 0 ; i < ${#arr[@]} ; i=$i+2 ))
- do
- mpc ${arr[$i+1]%?} ${arr[$i]} > /dev/null
- done
- mpc clear > /dev/null
- mpc load tmp > /dev/null
- mpc rm tmp > /dev/null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement