#!/bin/bash #system OS auto install #Mr.luo #exit 2:not mount system iso pxe_dir=/mnt/images/pxeboot http_dir=/var/www/html dhcp_dir=/etc/dhcp echo "you has config dhcpd.conf." read -p "are you sure to rewrite it,enter y or n: " option option=`echo $option|tr A-Z a-z` while ! [ $option == y -o $option == n -o $option == yes -o $option == no ];do read -p "wrong choose.enter again: " option option=echo $option|tr A-Z a-z done if [ $option == y -o $option == yes ];then echo "dhcp setting..." read -p "enter a dhcp subnet and netmask:" ip_sub net_mask while [ -z $ip_sub ] || [ -z $net_mask ];do read -p "wrong,enter again:" ip_sub net_mask done read -p "enter a dhcp range:" range_begin range_end while [ -z $range_begin ] || [ -z $range_end ];do read -p "wrong,enter again:" range_begin range_end done read -p "enter a dhcp router:" dhcp_router done read -p "enter a dhcp next_server:" next_server while [ -z $next_server ];do read -p "wrong,enter again:" next_server done else ip_sub=`grep subnet -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $2}‘` net_mask=`grep subnet -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $4}‘` range_begin=`grep range -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $2}‘` range_end=`grep range -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $3}‘|sed ‘s/;//‘` dhcp_router=`grep routers -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $3}‘|sed ‘s/;//‘` next_server=`grep next-server -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $2}‘|sed ‘s/;//‘` fi else echo "dhcp setting..." read -p "enter a dhcp subnet and netmask:" ip_sub net_mask while [ -z $ip_sub ] || [ -z $net_mask ];do read -p "wrong,enter again:" ip_sub net_mask done read -p "enter a dhcp range:" range_begin range_end while [ -z $range_begin ] || [ -z $range_end ];do read -p "wrong,enter again:" range_begin range_end done read -p "enter a dhcp router:" dhcp_router while [ -z $dhcp_router ];do read -p "wrong,enter again:" dhcp_router done read -p "enter a dhcp next_server:" next_server while [ -z $next_server ];do read -p "wrong,enter again:" next_server done fi #check dhcp and install it. dhcp_setting () { rpm -q dhcp >> /dev/null || yum install -y dhcp cat << EOF > /etc/dhcp/dhcpd.conf default-lease-time 600; max-lease-time 7200; log-facility local7; subnet $ip_sub netmask $net_mask { range $range_begin $range_end; option routers $dhcp_router; next-server $next_server; filename="pxelinux.0"; } EOF #if you enter wrong parameter,you can config /etc/dhcp/dhcpd.conf. } if grep default-lease-time $dhcp_dir/dhcpd.conf >>/dev/null && grep max-lease-time $dhcp_dir/dhcpd.conf >>/dev/null && grep log-facility $dhcp_dir/dhcpd.co #!/bin/bash #system OS auto install #exit 2:not mount system iso pxe_dir=/mnt/images/pxeboot http_dir=/var/www/html dhcp_dir=/etc/dhcp #dhcp server config #check dhcpd.conf echo "you has config dhcpd.conf." read -p "are you sure to rewrite it,enter y or n: " option option=`echo $option|tr A-Z a-z` while ! [ $option == y -o $option == n -o $option == yes -o $option == no ];do read -p "wrong choose.enter again: " option option=echo $option|tr A-Z a-z done #set dhcp global value if [ $option == y -o $option == yes ];then echo "dhcp setting..." read -p "enter a dhcp subnet and netmask:" ip_sub net_mask while [ -z $ip_sub ] || [ -z $net_mask ];do read -p "wrong,enter again:" ip_sub net_mask done read -p "enter a dhcp range:" range_begin range_end while [ -z $range_begin ] || [ -z $range_end ];do read -p "wrong,enter again:" range_begin range_end done read -p "enter a dhcp router:" dhcp_router done read -p "enter a dhcp next_server:" next_server while [ -z $next_server ];do read -p "wrong,enter again:" next_server done else ip_sub=`grep subnet -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $2}‘` net_mask=`grep subnet -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $4}‘` range_begin=`grep range -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $2}‘` range_end=`grep range -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $3}‘|sed ‘s/;//‘` dhcp_router=`grep routers -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $3}‘|sed ‘s/;//‘` next_server=`grep next-server -m1 $dhcp_dir/dhcpd.conf |awk ‘{print $2}‘|sed ‘s/;//‘` fi else echo "dhcp setting..." read -p "enter a dhcp subnet and netmask:" ip_sub net_mask while [ -z $ip_sub ] || [ -z $net_mask ];do read -p "wrong,enter again:" ip_sub net_mask done read -p "enter a dhcp range:" range_begin range_end while [ -z $range_begin ] || [ -z $range_end ];do read -p "wrong,enter again:" range_begin range_end done read -p "enter a dhcp router:" dhcp_router while [ -z $dhcp_router ];do read -p "wrong,enter again:" dhcp_router done read -p "enter a dhcp next_server:" next_server while [ -z $next_server ];do read -p "wrong,enter again:" next_server done fi #check dhcp and install it. dhcp_setting () { rpm -q dhcp >> /dev/null || yum install -y dhcp cat << EOF > /etc/dhcp/dhcpd.conf default-lease-time 600; max-lease-time 7200; log-facility local7; subnet $ip_sub netmask $net_mask { range $range_begin $range_end; option routers $dhcp_router; next-server $next_server; filename="pxelinux.0"; } EOF #if you enter wrong parameter,you can config /etc/dhcp/dhcpd.conf. } #tftp server check,install and set. tftp_server () { rpm -q tftp-server >> /dev/null || yum install -y tftp-server rpm -q syslinux >> /dev/null || yum install -y syslinux if [ -d /mnt/isolinux ] && [ -d /mnt/images ];then cp -f $pxe_dir/{initrd.img,vmlinuz} /var/lib/tftpboot/ cp -f /mnt/isolinux/{boot.msg,vesamenu.c32,splash.jpg} /var/lib/tftpboot/ #pxelinux file copy cp /usr/share/syslinux/pxelinux.0 /var/lib/tftpboot/ [ -d /var/lib/tftpboot/pxelinux.cfg ] || mkdir /var/lib/tftpboot/pxelinux.cfg cp /mnt/isolinux/isolinux.cfg /var/lib/tftpboot/pxelinux.cfg/default sed -i ‘0,/append\ initrd=initrd.img/ s/append\ initrd=initrd.img/append\ initrd=initrd.img\ ks=http:\/\/‘$next_server‘\/ks.cfg/‘ /var/lib/tftpboot/ pxelinux.cfg/default echo "pxeboot copy finished." else echo "you should mount system iso to /mnt/ first." exit 2 fi } linux_version=`cat /mnt/RELEASE-NOTES-en-US.html |grep title|awk ‘{print $1 $2}‘|awk -F">" ‘{print $2}‘` #system iso http repo iso_web () { rpm -q httpd >> /dev/null || yum install -y httpd [ -d $http_dir/$linux_version ] || mkdir $http_dir/$linux_version mount --bind /mnt/ $http_dir/$linux_version } #config kickstart system_install () { cat << EOF > $http_dir/ks.cfg install url --url="http://$next_server/$linux_version/" lang en_US.UTF-8 keyboard us network --onboot no --device eth0 --bootproto dhcp --noipv6 rootpw --plaintext 123456 authconfig --enableshadow --passalgo=sha512 graphical firstboot --disable bootloader --append="crashkernel=auto rhgb quiet" --location=mbr --driveorder="sda" selinux --disabled logging --level=info reboot timezone --utc Asia/Shanghai zerombr clearpart --all --initlabel part /boot --fstype ext4 --size=100 part swap --fstype swap --size=2048 part pv.01 --size=1 --grow volgroup vg_root pv.01 logvol / --vgname=vg_root --fstype ext4 --size=1 --grow --name=lv_root %packages --nobase @core %end EOF echo "anaconda finished" } dhcp_setting tftp_server iso_web system_install
时间: 2024-10-08 07:18:52