#!/bin/sh

TMPFILE=`mktemp`

dialog --ok-label "Continue" \
	--menu "Select operation" 0 0 0 \
	"Mount" "Make storage accessible from command line." \
	"Format" "Format storage device, removing all data." \
	2> ${TMPFILE}
retval=$?

clear

if [ ${retval} -ne 0 ]
then
	rm -f "${TMPFILE}"
	echo "Cancelled."
	exit 1
fi

case `cat ${TMPFILE}` in
Mount)
	rm -f "${TMPFILE}"
	exec Pt-storage --mount
	;;
Format)
	rm -f "${TMPFILE}"
	dialog --yesno "Please confirm you wish to format the storage device. \
		THIS WILL REMOVE ALL DATA FROM THE DEVICE, AND IT WILL NOT BE \
		POSSIBLE TO RETRIEVE IT." \
		0 0
	retval=$?

	clear

	if [ ${retval} -ne 0 ]
	then
		echo "Format cancelled."
		exit 1
	fi

	exec Pt-storage --format
	;;
esac

echo "Bug; retval=$retval, got:"
cat ${TMPFILE}
echo "(EOF)"
rm -f "${TMPFILE}"
exit 2
