Compaq BL10e Setting up a Linux PXE server and integrating clients - Page 16

import-to-tftpboot.sh file

Page 16 highlights

import-to-tftpboot.sh file The "import-to-tftpboot.sh" script imports a bootnet.img floppy into the /tftpboot directory and automatically renames the files based on the given name. #!/bin/sh TFTPBOOTDIR=/tftpboot PXELINUXDIR=$TFTPBOOTDIR/pxelinux.cfg TMPDIR=/tmp if [ -z "$2" ]; then echo This code will unpack a floppy image from location SOURCE into /tftpboot and will rename using the specified name; echo Usage: $0 SOURCE NAME; exit; fi SOURCE=$1 NAME=$2 # Create pxelinux.cfg directory if it does not exist. if [ ! -d $PXELINUXDIR ]; then mkdir -p $PXELINUXDIR; fi copyfiles() { # This section copies and renames all files except syslinux.cfg. FILES=`ls | grep -v syslinux.cfg` for X in $FILES; do cp -a $X $TFTPBOOTDIR/$NAME-$X; done # This section copies/renames syslinux.cfg and modifies it to point # correctly to the other copied/renamed files. for X in `ls | grep syslinux.cfg`; do sh /dev/null 2>&1 && { cd $SOURCE copyfiles cd / umount $SOURCE 16

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21

import-to-tftpboot.sh file
The "import-to-tftpboot.sh" script imports a bootnet.img floppy into the /tftpboot directory and
automatically renames the files based on the given name.
#!/bin/sh
TFTPBOOTDIR=/tftpboot
PXELINUXDIR=$TFTPBOOTDIR/pxelinux.cfg
TMPDIR=/tmp
if [ -z "$2" ]; then echo This code will unpack a floppy image from location SOURCE
into /tftpboot and will rename using the specified name; echo Usage: $0 SOURCE
NAME; exit; fi
SOURCE=$1
NAME=$2
# Create pxelinux.cfg directory if it does not exist.
if [ ! -d $PXELINUXDIR ]; then mkdir -p $PXELINUXDIR; fi
copyfiles()
{
# This section copies and renames all files except syslinux.cfg.
FILES=`ls | grep -v syslinux.cfg`
for X in $FILES; do cp -a $X $TFTPBOOTDIR/$NAME-$X; done
# This section copies/renames syslinux.cfg and modifies it to point
# correctly to the other copied/renamed files.
for X in `ls | grep syslinux.cfg`; do
sh <<-EOF > $PXELINUXDIR/$NAME-$X
`echo -ne "cat $X | sed"
for Y in $FILES; do
echo -ne " -e \"s,${Y}$\|${Y}[^=],$NAME-&,g\""
done`
EOF
done
}
# This section attempts to locate the specified files for copying purposes.
if [ -d $SOURCE ]; then
if [ `ls $SOURCE | wc -l` -eq 0 ]; then
# If SOURCE dir is empty, then attempt to mount that dir.
mount | grep $SOURCE ||
{
mount $SOURCE >/dev/null 2>&1 && {
cd $SOURCE
copyfiles
cd /
umount $SOURCE
16