a simple script i wrote to start/shutdown ushare for when i do or dont want to stream media to my xbox 360.
i am sure this code can be greatly simplified from what i wrote.
Code:
#!/bin/bash
# front end script for sharing media to xbox 360 with ushare by dubux
# variables
# setup directory structure of your media.
ALLMEDIA="/path/to/all/your/media"
US1=movies
US1DIR="/path/to/movies"
US2=music
US2DIR="/path/to/music"
US3=wma
US3DIR="/path/to/wma"
# name the media server and port to listen on.
MEDIASRVR=uShare
MDAPORT=49152
uscmd() {
nohup ushare -n $MEDIASRVR -p $MDAPORT -c "$MEDIADIR" -x >/dev/null 2>&1 &
}
ps aux | grep -v grep | grep -v /bin/bash | grep ushare -n > /tmp/tmp.myparsefile
USPID=`awk '{ print $2}' /tmp/tmp.myparsefile `
USGREP=`ps aux | grep -v grep | grep -c ushare -n `
if [ $USGREP != 0 ]
then
USSTATUS="running [PID: $USPID]"
rm /tmp/tmp.myparsefile
else
USSTATUS="not running"
rm /tmp/tmp.myparsefile
fi
echo " "
echo "#####################################"
echo "# ushare menu #"
echo "#####################################"
echo " "
echo "status: $USSTATUS"
echo " "
echo "[1] start ushare (all media)"
echo "[2] start ushare sharing only $US1"
echo "[3] start ushare sharing only $US2"
echo "[4] start ushare sharing only $US3"
echo "[5] shutdown ushare"
echo "[6] close menu"
echo " "
echo "select number from menu : "
read i;
case $i in
1)
if [ $USGREP != 0 ]
then
echo " "
echo "ushare is already running. [PID: $USPID]"
echo " "
else
MEDIADIR="$ALLMEDIA"
uscmd
echo " "
echo "ushare has been successfully started sharing all media."
echo " "
fi
;;
2)
if [ $USGREP != 0 ]
then
echo " "
echo "ushare is already running. [PID: $USPID]"
echo " "
else
MEDIADIR="$US1DIR"
uscmd
echo " "
echo "ushare has been successfully started sharing $US1."
echo " "
fi
;;
3)
if [ $USGREP != 0 ]
then
echo " "
echo "ushare is already running. [PID: $USPID]"
echo " "
else
MEDIADIR="$US2DIR"
uscmd
echo " "
echo "ushare has been successfully started sharing $US2."
echo " "
fi
;;
4)
if [ $USGREP != 0 ]
then
echo " "
echo "ushare is already running. [PID: $USPID]"
echo " "
else
MEDIADIR="$US3DIR"
uscmd
echo " "
echo "ushare has been successfully started sharing $US3."
echo " "
fi
;;
5)
if [ $USGREP != 0 ]
then
echo " "
echo "attempting to shut down ushare [PID: $USPID].."
echo " "
kill -9 $USPID
#check to see if processes were killed.
sleep 2
if ps aux | grep -v grep | grep -v /bin/bash | grep ushare -n
then
echo "ushare could not be shut down. try shutting down ushare manually."
else
echo "ushare has been shutdown successfully."
echo " "
fi
else
echo " "
echo "ushare is not currently running."
echo " "
fi
;;
6)
exit
esac