#!/usr/bin/perl

# MountDel  (c) Copyright 1998 Mark Black 

$version = 0.16 ;

# MountDel
# This script is called to delete a mounted filesystem.
# The input is the name of the filesytem to un-mount.

($inp) = @ARGV ;

# Output the version if requested
if($inp eq "-v") {
    print "$version\n" ;
    exit(0) ;
}

# Discover OS type and set variables for OS type
chop($os = `uname -s`) ;

if($os eq "Linux") {
    $fuser = "/usr/bin/fuser $inp" ;
} elsif($os eq "SunOS") {
    chop($ver = `uname -r`) ;
    ($major, $minor) = split(/\./, $ver) ;
    if($major == 5) {
	$fuser = "/usr/bin/fuser -c $inp" ;
    } else {
	$fuser = "/usr/bin/fuser -c $inp" ;
    }
}


# Does the mount point really exist
if( -d $inp ) {
    # Directory exists, now unmount it
    `umount $inp 2>/dev/null` ;
    if( $? ) {
	@fusers = `$fuser` ;
	print "ERROR:  Filesystem is in use by: @fusers " ;
	exit -1 ;
    }
} else {
    # Mountpoint does not exist!
    print "ERROR:  Mountpoint does not exist!\n" ;
    exit -1 ;
}
	    
exit 0 ;





