#! /bin/sh -x
#
#
cancel=0
# preflight for Max 5
if [ ! -d  "/Applications/Max5" ] ; then
		osascript $1/Contents/Resources/StopInst51.scpt
		exit 1
# in DIPS551.pkg
	else
		if [ -d "/Applications/Max5/DIPS4" ] ; then
			echo "run warning4"
			cancel=`osascript $1/Contents/Resources/DeleteDIPS4first.scpt >&1`
			if [ $cancel -eq 1 ]; then
# clean archives
				if [ -f "$1/../dips551.pkg/Contents/Archive.pax.gz" ]; then
				rm -f $1/../dips551.pkg/Contents/Archive.pax.gz
				fi
				if [ -f "$1/../dips560.pkg/Contents/Archive.pax.gz" ]; then
				rm -f $1/../dips560.pkg/Contents/Archive.pax.gz
				fi
				if [ -f "$1/../dips561.pkg/Contents/Archive.pax.gz" ]; then
				rm -f $1/../dips561.pkg/Contents/Archive.pax.gz
				fi
				exit 1
			fi			
			
		fi 
		if [ -d "/Applications/Max5/DIPS5" ] ; then
			echo "run warning5"
			cancel=`osascript $1/Contents/Resources/DeleteDIPS5first.scpt >&1`
			echo $cancel
			if [ $cancel -eq 1 ]; then
# clean archives
				if [ -f "$1/../dips551.pkg/Contents/Archive.pax.gz" ]; then
				rm -f $1/../dips551.pkg/Contents/Archive.pax.gz
				fi
				if [ -f "$1/../dips560.pkg/Contents/Archive.pax.gz" ]; then
				rm -f $1/../dips560.pkg/Contents/Archive.pax.gz
				fi
				if [ -f "$1/../dips561.pkg/Contents/Archive.pax.gz" ]; then
				rm -f $1/../dips561.pkg/Contents/Archive.pax.gz
				fi
				exit 1
			fi			
		fi
fi

exit $cancel

	