#!/bin/sh

if [ "x${1}" == "x" ]; then
    echo "Please give the filesystem name (under /Volumes, e.g. \"GARMIN\")"
    exit
fi

VOLUME=/Volumes/${1}

# Clean Spotlight
echo "Cleaning Spotlight."
mdutil -i off ${VOLUME} 2>&1 > /dev/null
mdutil -E ${VOLUME} 2>&1 > /dev/null
rm -rf ${VOLUME}/.Spotlight-V100

# Clean other Mac OS specific stuff
echo "Cleaning other Mac OS specific files."
rm -rf ${VOLUME}/.Trashes
rm -rf ${VOLUME}/.fseventsd
find ${VOLUME} -name "._*" | xargs rm -rf

# Umount disk
echo "Unmounting ${VOLUME}."
diskutil umount ${VOLUME}

echo "Done."
