lang en
network --bootproto static --nameserver 131.225.8.120
nfs --server linux.fnal.gov --dir /export/linux/52test/i386
keyboard us
#zerombr yes
#clearpart --all
#part / --size 1000 
#part /scratch --size 200 --grow
#part swap --size 127
#install
#mouse ps/2
timezone  US/Central
#xconfig --server "XF86_S3" --monitor "generic multisync"
#rootpw tr41n1ng
#lilo --location mbr
#%packages
#@ Base
#@ CDF
%post
MEDIA="NETWORK"
echo "Installing Post Install RPMS" >/dev/tty5
echo "Log file in /tmp/postinstall.log" >/dev/tty5
#
#
PATH=$PATH:/mnt/bin:/mnt/usr/bin:/mnt/sbin:/mnt/usr/sbin
VERSION=52test
#
RUN="chroot /mnt"
#
CHROOT="/mnt"
#
# This is because the rpmrc seems to be in a different place on the install
# floppy vs the "mounted" image.  SO we copy it over
cp /mnt/usr/lib/rpm/rpmrc /usr/lib/rpmrc

# This is for a future feature.  This allows us to have a rpm install of 
# postinstall.sh in /etc and we will use it as the install script vs
# doing it below.  The else part of the if is so that we could also have it
# reside on the install media.  At the moment this is coded so that only
# one of them will be run but maybe we should think about doing them all

if [ -x  $CHROOT/etc/postinstall.sh ]; then
  echo "postinstall.sh is already in /etc" >$CHROOT/etc/postinstall.log	
else
  if [ -x /tmp/rhimage/Fermi/workgroups/scripts/postinstall.sh ] ; then
     cp /tmp/rhimage/Fermi/workgroups/scripts/postinstall.sh  $CHROOT/etc/postinstall.sh 2> $CHROOT/etc/postinstall.log
  fi
fi
# done looking for postinstall.sh in /etc or in
# /tmp/rhimage/fermi/workgroups/scripts so now check for it and then run it.
#  If it is not found then use the inline version below

if [ -x $CHROOT/etc/postinstall.sh ]; then
      $RUN sh $CHROOT/etc/postinstall.sh 
# We only can install ssh via the network if the network is alive
# so we test to see if we can do the network.  This works on a cdrom
# if they have enabled a network
else
   if [ -d /tmp/rhimage/NOTFOREXPORT ] ; then
          /mnt/bin/rpm --root $CHROOT -i /tmp/rhimage/NOTFOREXPORT/*.i386.rpm >& $CHROOT/tmp/postinstall.log
   fi 
   if [ -s $CHROOT/etc/sysconfig/network ] ; then
# if we already have installed ssh we do not want to overwrite the keys so
# we skip it here
      if  [ -s $CHROOT/etc/ssh_host_key ]; then
          echo "ssh keys already exist,  skipping ssh install" > $CHROOT/tmp/postinstall.log
      else
          $RUN /etc/rc.d/init.d/network restart >& /dev/null
          /mnt/bin/rpm --root $CHROOT -i --force ftp://linux-rep.fnal.gov/pub/security/ssh-current.i386.rpm >& $CHROOT/tmp/postinstall.log
      fi
      $RUN  rdate -s 131.225.8.120
      $RUN /sbin/chkconfig xntpd on
      /mnt/bin/rpm --root $CHROOT -i --force /tmp/rhimage/RedHat/RPMS/zz_xntp3_change-*.i386.rpm >> $CHROOT/tmp/postinstall.log 2>&1
   fi
   $RUN /sbin/hwclock --systohc
   $RUN /sbin/chkconfig linuxconf off
#
# Determine which workgroup we are
     if [ -s $CHROOT/etc/workgroup ]; then
        WORKGROUP=`cat $CHROOT/etc/workgroup`
     else
	echo "CUSTOM" > $CHROOT/etc/workgroup
	WORKGROUP=`cat  $CHROOT/etc/workgroup`
     fi
    echo "Fermi Red Hat Linux 5.2.1 installed for $WORKGROUP via the $MEDIA on `$RUN /bin/date`" > /tmp/banner
    cat /tmp/banner /tmp/rhimage/Fermi/banner > $CHROOT/etc/motd
# go and copy all of the $WORKGROUP/* files from /tmp/rhimage which is
# either NFS or the CDROM
    mkdir  $CHROOT/etc/$WORKGROUP 2> /dev/null
    cd $CHROOT/etc/$WORKGROUP
    cp -R /tmp/rhimage/Fermi/workgroups/$WORKGROUP/* .
    cd $CHROOT
    ls etc/$WORKGROUP/RPMS/*.rpm > $CHROOT/tmp/rpmfiles 2> /dev/null
    if [ -s $CHROOT/tmp/rpmfiles ] ; then
      cd $CHROOT/etc/$WORKGROUP/RPMS
      /mnt/bin/rpm --root $CHROOT -U --force --nodeps *.rpm  >& $CHROOT/etc/$WORKGROUP/workgroup.rpm.log
    fi
    cd $CHROOT
    if [ -d etc/$WORKGROUP/RPMSI ] ; then
       ls etc/$WORKGROUP/RPMSI/*.rpm > $CHROOT/tmp/rpmfiles.i 2> /dev/null
       if [ -s $CHROOT/tmp/rpmfiles.i ] ; then
          cd $CHROOT/etc/$WORKGROUP/RPMSI
          /mnt/bin/rpm --root $CHROOT -i --force --nodeps *.rpm  >> $CHROOT/etc/$WORKGROUP/workgroup.rpm.log 2>&1
       fi
    fi  
    touch $CHROOT/etc/$WORKGROUP/after.rpms.log
    if [ -x $CHROOT/etc/$WORKGROUP/scripts/after.rpms.nochroot.sh ] ; then
        $CHROOT/etc/$WORKGROUP/scripts/after.rpms.nochroot.sh  >> $CHROOT/etc/$WORKGROUP/after.rpms.log 2>&1
    else
       echo "No after.rpms.sh found" >> $CHROOT/tmp/after.rpms.log 2>&1
    fi
    if [ -x $CHROOT/etc/$WORKGROUP/scripts/after.rpms.sh ] ; then
       ($RUN /etc/$WORKGROUP/scripts/after.rpms.sh  >> $CHROOT/etc/$WORKGROUP/after.rpms.log 2>&1 )
    else
       echo "No after.rpms.sh found" >> $CHROOT/tmp/after.rpms.log 2>&1
    fi
fi