#!/bin/bash
# CVS:     $Id: beckismartmount,v 1.3 2009/01/20 16:39:43 becki Exp $
# Author:  Stefan Beckert ( http://wiki.think-deep.com/becki:start )
# License: Public Domain
# Description:
#   Tries to mount a connected removable drive to the first available device
#   file listed in the "devices" variable
#   Typically used to mount an Usb Mass Storage Drive or PCMCIA drive
#   The mount point is independend from the device file and stays always the
#   same. It is specified in as the first command line parameter, eg:
#     beckismartmount /mnt/usbdrive
#   If omitted, /mnt/removable_drive is used instead

# Configuration
devices='/dev/sda1 /dev/sdb1 /dev/sdc1 /dev/sdd1'
target='/mnt/removable_drive'
# Configuration End

# filling some parameter variables:
script=$(basename $0)
error="$script error"
if [ "$1" ] ; then target=$1 ; fi

# Create target dir if it doesn't exist:
if [ ! -d "$target" ]; then
    if mkdir $target ; then
        echo "$script: $target did not exist, created it for you"
    else
        echo "$error: Could not create $target!"
        exit 2
    fi
fi

err='err'
for device in $devices; do
    echo "$script: Trying $device..."
    if mount -t reiserfs -o defaults $device $target ; then
        echo "$script: successfully mounted $device to $target"
        err=''
        break
    fi
done

if [ $err ]; then
    echo "$error: Mount failed!"
    exit 1
fi
