#!/bin/sh
#
# Kick-start post-configuration script, to do the configuration things
# that need to be done.  See also /etc/rc.d/rc.local which may do
# one-time configuration at first reboot, before it replaces itself.
#
# This file is loaded by ks.cfg from the ftp server, not from the floppy.
# The TARBALL specified below is also loaded via ftp, as is rc.local.
#
# Eric Myers <myers@umich.edu> - 14 December 2001
# #(@) $Id: ks.sh,v 1.3 2003/06/26 19:13:50 myers Exp myers $
######################################################################
# @(#) Last changed: -EAM 03Apr2005

TARBALL=kick-me-install.tar

# Be sure no mail daemons are running

service sendmail stop
service postfix stop


####################
# Make custom directories and mount points:

mkdir -p /root/rpm/updates
mkdir -p /floppy/
mkdir -p /cdrom

############
# Configuration changes/cleanup:

cd /etc/cron.daily
  rm 00-logwatch
  chmod -x logrotate

cd /var/spool/rwho
  rm -f *-gig
  rm -f *localhost


####################
# Services (init scripts) for boot time:

chkconfig ypbind off
chkconfig portmap off
chkconfig nfslock off
chkconfig nfs off
chkconfig netfs off
chkconfig amd off

chkconfig ipchains off
chkconfig sendmail off
chkconfig postfix  off

chkconfig wine   off
chkconfig pcmcia off

chkconfig rwhod on
chkconfig ntpd  on

chkconfig condor   off
chkconfig afs      off


####################
# Install and configure autorpm, to use it now, and always

cd /root/rpm
X=`ls -1 autorpm*rpm`
if [ "$X" != "" ]; then
  echo " * Installing autorpm..."
  rpm -Uhv $X
else
  echo " ! Cannot find autorpm package :-( "
fi
echo "  "


##############
# Unpack the tar file (copied by ks.cfg) to quickly configure the system

if [ -f /root/$TARBALL.gz ]; then 
  echo " * Unpacking the tar file $TARBALL ..." 
  gunzip /root/$TARBALL
  cd /  
  tar -xvf /root/$TARBALL
else
  echo " ! Cannot find configuration tarball $TARBALL :-( "
fi
echo "  "


##############
# Put newer rc.local (copied by ks.cfg) in place for first reboot

cd /root
echo "  "
if [ -f rc.local ]; then
  /bin/mv -f rc.local /etc/rc.d/rc.local
  chmod +x /etc/rc.d/rc.local
  echo " * Installed one-shot rc.local from /root" 
fi


####################
# Install locally selected package and update RH/FC packages with autorpm
# (Assumes untar'd Otto-rpm-?.conf files already in place.)

if [  -f /etc/autorpm.d/Otto-rpm.conf  ]; then
  echo " * Updating packages via autrpm..."
  cd /etc/autorpm.d 
  cp autorpm.conf autorpm.conf,ORIG

  # Replace main config file with our own, which uses #'s 5 & 6
  cat <<EOF > autorpm.conf
# /etc/autorpm.d/autorpm.conf created by ks.sh on `date`
# UPDATE FROM PACKAGES COPIED VIA FTP DURING INSTALLATION
Set_Var("ReportDest", "root");
Set_Var("Arch", "i686|i586|i386|noarch");
Set_Var("Lang", "en");
Eval_Var("RHVersion", "sed 's/\(Red Hat Linux \)\?release \([^ ]*\) (.*)/\2/' /etc/redhat-release");
Eval_Var("FedoraVersion", "rpm -q fedora-release | awk -F'-' {'print $3'}");
Report_Queues_To ("\${ReportDest}");

Config_File("/etc/autorpm.d/Otto-rpm-5.conf");	
Config_File("/etc/autorpm.d/Otto-rpm-6.conf");	
Config_File("/etc/autorpm.d/autorpm-updates.conf");	
Config_File("/etc/autorpm.d/openafs.conf");	

#EOF autorpm.conf
EOF

# Invoke autorpm to do the work

  autorpm "auto --print " 

# Now put in place the network version for later

  cp Otto-rpm.conf autorpm.conf

fi 

##########
# Add nsf:/usr/local to the filesystem table to join the club

X=`grep /usr/local /etc/fstab`
if [ "$X" = "" ]; then 
   cat <<EOF >>/etc/fstab
# added by ks.sh on `date`
santiam:/usr/local       /usr/local         nfs     defaults 0 0
EOF
fi


####################
# Prepare for reversible kernel upgrade later by saving this one

KVERS=2.6

cd /boot
mkdir -p Save
/bin/cp -f *${KVERS}* Save/

cd /lib/modules
mkdir -p Save
/bin/cp -rp ${KVERS}* Save/


####################
# Change LILO boot message & #read-only  (though we now use GRUB)

if [ -f /boot/boot.txt ]; then
  cd /etc
  cp lilo.conf lilo.conf.ORIG
  sed -e "s%^message=.*$%message=/boot/boot.txt%" \
      -e "s/[ \t]*read-only/        read-only/" \
      < lilo.conf.ORIG > lilo.conf
  echo " * Modified /etc/lilo.conf, now calling lilo..."
  if [ ! -z /etc/lilo.conf ]; then 
    lilo
  fi
fi



####################
# We are done

chmod -x /root/ks.sh

echo " * ks.sh finished."

exit 0

# EOF
