#!/bin/bash

#安装必备的软件
yum -y install dhcp tftp-server tftp xinetd syslinux vsftpd
yum -y install *kickstart*

#配置kickstart服务器端的DHCP服务
>/etc/dhcpd.conf
#############################################################
cat> /etc/dhcpd.conf< ddns-update-style interim;
ignore client-updates;
next-server 10.1.2.53;
filename "pxelinux.0";

subnet 10.1.2.0 netmask 255.255.255.0 {
        option routers                  10.1.2.1;
        option subnet-mask              255.255.255.0;

        option time-offset              -18000; # Eastern Standard Time
        range dynamic-bootp 10.1.2.100 10.1.2.200;
        default-lease-time 21600;
        max-lease-time 43200;
}

EOF
#####################################################

#修改网卡配置文件并启动DHCP
sed -i 's/^.*IPADDR.*$/IPADDR=10.1.2.53/g' /etc/sysconfig/network-scripts/ifcfg-eth1
sed -i 's/^.*BOOTPROTO.*$/BOOTPROTO=static/g' /etc/sysconfig/network-scripts/ifcfg-eth1
service network restart
service dhcpd restart
#修改tftp配置文件并重启xinetd服务
sed -i 's/^.*disable.*$/disable = no/g' /etc/xinetd.d/tftp
rsync -av /usr/lib/syslinux/pxelinux.0 /tftpboot/
service xinetd restart

#创建必要的目录
mkdir /var/ftp/disk
mkdir /var/ftp/kickstart

#挂载安装光盘
mount /dev/cdrom /var/ftp/disk
service vsftpd restart
#拷贝光盘中网卡启动文件到tftpboot目录下
rsync -av /var/ftp/disk/p_w_picpaths/pxeboot/ /tftpboot/
mkdir -p /tftpboot/pxelinux.cfg

修改网卡启动文件
#####################################################
cat> /tftpboot/pxelinux.cfg/default<
default linux
prompt 1
timeout 30

label linux
  kernel vmlinuz
  append initrd=initrd.img ks=ftp://10.1.2.53/kickstart/ks.cfg
  
EOF
#####################################################
#修改kickstart配置文件,这个文件的内容可以参照root目录下的anaconda-ks.cfg文件内容

cat>/var/ftp/kickstart/ks.cfg< install
text
#nfs --server=10.1.2.53 --dir=/var/ftp/pub/
url --url ftp://10.1.2.53/disk
#key --skip
#key 000000e90007fc00
key 2515dd4e215225dd
#lang en_US.UTF-8
lang zh_CN.UTF-8
keyboard us
network --device eth0 --bootproto dhcp --onboot=on
rootpw 123456
authconfig --enableshadow --enablemd5
firewall --disabled
selinux --disabled
timezone Asia/Shanghai
bootloader --location=mbr --driveorder=sda --append="rhgb quiet clock=pit"
zerombr
clearpart --all --drives=sda --initlabel
autopart
#part / --fstype ext3 --size=1 --grow
#part /var --fstype ext3 --size=2000
#part swap --size=1000
poweroff

%packages
@base
@core
@editors
@text-internet
@web-server
@graphical-internet
@base-x
@chinese-support
@gnome-desktop
libgfortran43
dejagnu
python-docs
gcc43
expect
pexpect
unifdef
kexec-tools
fipscheck
device-mapper-multipath
gtk+
xorg-x11-utils
xorg-x11-server-Xnest
xorg-x11-server-Xvfb
libsane-hpaio
perl-libxml-perl
perl-XML-SAX
perl-LDAP
perl-Convert-ASN1
perl-DateManip
perl-XML-Twig
perl-XML-Grove
perl-XML-Dumper
python-imaging
perl-Crypt-SSLeay
perl-Mozilla-LDAP
perl-Archive-Zip
perl-TimeDate
perl-XML-NamespaceSupport

%post
/usr/sbin/useradd admin
/bin/echo 888888 | sr/bin/passwd admin --stdin
/bin/touch /home/admin/HelloWorld

/sbin/chkconfig auditd off
/sbin/chkconfig autofs off
/sbin/chkconfig avahi-daemon off
/sbin/chkconfig bluetooth off
/sbin/chkconfig cups off
/sbin/chkconfig firstboot off
/sbin/chkconfig gpm off
/sbin/chkconfig haldaemon off
/sbin/chkconfig hidd off
/sbin/chkconfig ip6tables off
/sbin/chkconfig kudzu off
/sbin/chkconfig mcstrans off
/sbin/chkconfig netfs off
/sbin/chkconfig nfslock off
/sbin/chkconfig pcscd off
/sbin/chkconfig portmap off
/sbin/chkconfig restorecond off
/sbin/chkconfig rhnsd off
/sbin/chkconfig rpcgssd off
/sbin/chkconfig rpcidmapd off
/sbin/chkconfig smartd off
/sbin/chkconfig yum-updatesd off

EOF
#####################################################