# +----------------------------------------------------------+
# | Postinstall script for ESX3.5
# | Authors:
# | Gabrie van Zanten  http://www.GabesVirtualWorld.com 
# | Arnim van Lieshout  http://www.van-lieshout.com/
# +----------------------------------------------------------+
# +-------------------------------+
# | Begin default ESX 3.5 install |
# +-------------------------------+


# +-----------------------------------------------+
# | Kickstart sectie that will be executed AFTER the %PRE section
# +-----------------------------------------------+

# Regional Settings
keyboard us
lang en_US
langsupport --default en_US
timezone --utc Europe/Amsterdam

# Installatition settings
skipx
mouse none
firewall --disabled

# Unencrypted root password:
rootpw --iscrypted $1$5a17$VQby/1fu4eFKzu5EWkf.c0
reboot
install
url --url http://172.29.26.249/esx/esx301/

# While creating the partitions on the local storage, 
# we want to make sure we're writing on local disk
# The ignoredisk statement tells kickstart to ignore
# the disks in the list

# Remark: This is tested on a HP server. 
# The first local controller on HP is called cciss/c0d0. This can be 
# different in your config. Check this properly !!!!

ignoredisk --drives=sda,sdb,sdc,sdd,sde,sdf,sdg,sdh,sdi,sdj,sdk

# Bootloader options
bootloader --location=mbr --driveorder=cciss/c0d0  

# Authentication
auth --enableshadow --enablemd5

# Partitioning
clearpart --all --drives=cciss/c0d0 --initlabel

part /boot --fstype ext3  --size 1024  --ondisk=cciss/c0d0 
part / --fstype ext3  --size 8192  --ondisk=cciss/c0d0 
part swap   --size 1600  --ondisk=cciss/c0d0 
part /var --fstype ext3  --size 8192  --ondisk=cciss/c0d0 
part /tmp --fstype ext3  --size 8192  --ondisk=cciss/c0d0 
part None --fstype vmkcore  --size 102  --ondisk=cciss/c0d0 
part /home --fstype ext3  --size 2048 --ondisk=cciss/c0d0 

# Reading network configuratie from /tmp/networkconfig. 
# The /tmp/networkconfig file is created in the %PRE section

# Network Configurations
%include /tmp/networkconfig

# VMWare License options
vmaccepteula
vmlicense --mode=server --server=27000@vcenter.mycompany.local --edition=esxFull

%vmlicense_text

%packages
@base


#+-----------------+
#| Begin %PRE      |
#+-----------------+

%pre
# In this %PRE section we first analyze the boot parameters. 
# Therefore the commandline will but cut in parts on each space
# Only the ESXIP and ESXCL parameters will be used

set -- `cat /proc/cmdline`
for I in $*; do case "$I" in *=*) eval $I;; esac; done
echo Found IP address $ESXIP
echo Found Cluster $ESXCL

# Create /tmp/networkconfig file
# Replace 192.168.0. by the first three octets of your Service Console network
# adjust default gateway and nameserver addresses 
# adjust hostname to match your FQDN
cat << EOF >> /tmp/networkconfig
network --device eth0 --bootproto static --ip 192.168.0.${ESXIP} --netmask 255.255.255.0 --gateway 192.168.0.254 --nameserver 192.168.0.2 --hostname vmesx0${ESXIP}.mycompany.local --addvmportgroup=0 
EOF

# Now dumping the ESXIP and ESXCL into /call-esx-postinstall-3.5.sh in order te re-use them later on.
# 192.168.0.ESXIP = ESX host IP
# 192.168.10.ESXIP = VMotion IP

cat << EOF1 >> /call-esx-postinstall-3.5.sh
echo Starting /root/esx-postinstall-3.5.sh
/root/esx-postinstall-3.5.sh 192.168.0.${ESXIP} 192.168.10.${ESXIP} ${ESXCL}
EOF1
chmod a+x /call-esx-postinstall-3.5.sh

#+----------------------+
#| End PRE section     |
#+----------------------+


#+-----------------------------------+
#| Begin %POST --nochroot section|
#+-----------------------------------+

%post --nochroot
cp /call-esx-postinstall-3.5.sh /mnt/sysimage/root/call-esx-postinstall-3.5.sh


#+-----------------+
#| Begin %POST     |
#+-----------------+
     
%post

# +--------------------------------------+
# + Download esx-postinstall-3.5.sh script
# +--------------------------------------+

# 192.168.0.1 is IP of the UDA
lwp-download http://192.168.0.1/scripts/esx-postinstall-3.5.sh /root/esx-postinstall-3.5.sh
chmod a+x /root/esx-postinstall-3.5.sh

# +------------------------------------------+
# + Calling call-esx-postinstall-3.5.sh 
# +------------------------------------------+
echo Calling /tmp/call-esx-postinstall-3.5.sh
/root/call-esx-postinstall-3.5.sh > /root/esx-postinstall-3.5.log 2>&1