diff options
Diffstat (limited to 'god/streams/streams')
-rwxr-xr-x | god/streams/streams | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/god/streams/streams b/god/streams/streams new file mode 100755 index 00000000..80c654ad --- /dev/null +++ b/god/streams/streams @@ -0,0 +1,131 @@ +#! /bin/bash +set -euf + +stream_file=/tmp/krebs.stream.current + +HERE=$(dirname $(readlink -f $0)) +URLS=`cat $HERE/stream.db` +CURRENT_STREAM="no stream" #will be set when calling `status` +if [ ! `id -u` -eq "0" ]; then + exec sudo "$0" "$@" +fi + +#if [ ! `id -u` -eq "0" ]; then +# echo "we are going sudo..." +# exec sudo "$0" "$@" +#fi + +function start() { + # start the given stream von $1 + REQ=$1 + tmux start-server + if status &>/dev/null ; then + echo "!! Stream already running!" + exit 1 + fi + + if echo "$URLS" | while read URL NAME; do + if [ "$NAME" = "$REQ" ];then + tmux new-session -s streams -n streams -d " + while sleep 1; do + echo $NAME > $stream_file + mplayer $URL + done + " + echo "** $REQ started" + exit 1 + fi + done; then + echo "!! Stream '$REQ' not found!" + exit 1 + fi +} +function stop() +{ + #stops every stream + if status &>/dev/null; then + status | cut -d\ -f2 | xargs printf "** killing %s\n" + tmux kill-session -t streams 2>/dev/null || echo "!! killing session failed" + else + echo "** no stream running"; + return 1 + fi +} + +function status() +{ + #tmux has-session -t streams 2>/dev/null + #RET=$? + + #tmux list-sessions 2>/dev/null + #return $RET + EV="`ps -ef | grep mplayer`" + if echo "$URLS" | while read URL NAME; do + if [ "`echo "$EV" | grep \"$URL\"`" ] ;then + echo "** $NAME running ($URL)" + exit 1 + fi + done; then + echo "** no stream running" + return 1 + else + return 0 + fi +} +function current() +{ + + return 1 +} +function list() +{ + echo "$URLS" | while read URL NAME ; do + echo "$NAME : $URL" + done + +} + +function shorthelp() +{ + echo "start|stop|restart|status|list [audio stream]" +} +function longhelp() +{ + B=`basename $0` + echo -n "Usage: $B " + shorthelp + echo "[32;1m get all available streams with [31;1;4m'/$B list'[m +Examples: + $B list + $B start groove + $B restart deepmix + $B status + $B stop" +} + + +case "$1" in + start) + start ${2-"`test -f $stream_file && cat $stream_file`"} + ;; + stop) + stop + ;; + (switch|restart) + stop + start $2 + ;; + status) + status + exit $? + ;; + list) + list + ;; + (--help) + shorthelp + ;; + *) + longhelp + ;; +esac |