搭建PXE无人值守shell script

#!/bin/bash
#Shell name:conf_pxe.sh
#
#Program:
# configer pxe server
#
#Author: pero
#Email:  [email protected]
#
#History:
# 2012/7/25
#Usage: vi conf_pxe.sh :set ff=unix
#
#If you have any opinion please contact me

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:.
export PATH

if [ $UID -ne 0 ]
then
 echo "Run as root"
 exit 77
fi

soft=$(rpm -qa |grep tftp-server |wc -l)

if [ $soft -lt 1 ]
then
 yum install tftp-server -y &> /dev/null
fi

chkconfig tftp on

read -p "Please input a dir which have all package of rpm like source of yum:" dir

sdir=$dir/Packages

if [ ! -e $sdir ]
then
 echo "$dir is wrong,try again"
 exit 77
fi

nfile=/etc/exports
cs=$(cat /etc/exports |gawk '{NR==1} {print $2}')

echo "$dir $cs" >> $nfile


path=$(grep server_args /etc/xinetd.d/tftp |gawk '{print $4}')

cd $path

softp=$(rpm -qa |grep syslinux|wc -l)

if [ $softp -eq 0 ]
then
 yum install syslinux -y &> /dev/null
fi

pxe=$(find /usr/share/syslinux/ -name pxelinux.0)

cp -a $pxe $path

cp -a $dir/images/pxeboot/vmlinuz $path
cp -a $dir/images/pxeboot/initrd.img $path

mkdir pxelinux.cfg

cd pxelinux.cfg

filep=default
touch $filep

echo "default perofu" >> $filep
echo "timeout 300" >> $filep
echo "prompt 1" >> $filep
echo "label perofu" >> $filep
echo "  kernel vmlinuz" >> $filep
echo "  append initrd=initrd.img" >>$filep

/etc/init.d/xinetd restart &> /dev/null
/etc/init.d/nfs restart &> /dev/null
/etc/init.d/dhcpd restart &> /dev/null

if [ $? -eq 0 ]
then
 echo "pxe is ok"
else
 echo "Please check again"
fi

你可能感兴趣的:(shell,script)