#!/bin/sh

# sqp_JogglerPurge.sh v1.01 (16th April 2012) by Andy Davison
#  Called by the JogglerPurge applet to completely remove SqueezePlay for Joggler.

PLATFORM=`cat /tmp/sqp_platform`
[ "$PLATFORM" = "native" ] || export PATH=$PATH:`dirname $0`

if [ "$1" != "purge" ]; then
	echo "Unless you tell me to purge, I'm not doing a thing."
	exit 0
fi

if [ "$PLATFORM" = "sqpos" ]; then
	echo "Oh, no you don't!"
	exit 0
elif [ "$PLATFORM" = "native" ]; then
	SUDO=""
else
	SUDO="sudo"
fi

# Put the original asound.conf file back.
if [ -f /etc/asound.conf_presqp ]; then
	$SUDO rm /etc/asound.conf
	$SUDO mv /etc/asound.conf_presqp /etc/asound.conf
fi

# Remove the config files.
#  We can use a fixed user path, because we should have been deleted if
#  this was a non-standard install or on a custom OS.
[ "$PLATFORM" = "native" ] && rm -rf /.squeezeplay
[ "$PLATFORM" = "native" ] || rm -rf /home/joggler/.squeezeplay

# Now do the platform-specific stuff.
if [ "$PLATFORM" = "native" ]; then
	
	INSTALL_DIR="/media/opt"
	
	# Remove logs.
	rm /media/logs/squeezeplay.log 2>/dev/null
	
	# Remove the Launcher
	if [ -d /media/launcher/apps/SqueezePlay ]; then
		rm -rf /media/launcher/apps/SqueezePlay
		/media/launcher/index.cgi >/dev/null
	fi
	
else

	INSTALL_DIR="/opt"
	
	# Remove logs.
	$SUDO rm /var/log/squeezeplay.log
	
	# Remove the menu entry and the autostart.
	$SUDO xdg-desktop-menu uninstall --mode system $SQPAREA/squeezeplay/bin/squeezeplay.desktop 2>/dev/null
	rm /home/joggler/.config/autostart/sqpautostart.sh.desktop 2>/dev/null

fi

# Deep breath.
sleep 3

# And gone.
$SUDO rm -rf $INSTALL_DIR/squeezeplay
killall jive

exit 0