#!/bin/bash
read -p "请输入IP地址:" name
iptables -F
systemctl stop firewalld
setenforce 0
yum -y install vsftpd &> /dev/null
[ -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
[ -d /var/lib/tftpboot/pxelinux.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<<EOF
option domain-name "example.org";
option domain-name-servers ${name};
default-lease-time 600;
max-lease-time 7200;
subnet 192.168.200.0 netmask 255.255.255.0 {
range 192.168.200.10 192.168.200.20;
option routers 192.168.200.2;
next-server ${name};
filename "pxelinux.0";
}
EOF
systemctl start tftp.socket
systemctl enable tftp.socket &> /dev/null
systemctl start dhcpd
systemctl enable dhcpd &> /dev/null
systemctl start vsftpd
systemctl enable vsftpd &> /dev/null
echo $? "OK"