#!/bin/sh
##############################################################################
# Copyright (C) 2008 - 2013 vortexbox.org
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# Name: switch-player
# 
# Script to switch between VortexBox Player and Squeezeslave.
#
# Usage: switch-player [ vortexbox | squeezeslave ]
#
# Author: Ron Olsen <ronolsen@comcast.net>
#
# Date: Sat Mar 27 2010
# Version: 1.1
# Use chkconfig on/off instead of chkconfig --add/--del
#
# Date: Fri Mar 26 2010
# Version: 1.0
#
##############################################################################
 
if [ $# -ne 1 ]
then
    echo "Usage: switch-player [ vortexbox | squeezeslave ]"
    exit
fi

#echo "Switch player to $1"

case $1 in
vortexbox)
    if [ ! -f /usr/bin/vortexbox-player ]
    then
        echo "Error: VortexBox Player is not installed"
        exit 1
    fi
    echo "Switching to VortexBox Player"
    chkconfig vortexbox-player on
    chkconfig squeezeslave off
    if pgrep -f /usr/bin/squeezeslave > /dev/null
    then
        service squeezeslave stop
    fi
    if ! pgrep -f /usr/bin/vortexbox-player > /dev/null
    then
        service vortexbox-player start
    fi
    ;;
squeezeslave)
    if [ ! -f /usr/bin/squeezeslave ]
    then
        echo "Error: Squeezeslave is not installed"
        exit 1
    fi
    echo "Switching to Squeezeslave"
    chkconfig squeezeslave on
    chkconfig vortexbox-player off
    if pgrep -f /usr/bin/vortexbox-player > /dev/null
    then
        service vortexbox-player stop
    fi
    if ! pgrep -f /usr/bin/squeezeslave > /dev/null
    then
        service squeezeslave start
    fi
    ;;
*)
    echo "Usage: switch-player [ vortexbox | squeezeslave ]"
    exit
    ;;
esac
