kickstar 无人值守安装脚本

写了N个小时的脚本终于出来了,第一次写还不成熟,有意见的地方请大家多多指点,还有需要手动填写的地方,如下:

为了不重复循环安装,需要ks输入方可安装。

最后,脚本如下:

#!/bin/bash
/bin/umount /dev/cdrom
/bin/mount /dev/cdrom /media
/bin/sed -i '/ftp/d' /etc/yum.repos.d/rhel-debuginfo.repo 
echo "baseurl=file:///media/Server" >> /etc/yum.repos.d/rhel-debuginfo.repo 
/bin/sed -i '/enabled/s/0/1/' /etc/yum.repos.d/rhel-debuginfo.repo
/usr/bin/yum clean all
/usr/bin/yum -y install dhcp*
read -p "Please import you IP :" ip
read -p "Please import you netmask :" mask
read -p "Please import your route : " route
read -p "Please import your dns :" dns
read -p "Please import your bootp begin :" begin
read -p "Please import your bootp end :" end
read -p "Please import your network section :" section
DHCP="ddns-update-style interim;\n
ignore client-updates;\n
filename \"pxelinux.0\";\n
next-server $ip;\n
subnet $section netmask $mask {\n
        option routers                  $route;\n
        option subnet-mask              $mask;\n
        option nis-domain               \"domain.org\";\n
        option domain-name              \"domain.org\";\n
        option domain-name-servers      $dns;\n
        option time-offset              -18000; # Eastern Standard Time\n
        range dynamic-bootp $begin $end;\n
        default-lease-time 21600;\n
        max-lease-time 43200;\n
}\n"
KS="auth  --useshadow  --enablemd5\n
bootloader --location=mbr\n
zerombr\n
clearpart --all --initlabel\n
key --skip\n
text\n
firewall --disabled\n
firstboot --disable\n
keyboard us\n
lang en_US\n
logging --level=info\n
nfs --server=$ip --dir=/media/\n
network --bootproto=dhcp --device=eth0 --onboot=on\n
reboot \n
rootpw --iscrypted \$1\$OocBdGrz\$npppr3Jgfb2kApufUcW\/t0\n
\n
selinux --enforcing\n
timezone --isUtc Asia/Shanghai\n
install\n
xconfig  --defaultdesktop=GNOME --depth=8 --resolution=640x480\n
part /boot --bytes-per-inode=4096 --fstype=\"ext3\" --size=100\n
part swap --bytes-per-inode=4096 --fstype=\"swap\" --size=512\n
part / --bytes-per-inode=4096 --fstype=\"ext3\" --size=3000\n
\n
%packages       --resolvedeps\n
@base-X\n"

DEFAULT="ks\n
prompt 1\n
timeout 600\n
display boot.msg\n
F1 boot.msg\n
F2 options.msg\n
F3 general.msg\n
F4 param.msg\n
F5 rescue.msg\n
label ks\n
  kernel vmlinuz\n
  append ks=http://192.168.152.129/ks.cfg  initrd=initrd.img\n
label text\n
  kernel vmlinuz\n
  append initrd=initrd.img text\n
label local\n
  localboot 1\n
label memtest86\n
  kernel memtest\n
  append -\n"

echo -e $DHCP > /etc/dhcpd.conf

/etc/init.d/dhcpd restart
/sbin/chkconfig dhcpd on

echo "========tftp=============="
/usr/bin/yum -y install tftp tftp-server
/bin/sed -n '/disable/s/yes/no/p' /etc/xinetd.d/tftp
#/bin/cp -f /media/images/pxeboot/initrd.img /tftpboot/
/bin/cp -rf /media/isolinux/* /tftpboot/
/bin/cp -rf /media/images/pxeboot/vmlinuz /tftpboot/
/bin/mkdir -p /tftpboot/pxelinux.cfg
/bin/cp -rf /media/isolinux/isolinux.cfg /tftpboot/pxelinux.cfg/default
/bin/cp -rf /usr/lib/syslinux/pxelinux.0 /tftpboot/

echo -e $DEFAULT > /tftpboot/pxelinux.cfg/default
/bin/chmod o+w /tftpboot/pxelinux.cfg/default

/sbin/chkconfig tftp on
/etc/init.d/xinted restart

echo "/media/   *(ro)"  > /etc/exports
/sbin/chkconfig nfs on
/etc/init.d/nfs restart

echo "=============http================"
/usr/bin/yum -y install httpd 
/sbin/chkconfig httpd on
/etc/init.d/httpd restart

echo -e $KS > /var/www/html/ks.cfg

echo "finish"
 

 

你可能感兴趣的:(职场,休闲,Kickstar,无人值守安装脚本)