#!/bin/sh
VENDOR=Samsung

BASE_DIR=`dirname "$0"`
cd "$BASE_DIR"

VENDOR_PATH=/opt/$VENDOR

if test -d "$VENDOR_PATH/PSU" ; then
	DEST_PATH="$VENDOR_PATH/PSU"
elif test -d $VENDOR_PATH/psu ; then
	DEST_PATH="$VENDOR_PATH/psu"
else
	echo "INFO: psu already uninstalled."
	return
fi

# Start PhoneBook uninstall if found
if test -e ../phonebook/uninstall.sh ; then
	sh ../phonebook/uninstall.sh $VENDOR
elif test -e ../PhoneBook/uninstall.sh ; then
	sh ../PhoneBook/uninstall.sh $VENDOR
fi

# Start EmailBook uninstall if found
if test -e ../emailbook/uninstall.sh ; then
	sh ../emailbook/uninstall.sh $VENDOR
elif test -e ../EmailBook/uninstall.sh ; then
	sh ../EmailBook/uninstall.sh $VENDOR
fi

# Start AddressBook uninstall if found
if test -e ../addressbook/uninstall.sh ; then
	sh ../addressbook/uninstall.sh $VENDOR
elif test -e ../AddressBook/uninstall.sh ; then
	sh ../AddressBook/uninstall.sh $VENDOR
fi

# Start WirelessSetup uninstall if found
if test -e ../wirelessetup/uninstall.sh ; then
	sh ../wirelessetup/uninstall.sh $VENDOR
elif test -e ../WirelessSetup/uninstall.sh ; then
	sh ../WirelessSetup/uninstall.sh $VENDOR
fi

# Start PSULauncher uninstall if found
if test -e ../psulauncher/uninstall.sh ; then
	sh ../psulauncher/uninstall.sh
elif test -e ../PSULauncher/uninstall.sh ; then
	sh ../PSULauncher/uninstall.sh
fi

#remove destination
VERSION=`cat "$DEST_PATH/bin/.version"`
rm -fr "$DEST_PATH"
if test -d "$DEST_PATH" ; then
	echo "ERROR: Cannot uninstall psu! Check your permissions."
	return
else
	echo "INFO: psu (ver.$VERSION) has been uninstalled successfully"
fi

# remove vendor folder if it is empty
rmdir "$VENDOR_PATH" 2>/dev/null
