Sophie

Sophie

distrib > Mandriva > 8.2 > i586 > media > contrib > by-pkgid > b577c848bffee1d28262e31db2ee3f85 > files > 174

pxe-sample-1.2.0-8mdk.i586.rpm

#!/bin/bash

#Path were the tftp store his files
TFTPBASE="/tftpboot"

#Path were the pxelinux.0 or linux.0 is stored
PXEBASE=${TFTPBASE}/PXEClient

#Path were the configfile of pxelinux are stored
PXELINUXCFG=${PXEBASE}/pxelinux.cfg/

#The base address of your network (A C class address)
BASE="192.168.200"


##############   showParams ########################
# Show the syntax of the script
showParams(){
echo "Syntax is : $0 <ip_min> <ip_max> <config_file>";
echo "       ie : $0 1 254 default"
echo "If <config_file> equal 'delete', it removes the config file";
exit;
}


############## maxLowerThanMin ####################
#Indicate that your parameter are stupid !
maxLowerThanMin(){
echo "Parameter <ip_max> is lower than <ip_min> !";
echo " $2 is lower than $1";
}


#################### MAIN ###########################
# The main procedure

#If you don't give 3 parameters, it shows the syntax
if [ $# -ne 3 ]; then
showParams;
fi

#If the greater ip is lower than the lower ip, it shows the error !
if [ $2 -lt $1 ]; then
maxLowerThanMin;	
fi

MIN=$1
for i in `seq $1 $2`; do # For all the ip adresses
		# Get the filename from the ip address of the pxe client.
		# gethostip give the config filename from an ip address
		FILENAME=$(gethostip ${BASE}.${i} | cut -d " " -f 3) 
		#if third parameter is "delete"
		if [ $3 == "delete" ]; then
			# Delete the config file
			rm ${PXELINUXCFG}/$FILENAME;
		else
			# Create the config file with the ip address : link
			ln -sf $3 ${PXELINUXCFG}/$FILENAME;
			# Or Create the config gile with the ip address : copy
			#cp $3 ${PXELINUXCFG}/$FILENAME -f;
		fi
done