#!/bin/bash

if [[ "$DISPLAY" && "$(which Xdialog 2>&1 | grep -v "which: no")" ]]; then
	dialog="Xdialog"
else
	dialog="dialog"
fi
if [ ! -e "$1" ]; then
	$dialog --title "Un-Mount What??" --msgbox "\nIf you passed a path, it seems to be incorrect.\n" 0 0
	exit
fi
xx=`mountpoint "$1"`
if [[ "$xx" == *"is a mountpoint"* ]]; then
	fusermount -u "$1"
	rmdir "$1"
else
	$dialog --title "Already unmounted" --msgbox "\n...so we will delete :-)\n" 0 0
	rmdir "$1"
fi
exit 0
