#platform=x86, AMD64, or Intel EM64T
key --skip
# System authorization information
auth  --useshadow  --enablemd5 
# System bootloader configuration
bootloader --location=mbr
# Clear the Master Boot Record
zerombr
# Partition clearing information
ignoredisk --drives=sdb,sdc,sdd,hdb,hdc,hdd
clearpart --linux --initlabel --drives=sda
# Use text mode install
text
# Firewall configuration
firewall --enabled --ssh  --trust=eth0
# Run the Setup Agent on first boot
firstboot --disable
# System keyboard
keyboard us
# System language
lang en_US
# Installation logging level
logging --level=info
# Use network installation
url --url=http://192.168.1.51/rhel_64_5.6
# Network information
network --bootproto=dhcp --device=eth0 --onboot=on
# Reboot after installation
reboot
#Root password
rootpw --iscrypted $1$b2bDwXkz$ZpKi4Jx7tox779nrUdt8h1

# SELinux configuration
selinux --permissive
# Do not configure the X Window System
skipx
# System timezone
timezone  America/Chicago
# Install OS instead of upgrade
install
# Disk partitioning information
part / --asprimary --bytes-per-inode=4096 --fstype="ext3" --ondisk=sda --size=30000
part /teleflora --asprimary --bytes-per-inode=4096 --fstype="ext3" --grow --ondisk=sda --size=1
%include /tmp/swapsize
%pre 
DEVICE=""

find_passport ()
{
	passport_device=""

	dev_names=(sda sdb sdc sdd sde)

	for thisdev in ${dev_names[@]}
	do

		# WD (Western Digital) is the vendor
		found=0
		vendor_file="/sys/block/$thisdev/device/vendor"
		if [ -f $vendor_file ]
		then
			exec < $vendor_file
			while read line
			do
				if [[ $line =~ "WD" ]]
				then
					found=1
					break
				fi
			done
		fi
		if [ $found -eq 0 ]
		then
			continue
		fi

		# ... AND Model is correct.
		# Note it is important to look at the model. Some shops
		# could have internal Western digital HDDs. If we were
		# to only look for "WD" drive, and not look for this particular
		# model, then, we could inadvertently use the "real" device
		# as the "backup" device, which would be catastrophic.

		model_file="/sys/block/$thisdev/device/model"
		if [ -f $model_file ]
		then
			exec < $model_file
			while read line
			do
				if [[ $line =~ "My Passport" ]]
				then
					found=1
					break
				fi
			done
		fi
		if [ $found -eq 0 ]
		then
			continue
		fi

		# found a match
		passport_device="/dev/$thisdev"
		break
	done

	DEVICE=$passport_device
}


if [ -d "/sys/block" ]
then
	find_passport
fi

if [ $DEVICE = "/dev/sda" -o \
	$DEVICE = "/dev/sdb" -o \
	$DEVICE = "/dev/sdc" -o \
	$DEVICE = "/dev/sdd" -o \
	$DEVICE = "/dev/sde" ]
then
	# use separate virtual console for output
	VCON=3
	exec < /dev/tty$VCON > /dev/tty$VCON 2>/dev/tty$VCON
	chvt $VCON

	echo
	echo "**********************************************************"
	echo 'Starting Teleflora Kickstart $Revision: 1.18 $'
	echo "**********************************************************"
	echo
	echo
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "!!!!"
	echo "!!!! ERROR! Passport Drive is plugged in as device $DEVICE."
	echo "!!!! Since the assumption is that the passport drive contains"
	echo "!!!! backup data and that data could be destroyed by the"
	echo "!!!! installation, the installation will not proceed."
	echo "!!!!"
	echo "!!!! Please unplug the Western Digital Passport device and"
	echo "!!!! then re-try this kickstart."
	echo "!!!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
	echo
	echo
	echo "Sleeping for 10 seconds... and then rebooting."
	echo
	sleep 10
	reboot
fi

# Section to determine how big to make the swap device based on the amount of ram. RedHat recommends 4gig of swap up to 3gig of memory and (amount of ram) + 2 gig for anything 4gig of ram or over.

memory=`cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | cut -d'k' -f1`
memory="${memory#"${memory%%[![:space:]]*}"}"    # remove leading spaces
memory="${memory%"${memory##*[![:space:]]}"}"    # remove trailing spaces
memoryG=$((memory/1024/1024))  #memory in gig
memoryG2=$((memoryG+2))        #memory in gig + 2gig
remainder=`expr $memoryG2 % 2`
ram=$((memoryG+remainder))     #ram in gig
if [ "$ram" -lt 4 ] ; then
        swap="4096"
else
        swap=$((ram*1024+2048))
fi
echo "part swap    --ondisk=sda --asprimary --size=$swap">/tmp/swapsize
%post 
cat << xxxEOFxxx > /tmp/ksrti.sh
#!/bin/bash
# Script to run, just after a kickstart, which will start things rolling.
if [ \$# -ne 1 ]; then
        echo "Usage ksrti.sh {hostname}"
        exit 1
fi
echo "\`date\` -- Beginning RTI Install \${1}.teleflora.com" >/tmp/verify.txt
hostname \${1}.teleflora.com
ipAdd="\`ifconfig eth0 | grep inet | cut -d":" -f2 | cut -d" "  -f1\`"
echo "\$ipAdd	\${1}.teleflora.com	\$1">>/etc/hosts
sed -i -r -e "s/HOSTNAME=localhost.localdomain/HOSTNAME=\${1}.teleflora.com/g" /etc/sysconfig/network
set -x
wget -O - http://192.168.1.51/ostools/install-ostools.pl | perl - --update
mount /dev/cdrom /mnt
cp /mnt/14_new.tar.gz /tmp
umount /mnt
cd /tmp
#wget http://192.168.1.51/rhel_64_5.6/14_new.tar.gz
gunzip /tmp/14_new.tar.gz
tar xvf /tmp/14_new.tar
gunzip /tmp/RTI-14.3.2-Linux.iso.gz
mount -o loop /tmp/RTI-14.3.2-Linux.iso /mnt
cd /teleflora/ostools/bin
./updateos.pl --baremetal
./updateos.pl --ospatches
./rtibackup.pl --install
./updateos.pl --rti14
cd /mnt
echo "Press enter to continue"
read X
./install_rti-14.3.2.pl --nobbxt --nocryptoback /usr2/bbx
cd /tmp
umount /mnt
cd /tmp
mkdir /home/tfsupport/.ssh
chmod 700 /home/tfsupport/.ssh
chown tfsupport:rti /home/tfsupport/.ssh
yum -y install expect
/tmp/sftp_files.sh
tar xvf /tmp/twofactor-20090723.tar
chmod +x /tmp/*.pl
cp /tmp/tfsupport-authorized_keys /home/tfsupport/.ssh/authorized_keys
chmod 700 /home/tfsupport/.ssh/authorized_keys
chown tfsupport:root /home/tfsupport/.ssh/authorized_keys
cd /usr2/ostools/bin
./rtibackup.pl --install
cd /tmp
/tmp/install_adminmenus.pl --run
gunzip /tmp/delldset_v2.0.0.119_A00.bin.gz
/tmp/dset.sh
rm -f /etc/cron.d/nightly-backup
sed -i -r -e "s/\$ipAdd/192.168.1.21/g" /etc/hosts
service network restart
echo "\`date\` -- End RTI Install \${1}.teleflora.com" >>/tmp/verify.txt
/tmp/verify.sh
echo "Please reboot the system......"
xxxEOFxxx

cat << xxxEOFxxx > /tmp/ksdaisy.sh
#!/bin/bash
# Script to run, just after a kickstart, which will start things rolling.
#if [ \$# -ne 1 ]; then
#        echo "Usage ksdaisy.sh {hostname or shopcode ex:12345678}"
#        exit 1
#fi
echo "\`date\` -- Beginning Daisy Install \${1}.teleflora.com" >/tmp/verify.txt
hostname \${1}.teleflora.com
ipAdd="\`ifconfig eth0 | grep inet | cut -d":" -f2 | cut -d" "  -f1\`"
set -x
wget -O - http://192.168.1.51/ostools/install-ostools.pl | perl - --update
mount /dev/cdrom /mnt
cp /mnt/daisy8.iso.gz /tmp
umount /mnt
cd /tmp
#wget http://192.168.1.51/rhel_64_5.6/daisy8.iso.gz
gunzip /tmp/daisy8.iso.gz
mount -o loop /tmp/daisy8.iso /mnt
cd /teleflora/ostools/bin
./updateos.pl --baremetal
./updateos.pl --ospatches
./rtibackup.pl --install
./updateos.pl --daisy8
cd /mnt
yum -y install expect
/tmp/install_daisy.sh
cd /tmp
umount /mnt
mkdir /home/tfsupport/.ssh
chmod 700 /home/tfsupport/.ssh
chown tfsupport:rti /home/tfsupport/.ssh
/tmp/sftp_files.sh
tar xvf /tmp/twofactor-20090723.tar
chmod +x /tmp/*.pl
cp /tmp/tfsupport-authorized_keys /home/tfsupport/.ssh/authorized_keys
chmod 700 /home/tfsupport/.ssh/authorized_keys
chown tfsupport:root /home/tfsupport/.ssh/authorized_keys
cd /usr2/ostools/bin
./rtibackup.pl --install
cd /tmp
echo "\`date\` -- End Daisy Install \${1}.teleflora.com" >>/tmp/verify.txt
/tmp/verify.sh
reboot
xxxEOFxxx

cat << xxxEOFxxx > /tmp/sftp_files.sh
#!/usr/bin/expect
spawn sftp rtidev@sftp.teleflora.com
expect "(yes/no)?"
send "yes\n";
expect "password:"
send "A3b7iwq\n";
expect "sftp>"
send "cd mservices\n";
expect "sftp>"
send "get twofactor-20090723.tar\n";
expect "sftp>"
send "get tfsupport-authorized_keys\n";
expect "sftp>"
send "bye\n";
interact
xxxEOFxxx

cat << xxxEOFxxx > /tmp/dset.sh
#!/usr/bin/expect
spawn /tmp/delldset_v2.0.0.119_A00.bin
expect "to proceed"
send "q";
expect "of this license? (y/n):"
send "y";
expect "to quit:"
send "4"
expect "new directory path:"
send "\n";
expect "Create? (y/n):"
send "y";
interact
xxxEOFxxx

cat << xxxEOFxxx > /tmp/install_daisy.sh
#!/usr/bin/expect
spawn ./install-daisy.pl /d/daisy
expect "after input ==>"
send "B\n";
expect "after input ==>"
send "YES\n";
expect "8 digit Shop Code\n"
send "${1}";
interact
xxxEOFxxx

cat << xxxEOFxxx >> /tmp/verify.sh
echo "--------------------">>/tmp/verify.txt
echo "ifconfig results....">>/tmp/verify.txt
ifconfig >>/tmp/verify.txt
echo "--------------------">>/tmp/verify.txt
echo "etc/hosts ....">>/tmp/verify.txt
cat /etc/hosts >>/tmp/verify.txt
echo "--------------------">>/tmp/verify.txt
echo "etc/resolve.conf .....">>/tmp/verify.txt
cat /etc/resolv.conf >>/tmp/verify.txt
echo "--------------------">>/tmp/verify.txt
echo "netstat results....">>/tmp/verify.txt
netstat -rn >>/tmp/verify.txt
echo "--------------------">>/tmp/verify.txt
echo "etc/samba/smb.conf .....">>/tmp/verify.txt
cat /etc/samba/smb.conf >>/tmp/verify.txt
echo "--------------------">>/tmp/verify.txt
echo "usr2/basis/basis.lic .....">>/tmp/verify.txt
cat /usr2/basis/basis.lic >>/tmp/verify.txt
echo "--------------------">>/tmp/verify.txt
mail -s \`hostname\` mgreen@teleflora.com,kpugh@teleflora.com,sjackson@teleflora.com </tmp/verify.txt
xxxEOFxxx

cd /tmp
chmod +x /tmp/*.sh

/usr/bin/chage -d 0 root

memory=`cat /proc/meminfo | grep MemTotal | cut -d':' -f2 | cut -d'k' -f1`
memory="${memory#"${memory%%[![:space:]]*}"}"    # remove leading spaces
memory="${memory%"${memory##*[![:space:]]}"}"    # remove trailing spaces
memoryG=$((memory/1024/1024))  #memory in gig
memoryG2=$((memoryG+2))        #memory in gig + 2gig
remainder=`expr $memoryG2 % 2`
ram=$((memoryG+remainder))     #ram in gig
javaram=$((ram/2))	       #jvm max memory in gig
if [ "$ram" -lt 4 ] ; then
        swap="4096"
else
        swap=$((ram*1024+2048))
fi
javaram=$((javaram*1024))
echo "ram=$ram gig,swap=$swap meg,jvm_max=$javaram meg">/tmp/memoryinfo


%packages --resolvedeps
@base
@admin-tools
@printing
@system-tools
@editors
@text-internet
samba
audit
sysstat
vlock
cdrecord
dvd+rw-tools
curl
dialog
mtools
firstboot
e2fsprogs
minicom
slang
mc
strace
net-snmp
procps
compat-libstdc++-33