#!/bin/bash
#
# This preflight script deletes the previous application symlink
# so writes by the installer act as expected.
#
echo "Start preflight script"

# the Application's name - this must be configured for each project!
APPNAME="X2"

# get the params we care about
DESTPATH="$2"

# destpath is not kept properly in all times. If we have a dest token, use it.
# needs removal of app name if it's there
if [ "$DESTINATION_TOKEN" ]; then
	echo using "$DESTINATION_TOKEN"
	FINALPATH="$DESTINATION_TOKEN/Contents/MacOS/$APPNAME"
else
	FINALPATH="$DESTPATH/$APPNAME.app/Contents/MacOS/$APPNAME"
fi

# simply delete the symlink, if it exists
echo "$FINALPATH"
if [ -e "$FINALPATH" ]
then
	if ! rm "$FINALPATH"
	then 
		exit 1
	fi
else
	echo "not there"
fi
echo "done"
exit 0
