VERSION=slf58
SECUREFTPSERVER=linux1.fnal.gov
#
CHROOT="/mnt/sysimage/"
RUN="chroot $CHROOT"
INSTALLIMAGE="/mnt/source/"
PATH=$PATH:/$CHROOT/bin:/$CHROOT/usr/bin:/$CHROOT/sbin:/$CHROOT/usr/sbin
if [ -s $CHROOT/tmp/upgrade.log ] ; then
   METHOD=UPGRADE
else
   METHOD=INSTALL
fi
cat /proc/cmdline | grep -q slf5rolling
if [ $? -eq 0 ] ; then
  RELEASE=slf5rolling
else
  RELEASE=$VERSION
fi
echo $RELEASE > /dev/tty5
#determine what media was used to do the install 
SEARCHSTRING=method
for item in `cat /proc/cmdline`
do
   b=`echo $item | grep $SEARCHSTRING`
   if [ -n "$b" ]; then
      #Now get the string after the =
      c=`echo $b | cut -f2 -d"="`
      if [ -n "$c" ]; then
         MEDIA=$c
      else
         MEDIA="UNKNOWN"
      fi
   fi
done

# Run the script that fixes up the kernel-module problem
if [ -x /tmp/updates/fermi/kernel.module.fixup.sh ] ; then
	cp -f /tmp/updates/fermi/kernel.module.fixup.sh $CHROOT/tmp/kernel.module.fixup.sh
	($RUN /tmp/kernel.module.fixup.sh  > $CHROOT//tmp/kernel.module.fixup.log 2>&1 )
fi

export CHROOT
export RUN
export INSTALLIMAGE
export PATH
export METHOD
#echo "Installing Post Install RPMS" >/dev/tty5
echo "Log file in /tmp/postinstall.log" >/dev/tty5

#
# Determine which workgroup we are
if [ -s $CHROOT/etc/workgroup ]; then
   WORKGROUP=`cat $CHROOT/etc/workgroup`
else
   WORKGROUP=`cat  $CHROOT/etc/workgroup`
   echo $WORKGROUP >/dev/tty5
   echo "CUSTOM" > $CHROOT/etc/workgroup
   WORKGROUP=`cat  $CHROOT/etc/workgroup`
fi

echo "Fermi Linux $RELEASE $METHOD for $WORKGROUP via $MEDIA on `$RUN /bin/date`" > /tmp/banner
grep -q "NOTICE TO USERS" $CHROOT/etc/motd
if [ $? -ne 0 ] ; then
   cat $CHROOT/etc/motd $INSTALLIMAGE/Fermi/common/configfiles/fermibanner > /tmp/fermibanner
   cp /tmp/fermibanner $CHROOT/etc/motd
fi
if [ -s $CHROOT/etc/motd.rpmsave ] ; then
   grep "Fermi " $CHROOT/etc/motd.rpmsave > /tmp/fermilinux
   cat /tmp/banner /tmp/fermilinux | uniq > /tmp/bannerlinux
   cp /tmp/bannerlinux /tmp/banner
fi
cat /tmp/banner $CHROOT/etc/motd > /tmp/tmpbanner
cp /tmp/banner $CHROOT/etc/FermiLinuxHistory
cp /tmp/tmpbanner $CHROOT/etc/motd
cd $CHROOT
$RUN touch /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.nochroot.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
cd $CHROOT
if [ -x $CHROOT/etc/$WORKGROUP/scripts/final.after.rpms.sh ] ; then
   ($RUN /etc/$WORKGROUP/scripts/final.after.rpms.sh  > $CHROOT/etc/$WORKGROUP/final.after.rpms.log 2>&1 )
fi
cp /tmp/anaconda.log $CHROOT/root/anaconda.log
cd
