#!/bin/bash ################################# # ## # mediacenter control script ## # ## ################################# # **** config section **** author="david@socialnerds.org" version="0.1_alpha" hwaddr="00:10:c6:cd:00:d4" #mc mac address ipaddr="10.1.1.7" #mc ip address/hostname wolserv="10.1.1.4" #remote wakeonlan host (connects via ssh) remoteuser="media" #mc user mediapath="/home/media/Videos" #remote basepath for mediafiles # check for dependencies #apt-get install wakeonlan dialog # **** bashtrap **** # bash trap function is executed when CTRL-C is pressed bashtrap() { log 3 "bashtrap - triggered" clear echo "CTRL+C detected.. exiting!" exit 1 } navigation() { dialog --backtitle "Media Center Control" --title "Navigation" --no-cancel --menu "" 13 55 7 start "start mediacenter" stop "shutdown mediacenter" vnc "open vnc session" play "play mediafile" kill "kill mediaplaybak" volume "control volume" quit "leave media control" 2> /tmp/dialog navresult=$(cat /tmp/dialog) rm /tmp/dialog if [ $navresult = start ]; then startmc elif [ $navresult = stop ]; then stopmc elif [ $navresult = vnc ]; then vncconnect elif [ $navresult = play ]; then playmedia elif [ $navresult = kill ]; then killmedia elif [ $navresult = volume ]; then volumecontrol elif [ $navresult = quit ]; then exit 0 fi } isitup() { # is mediacenter up? clear echo "checking if mediacenter is up..." ping -w 1 $ipaddr &> /dev/null local pingresult=$? return $pingresult } startmc() { # check if mediacenter is up isitup if [ $? = 0 ]; then dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr is already up and running" 9 55 else ssh $wolserv wakeonlan $hwaddr &> /dev/null dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n magic package sent to mediacenter@$ipaddr" 9 55 fi } stopmc() { # is mediacenter up? isitup if [ $? = 0 ]; then ssh $remoteuser@$ipaddr "sudo shutdown -h now" dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr will be shutdown" 9 55 else dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55 fi exit 0 } vncconnect() { # check if mediacenter is up isitup if [ $? = 0 ]; then vncviewer $ipaddr &> /dev/null & else dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55 fi } playmedia() { file="/home/media/Videos/series/the_big_bang_theory/season_4/BBTIV.14.avi" # check if mediacenter is up isitup if [ $? = 0 ]; then # selecting file ssh -t $remoteuser@$ipaddr "dialog --fselect $mediapath 7 70 2> /tmp/dialog" local file=$(ssh $remoteuser@$ipaddr "cat /tmp/dialog && rm /tmp/dialog") ssh $remoteuser@$ipaddr "export DISPLAY=:0.0 && vlc --no-video-title-show -f $file &> /dev/null" & else dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55 fi } killmedia() { # check if mediacenter is up isitup if [ $? = 0 ]; then ssh $remoteuser@$ipaddr "killall vlc && killall rhythmbox" else dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55 fi } # **** volume control **** volumecontrol() { # check if mediacenter is up isitup if [ $? = 0 ]; then # open up remote alsamixer ssh -t $remoteuser@$ipaddr alsamixer else dialog --backtitle "Media Center Control" --title "Info" --msgbox "\n\n mediacenter@$ipaddr unreachable" 9 55 fi } # ****** start of actual script ****** # **** bash trap initialisation **** trap bashtrap INT # **** run navigation **** # endless loop while [ 1 ]; do navigation done exit 0 # end of script