#!/bin/bash
#
# mountcd 1.0.0 (trax@the-force.ml.org)
#
# Semi-Intelligent CD-Mounting Script
# 1998/04/1
#

# "config section : the hard part :)"

device="/dev/cdrom"

# where do you want to mount today?
mountpoint="/mnt/cdrom"

# end config section

case $1 in
# user wants to mount...*shudder*
'on')
  # and a complex way of asking, is the mountpoint mounted?
  list=`ls $mountpoint | cut -f 1 | wc -l | cut -f 7 -d ' ' `

  case $list in

  # if it isn't, go ahead and mount, Scotty!
  '1') mount $device $mountpoint ;;
  # no comment...
  *) echo "First unmount $mountpoint with 'mountcd off'"
  ;;

  esac
  ;;

'off')
# blowing off steam...

  # ooh, it's that thing again
  list=`ls $mountpoint | cut -f 1 | wc -l | cut -f 7 -d ' ' `

  case $list in

  # you know the drill by now...
  '1') echo "First mount $device with 'mountcd on'"
  ;;
  *) umount $device ;;

  esac
;;

# and for people like me, who doesn't know the difference
# between left and right...

*) echo "Usage: mountcd [on|off]"
;;
esac
