#!/bin/sh

if [ $# -lt 6 -o $# -gt 7 ]; then
    echo
    echo "Usage: makeset min count cmd prefix type major [suffix]"
    echo
    echo "where  min     is the minor of the first node to make,"
    echo "       count   is the number of the last node to make,"
    echo "       cmd     is the command to make a node,"
    echo "       prefix  is the node name prefix,"
    echo "       type    is the type selector for the node,"
    echo "       major   is the major number for the node,"
    echo "  and  suffix  is a suffix to append to the node names."
    echo
    echo "The following type selectors are supported:"
    echo
    echo "   b    Block device, all nodes have numeric suffix."
    echo "   d    Block device, first node is raw device without numeric suffix."
    echo
    echo "   c    Character device with decimal numeric suffix."
    echo "   x    Character device with hexadecimal numeric suffix."
    echo
else
    N=0
    while [ $N -le $2 ]; do
	P=`expr $N + $1`
	case ".$5" in
	    .b)     eval $3 $4$N$7 $5 $6 $P
		    ;;
	    .c)     eval $3 $4$N$7 $5 $6 $P
		    ;;
	    .d)     if [ $N -gt 0 ]; then
			eval $3 $4$N$7 $5 $6 $P
		    else
			eval $3 $4$7 $5 $6 $P
		    fi
		    ;;
	    .x)	    if [ $N -gt 9 ]; then
			R=`echo 123456789abcdef | cut -b $N`
			eval $3 $4$R$7 c $6 $P
		    else
			eval $3 $4$N$7 c $6 $P
		    fi
		    ;;
	esac
	N=`expr $N + 1`
    done
fi
