#!/bin/sh
#
# ident "@(#)bbmknod.src	1.5 05/02/17 SMI"
#
# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

# duplicates a special file 
# $1 src dir
# $2 special file
# $3 destination path
# $4 file permission  
# $5 owner

. $BBROOT/etc/opt/SUNWbb/blackbox.rc    

if [ $# != 5 ]; then

	echo "usage: $0 <srcdir> <file> <dstdir> <perm> <owner>"
	exit 1
fi

if [ $1 != "." ]; then 
	DSTDIR=$3/$1
else 
	DSTDIR=$3
fi

SRCFILE=$1/$2
DSTFILE=$DSTDIR/$2

if [ ! -c $SRCFILE ]; then
        echo "not character special file: $SRCFILE"
        exit 1
fi


if [ ! -d $DSTDIR ]; then
        (umask 022; mkdir -p $DSTDIR)
fi

str=`/usr/bin/file $SRCFILE | awk '{ print $4 }' | cut -f2 -d'(' | cut -f1 -d')'`
major=`echo $str | cut -f1 -d'/'`
minor=`echo $str | cut -f2 -d'/'`

rm -f $DSTFILE
mknod $DSTFILE c $major $minor > /dev/null 2>&1
chown $5 $DSTFILE
chmod $4 $DSTFILE

exit 0
