#!/bin/bash

# * Create 10 /dev/vtl? device nodes - Could be improved.
# *
# * $Id: make_vtl_devices,v 1.2.2.1 2006-08-06 07:58:44 markh Exp $
# *
# * Copyright (C) 2005 Mark Harvey markh794 at gmail dot com
# *                                mark dot harvey at veritas dot com
# *
# * This program is free software; you can redistribute it and/or modify
# * it under the terms of the GNU General Public License as published by
# * the Free Software Foundation; either version 2 of the License, or
# * (at your option) any later version.
# *
# * This program is distributed in the hope that it will be useful,
# * but WITHOUT ANY WARRANTY; without even the implied warranty of
# * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# * GNU General Public License for more details.
# *
# * You should have received a copy of the GNU General Public License
# * along with this program; if not, write to the Free Software
# * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
#

if [ $# != 1 ]; then
	echo "Usage: $0 username"
	exit 1
fi

USER=$1
MAJOR=`grep " mhvtl$" /proc/devices|awk '{print $1}'`

# Source default config file if not already set
if [ "X$MHVTL_CONFIG_PATH" == "X" ]; then
	. /etc/mhvtl/mhvtl.conf
else
	. $MHVTL_CONFIG_PATH/mhvtl.conf
fi
DEVICE_CONF=$MHVTL_CONFIG_PATH/device.conf

umask 002

if [ "X" == "X$MAJOR" ]; then
	echo "Could not find a major number for mhvtl: kernel module loaded ?"
	exit 1
fi

for a in $(awk '$1 == "Drive:" || $1 == "Library:" {print $2}' $DEVICE_CONF); do
	if [ -c /dev/mhvtl$a ]; then
		rm -f /dev/mhvtl$a
	fi
	mknod -m 660 /dev/mhvtl$a c $MAJOR $a
	chown $USER:$USER /dev/mhvtl$a
	chmod 660 /dev/mhvtl$a
	echo "Made node for /dev/mhvtl$a"
done

