Skip to content

Instantly share code, notes, and snippets.

@juzam
Last active August 29, 2015 13:56
Show Gist options
  • Save juzam/9207065 to your computer and use it in GitHub Desktop.
Save juzam/9207065 to your computer and use it in GitHub Desktop.
#!/bin/bash
#
# This starts and stops shairport
#
### BEGIN INIT INFO
# Provides: sonos-airplay
# Required-Start: $network
# Required-Stop:
# Short-Description: Sonos Airplay Bridge
# Description: Sonos Airplay Bridge
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
### END INIT INFO
# Source function library.
. /lib/lsb/init-functions
RETVAL=0
start() {
echo -n "Starting Sonos-Airplay: "
mkfifo /tmp/airplay2sonos
chmod 666 /tmp/airplay2sonos
/bin/su - shairport -c "/usr/local/bin/shairport -d -a Sonos -P /home/shairport/shairport.pid -l /home/shairport/shairport.log -e /home/shairport/shairport.err -B \"echo -e 'play\nlogout'|nc localhost 7070\" -o pipe /tmp/airplay2sonos"&
/bin/su - vlc -c "/usr/bin/vlc -d --pidfile /home/vlc/vlc.pid --logfile /home/vlc/vlc.log -I rc --rc-host localhost:7070 --demux=rawaud --rawaud-channels 2 --rawaud-samplerate 44100 /tmp/airplay2sonos :sout='#gather:transcode{acodec=mp3,ab=256,channels=2,samplerate=44100}:http{mux=raw,dst=:8081}' :sout-keep :repeat"
}
stop() {
echo -n "Shutting down Sonos-Airplay: "
rm -f /tmp/airplay2sonos
kill -9 `cat /home/shairport/shairport.pid`
kill -9 `cat /home/vlc/vlc.pid`
# in case there's more than one vlc running..
killall -9 vlc
}
restart() {
stop
sleep 1
start
}
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status shairport
;;
restart)
restart
;;
*)
echo "Usage: $0 {start|stop|status|restart}"
;;
esac
exit 0
check process sonos-airplay with pidfile /home/vlc/vlc.pid
start program = "/etc/init.d/sonos-airplay start"
stop program = "/etc/init.d/sonos-airplay stop"
if changed pid then restart
if failed host 127.0.0.1 port 5002 then restart
if failed host 127.0.0.1 port 8081 then restart
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment