2011-06-27 01:29:26 +02:00
|
|
|
#!/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()
|
|
|
|
{
|
2011-06-28 00:35:58 +02:00
|
|
|
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
|
2011-06-27 01:29:26 +02:00
|
|
|
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
|
2011-06-28 00:35:58 +02:00
|
|
|
killmedia
|
2011-06-27 01:29:26 +02:00
|
|
|
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
|
2011-06-27 19:49:04 +02:00
|
|
|
vncviewer $ipaddr &> /dev/null &
|
2011-06-27 01:29:26 +02:00
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2011-06-28 00:35:58 +02:00
|
|
|
killmedia()
|
2011-06-27 01:29:26 +02:00
|
|
|
{
|
|
|
|
# check if mediacenter is up
|
|
|
|
isitup
|
|
|
|
if [ $? = 0 ]; then
|
2011-06-28 00:35:58 +02:00
|
|
|
ssh $remoteuser@$ipaddr "killall vlc && killall rhythmbox"
|
2011-06-27 01:29:26 +02:00
|
|
|
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
|
|
|
|
|
2011-06-27 19:49:04 +02:00
|
|
|
exit 0
|
2011-06-27 01:29:26 +02:00
|
|
|
# end of script
|