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

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

# we are interested in the following special files
# syntax for each entry  <permisson>':'[path]<filename>
# if filename is '+' ==> all files with this path and
# all files get the same permission
# SP_FILES="660:ip 666:kstat 666:null 666:ptmx 644:pts/+ 666:tty 666:zero"
# defined in blackbox.rc

# $1 directory
# $2 special file
# $3 destination path
# $4 file permission
# $5 owner

create_entry() {

    if [ ! -c ${1}/${2} ]; then
	echo "not character special file: ${1}/${2}"
	return
    fi

    if [ ! -d ${3}/${1} ]; then
	mkdir -p ${3}/${1}
    fi
    str=`/bin/ls -Ll ${1}/${2}`
    major=`echo $str | awk '{ print $5 }' | cut -f1 -d','`
    minor=`echo $str | awk '{ print $6 }'`

    rm -f ${3}/${1}/${2}
    mknod ${3}/${1}/${2} c $major $minor 
    chmod $4 ${3}/${1}/${2}
    chown $5 ${3}/${1}/${2} 
}



#
# main starts here
#
dest=`pwd`
cd /dev

for entry in $SP_FILES; do

    ownr=`echo $entry | cut -f1 -d':'`
    perm=`echo $entry | cut -f2 -d':'`
    rest=`echo $entry | cut -f3 -d':'`
    dir=`dirname $rest`
    file=`basename $rest`
    ( 
	if [ "$file" = "+" ]; then
	    files=`ls -L $dir`
	    for f in $files; do
		bbmknod $dir $f $dest $perm $ownr
	    done
	else
	    bbmknod $dir $file $dest $perm $ownr
	fi
    )
done



