#!/bin/bash
#zxs
read -p "请输入IP地址:" name
read -p "请输入网段:" a
read -p "请输入地址池:" b
read -p "请输入网关:" c
iptables -F &> /dev/null
systemctl stop firewalld &> /dev/null
setenforce 0 &> /dev/null
yum -y install vsftpd &> /dev/null
echo $? " ok"
[ -d /var/ftp/asd ] || mkdir /var/ftp/asd
yum -y install tftp-server syslinux dhcp &> /dev/null
rpm -q tftp-server
rpm -q dhcp
umount /dev/sr0
mount /dev/sr0 /var/ftp/asd
sed -i "s/yes/no/g" /etc/xinetd.d/tftp
cd /var/ftp/asd/isolinux
cp vmlinuz initrd.img /var/lib/tftpboot/
cp /root/anaconda-ks.cfg /var/ftp/ks.cfg
chmod 777 /var/ftp/ks.cfg
sed -i "s/cdrom/#cdrom/" /var/ftp/ks.cfg
sed -i "s/url/#url/" /var/ftp/ks.cfg
sed -i "5a url --url=ftp://${name}/asd" /var/ftp/ks.cfg
cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/
cp /var/ftp/asd/isolinux/isolinux.cfg /var/lib/tftpboot/
chmod 644 /var/lib/tftpboot/isolinux.cfg
mkdir /var/lib/tftpboot/pxelinux.cfg
mv /var/lib/tftpboot/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default
sed -i "s/default vesamenu.c32/default linux/" /var/lib/tftpboot/pxelinux.cfg/default
sed -i ‘2a prompt 0‘ /var/lib/tftpboot/pxelinux.cfg/default
sed -i "65a append initrd=initrd.img inst.repo=ftp://${name}/asd inst.ks=ftp://${name}/ks.cfg" /var/lib/tftpboot/pxelinux.cfg/default
rm -rf /etc/dhcp/dhcpd.conf
cat>/etc/dhcp/dhcpd.conf<
option domain-name "example.org";
option domain-name-servers ${name};
default-lease-time 600;
max-lease-time 7200;
subnet ${a} netmask 255.255.255.0 {
range ${b};
option routers ${c};
next-server ${name};
filename "pxelinux.0";
}
EOF
systemctl start tftpsystemctl enable tftp &> /dev/nullsystemctl start dhcpdsystemctl enable dhcpd &> /dev/nullsystemctl start vsftpdsystemctl enable vsftpd &> /dev/null