#!/bin/bash

nodename="netboot-node"
nodedir="node"

if [ $# -lt 1 ]; then
    echo "Usage: $0 <base kennel> [path to nfs-root]";
	echo 
	echo "If not \"path to nfs-root\" defined, it takes from"
	echo "/etc/inetd.conf file or it makes equal to /tftpboot"
    exit 0;
fi

base=$1;

if [ ! -f $base ]; then 
	echo "File "$base" not found" 
	exit 1
fi

if [  $# -lt 2 ]; then
	tmp=`grep "in.tftp" /etc/inetd.conf | awk '{print $NF}'`
	# only first occure
	for i in $tmp ;	do
		tmp=$i
		break
	done
	unset $i
	
	if [ $tmp != "in.tftp" ]; then 
		path=$tmp
	else
		path="/tftpboot"
	fi

	unset $tmp
else
	path=$2
fi

echo "Base kernel file is "$base
echo "Path to nfs-root is "$path

echo -n "Creating kernels... "
for i in `seq -w 15`; do
    mknbi-linux --rootdir=$path/$nodedir$i $base > ./$nodename$i;
done
echo "done."

exit 0

