#!/bin/sh
[ -n "$1" ] || {
    echo "Usage: $0 <mount point>"
	exit 1
}

# ltspfs_mount, passed a directory name, used in /var/run/ltspfs_fstab.
grep "$1" /var/run/ltspfs_fstab | while read DEV MOUNTPOINT TYPE OPTIONS DUMP PASS; do
   [ -d ${MOUNTPOINT} ] || mkdir ${MOUNTPOINT}
   ret=$(LANG=C mount -t ${TYPE} -o ${OPTIONS} ${DEV} ${MOUNTPOINT} 2>&1)
   # Call ltspfs_entry remove if the mount fails and is not a floppy drive
   # and if the failure is not that it is already mounted (since this can occur
   # when more than one ltspfsmounter tries to mount the volume, at which 
   # point we want to gracefully resume
   if [ "$?" != 0 ]; then
        case $MOUNTPOINT in
            *floppy*) ;;
            *) 
                case $ret in
                    *already*mounted*) ;;
                    *) 
                       [ -z "$(grep ${MOUNTPOINT} /proc/mounts)" ] && \
                           /lib/udev/ltspfs_entry remove ${DEV} ;;
                esac
                ;;
        esac
   fi
done
