#!/bin/sh
# vcmount 
# check directory, mount if device is specified

MOUNT=$1
DEVICE=$2

if [ -z "$MOUNT" ]; then
    echo "ERROR: Directory is not specified"
    exit 1
fi
mkdir -p $MOUNT

if [ "$DEVICE" ]; then
    echo Mounting $DEVICE to $MOUNT
    if mount | grep -qe "^$DEVICE "; then
	umount $MOUNT
    fi
    if mount | grep -qe "on *$MOUNT "; then
	umount $DEVICE
    fi
    if ! mount $DEVICE $MOUNT; then
	echo "ERROR: cannot mount $DEVICE"
	exit 1
    fi
    mount | grep -e "$DEVICE"
fi
