#!/bin/bash
logfile="${HOME}/.Skype/skype.log"
progname="skype"
progpath="/opt/${progname}/"
shellcheck1=` which artsshell 2> /dev/null `
shellcheck2=` which esd 2> /dev/null `
artsdcheck=` ps x | grep artsd | grep -v grep `
esdcheck=` ps x | grep "esd ." | grep -v grep `
wrapsound="yes"

[ "$1" == "oss" ] && wrapsound="no"

echo "===== " `date` " =====" > ${logfile}
if [[ -z ${shellcheck1} && -z ${shellcheck2} ]]
then
	echo "No installed artsshell or esd found"
	echo "Assuming you're running no sound daemon"
	echo "Starting ${progname} without a sound wrapper"
	echo "Starting ${progname} without a sound wrapper" >> ${logfile}
	${progpath}/${progname}.bin >> ${logfile} 2>> ${logfile}
				
else
	if [[ ${wrapsound} == "yes" && ${shellcheck1} == ${KDEDIR}/bin/artsshell && -n ${artsdcheck} ]]
	then
		echo "Running artsd found"
		echo "Starting artsd wrapped ${progname}"
		echo "Starting artsd wrapped ${progname}" >> ${logfile}
		artsdsp -m ${progpath}/${progname}.bin >> ${logfile} 2>> ${logfile}

	elif [[ ${wrapsound} == "yes" && ${shellcheck2} == /usr/bin/esd && -n ${esdcheck} ]]
	then
		echo "Running esd found"
                echo "Starting esd wrapped ${progname}"
		echo "Starting esd wrapped ${progname}" >> ${logfile}
		esddsp ${progpath}/${progname}.bin >> ${logfile} 2>> ${logfile}
	else
		echo "No running artsd or esd found"
		echo "Starting ${progname} without sound daemon"
		echo "Starting ${progname} without sound daemon" >> ${logfile}
		${progpath}/${progname}.bin >> ${logfile} 2>> ${logfile}
	fi
	
fi
exit 0
