#!/bin/sh

if [ "$1" = "" ];
then
	echo "usage: $0 max"
	echo
	echo "creates missing console devices tty[1-max] vcs[1-max] and vcsa[1-max]"
	echo "where max is [1-63]."
	exit 0
fi

if [ "$1" -gt 63 -o "$1" -lt 1 ]
then
	echo "Error: max must be in [1-63]"
	exit 1
fi

MAX="$1"

I=1
while [ $I -le $MAX ];
do
	if [ ! -e /dev/tty$I ];
	then
		echo "creating /dev/tty$I..."
		mknod -m 644 /dev/tty$I c 4 $I
		chown root.tty /dev/tty$I
	fi

	if [ ! -e /dev/vcs$I ];
	then
		echo "creating /dev/vcs$I..."
		mknod -m 644 /dev/vcs$I c 7 $I
		chown root.tty /dev/vcs$I
	fi

	if [ ! -e /dev/vcsa$I ];
	then
		echo "creating /dev/vcsa$I..."
		mknod -m 644 /dev/vcsa$I c 7 $[$I+128]
		chown root.tty /dev/vcsa$I
	fi

	I=$[$I+1]
done
