#! /bin/bash HERE=$(dirname $(readlink -f $0)) URLS=`cat $HERE/stream.db` #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; 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 "exec mplayer $URL" echo "** $REQ started" exit 1 fi done; then echo "!! Stream '$REQ' not found!" exit 1 fi } function stop() { #stops every stream tmux kill-session -t streams || echo "!! killing session failed" } function status() { tmux has-session -t streams 2>/dev/null RET=$? tmux list-sessions 2>/dev/null return $RET } 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 " get all available streams with '/$B list' Examples: $B list $B start groove $B restart deepmix $B status $B stop" } case "$1" in start) start $2 ;; stop) stop ;; restart) stop start $2 ;; status) if status; then echo "** stream running" exit 0 else echo "** Stream not running" exit 1 fi ;; list) list ;; (--help) shorthelp ;; *) longhelp ;; esac