#! /bin/sh

###############################################################################
###                                                                         ###
###               GNU Interactive Tools 4.3.17 auto-mount script            ###
###            Copyright (C) 1994-1998 Free Software Foundation, Inc.       ###
###                 Written by Tudor Hulubei and Andrei Pitis.              ###
###                                                                         ###
###############################################################################

### $Id: gitmount,v 1.3 1998/03/06 02:40:12 tudor Exp $

###
### The ideea of this script is quite general but the script needs
### some changes in order to run on other UNIX systems.
### The major change is in the file system types list.
###
### If you enhance this script, please send me a patch at
### tudor@cs.unh.edu and I'll include it in the next release.
###

exit_code=0
name=`basename "$0"`
mp="/mnt"

if test "$#" -lt 1; then
    echo "usage: $name devices...      (ex: $name fd0)"
    exit 1
fi

while true; do
    device="$1"

    if test `echo "$device" | cut -c1-5` = "/dev/"; then
	device=`echo "$device" | cut -c6-`
    fi

    if test ! -b /dev/"$device"; then
	echo "$0: /dev/$device: no such device" >&2
	exit_code=1
    else
	success=1
	if test ! -d "$mp/$device"; then
	    gitmkdirs "$mp/$device"
	    if test $? -ne 0; then
		success=0
		exit_code=1
	    fi
	fi

	if test $success -eq 1; then
	    success=0
	    for fstype in ext2 iso9660 vfat msdos ntfs minix ext xiafs\
			  hpfs xenix sysv coherent ufs umsdos affs; do
		mount -t "$fstype" /dev/"$device" "$mp/$device"> /dev/null 2>&1
		if test $? = 0; then
		    success=1
		    break
		fi
	    done

	    # No luck so far.  Try without specifying the fs type.
	    if test $success -eq 1; then
		echo "$device: $fstype"
	    else
		mount /dev/"$device" "$mp/$device" > /dev/null 2>&1
		if test $? = 0; then
		    echo "$device: default"
		else
	            # As a last resort try without specifying the fs
	            # type and mounting directory.  Hopefully this
	            # will allow regular users to mount floppies, zip
	            # drives and and cdroms under Linux.
		    mount /dev/"$device" > /dev/null 2>&1
		    if test $? = 0; then
			echo "$device: default"
		    else
			echo "$device: could not mount file system" >&2
			exit_code=1
		    fi
		fi
	    fi
	fi
    fi

    shift
    if test $# -eq 0; then
	exit $exit_code
    fi
done
