#!/bin/sh

# This must agree w/ explorer_pd and mkpdmount
MNT_PENDRIVE=$(pd_directory)

# In case it doesn't exist
cd $MNT_PENDRIVE || exit 1

# Check for relative pathnames in argument; could be used to wipe out entire
# filesystem
if ! perl -e 'exit $ARGV[0] =~ m[\.];' $1; then
  echo 'Relative pathnames are not allowed.'
fi

# Check if mountpoint to be deleted actually exists... :D
if [ ! -d "$1" ]; then exit 1; fi

# Delete the mount point indicated by the first argument, but not before
# checking mounted file systems for the same
if ! mount | grep -q "${MNT_PENDRIVE}/${1}"; then
  rm -r ${1}
else
  echo "File system is mounted."
fi
