#!/bin/sh
set -e
USBDIR="/media/cdrom"
DIR="/media/cdrom/etc"

if [ -d ${DIR} ] ; then
   cryptmount -u cusb
   umount ${USBDIR}
   exit
fi

if mount | grep -q ${USBDIR} ; then
   umount ${USBDIR}
   exit
fi

MODULES="cdrom
         vfat"

for mod in $MODULES ; do
    if ! /sbin/lsmod | grep -q -w "^$mod" ; then
         sudo modprobe -v $mod
    fi
done

mount ${USBDIR}

if [ -d ${DIR} ] ; then
    cryptmount cusb
fi
