#!/bin/sh
#
# UWMLSC Red Hat 7.3 gc post-install script
# $Id: post-install.sh,v 1.1.1.1 2004/03/23 21:34:48 jspauli Exp $
#
# Initial contributions from hammerd, jspauli, kflasch
#
# Some things this script does:
#  Uses a textual gui
#  Asks user if they want to install globus stuff
#  Asks if this box is a laptop and changes congiguration files accordingly
#  Produces:
#    a general event log (including errors) in /tmp/postinst.log
#    a log of downloaded rpms and config files in /tmp/postist.dload
#    a log of output from the rpm program in /tmp/postinst.rpms
#  In theory the script can be run many times on one box without breaking anything
#  (including itself) assuming no changes have been made to the conf files, etc. 
#

# log files
logfile=/tmp/postinst.log
rpmlogfile=/tmp/postinst_rpms.log
dloadlogfile=/tmp/postinst_dload.log

echo "* post-install error log * created on" `date` > $logfile
echo "* post-install rpm log * created on" `date` > $rpmlogfile
echo "* post-install download log * created on" `date` > $dloadlogfile

# remove printconf
#
echo "removing printconf..."
rpm -e printconf-gui >> $logfile 2>&1
rpm -e printconf/ >> $logfile 2>&1

dialog --backtitle "UWMLSC post-install for Red Hat 7.3" --msgbox "Welcome
to the UWMLSC post-install script. This script will update the 'stock'
install with the latest RPM's and present you with several choices, such
as whether or not to install GSI-enabled ssh. If you are unsure about any
of the options in the script, please contact the admins in person or via
email at admins@gravity.phys.uwm.edu \n\nYou can run this script multiple
times without any adverse effects. \n\nThis script will produce these
logs: \n $logfile \n $rpmlogfile \n $dloadlogfile \n
You may wish to refer to these if you experience difficulties." 20 100 

dialog --backtitle "UWMLSC post-install for Red Hat 7.3" \
--title "Install GSI-enabled ssh?" --yesno "\nDo you want to install 
the GSI-enabled (Globus) ssh packages? If you are unsure, choose yes." 7 60
sshsel=$?

if [ $sshsel -eq 0 ];
then 
EXTRA_RPMS="globus-LSC-server-2.2.2-1.i386.rpm \ 
openssh-3.5p1-2.i386.rpm \
openssh-askpass-3.5p1-2.i386.rpm \
openssh-askpass-gnome-3.5p1-2.i386.rpm \
openssh-clients-3.5p1-2.i386.rpm \
openssh-server-3.5p1-2.i386.rpm \
";
fi

clear
# If you have problems with getting the rpms to install comment out the line 
# "rm -rf /tmp/rpms" change directory to /tmp/rpms and run `rpm -Uvh *` to 
# see what has gone wrong.  Once you have gotten the rpms to intall run the 
# postinstall script again to make sure the config files installed properly.

# rpms with -Uvh
#
EXTRA_RPMS=$EXTRA_RPMS" \
acroread-505-1.i386.rpm \
enscript-1.6.1-19.i386.rpm \
gtk-theme-xfce-3.8.16-1.i386.rpm \
ifhp-3.5.10-1.i386.rpm \
ImageMagick-perl-5.4.3.11-1.i386.rpm \
libPropList-0.10.1-8.i386.rpm \
lynx-2.8.4-18.i386.rpm \
nc-1.10-11.i386.rpm \
ncurses4-5.0-5.i386.rpm \
openmotif21-2.1.30-1.i386.rpm \
opera-6.10-20021029.3-shared-qt.i386.rpm \
qt-devel-3.0.3-11.i386.rpm \
tin-1.22-12.i386.rpm \
transfig-3.2.3d-2.i386.rpm \
vim-X11-6.1-2.i386.rpm \
WebMagick-2.01-1.noarch.rpm \
WindowMaker-0.80.0-9.i386.rpm \
WindowMaker-libs-0.80.0-9.i386.rpm \
Xbae-4.6.2.4-7.i386.rpm \
xfce-3.8.16-1.i386.rpm \
xfig-3.2.3d-3.i386.rpm \
xmgr-dynamic-4.1.2-12.i386.rpm \
xosview-1.7.3-10.i386.rpm \
xv-3.10a-27.i386.rpm \
zsh-4.0.4-5.i386.rpm"

rm -rf /tmp/rpms
mkdir -p /tmp/rpms

#EXTRA_RPMS=""
echo "Getting rpms and logging status in $dloadlogfile"
echo "This could take a few minutes."

for rpm in $EXTRA_RPMS
do 
	`wget -nv -a $dloadlogfile -P /tmp/rpms --http-user install --http-passwd Br1tn3y http://www.lsc-group.phys.uwm.edu/computing/system/linux/rpms_73/${rpm}`
#clear
done
pushd /tmp/rpms
echo "Installing rpms and logging in $rpmlogfile"
sleep 2
rpm -Uvh --force *.rpm 2>&1 | tee -a $rpmlogfile
exstat=$?
clear
echo "rpm exit status was: "$exstat
sleep 2
if [ $exstat -eq 1 ] ;
then
  echo "The rpm installation has failed. Please contact the administrators."
  exit 1;
fi

popd

rm -rf /tmp/rpms >>$logfile 2>&1

dialog --backtitle "UWMLSC post-install for Red Hat 7.3" --yesno "Is
this computer a laptop?" 20 20
sel=$?

if [ $sel -eq 1 ] ;
then
	clear
	echo "copying config files..."
	sleep 1
	for file in sendmail.cf \
		 DIR_COLORS \
		 auto.master \
	 	 auto.mnt \
	         nsswitch.conf \
     	  	 ntp.conf \
       		 ntp/step-tickers \
	      	 profile.d/globus.csh \
		 profile.d/globus.sh  \
		 profile.d/graspada.csh \
		 profile.d/graspada.sh  \
		 printcap
	do
		`wget -nv -a /tmp/postinst.dload -r --cut-dirs=4 -nH -P /etc --http-user install --http-passwd Br1tn3y http://www.lsc-group.phys.uwm.edu/computing/system/linux/config_73/${file}`
		clear
	done
fi

clear

echo "Changing permissions of files"
chmod +x /etc/profile.d/*.sh /etc/profile.d/*.csh >>$logfile 2>&1

echo "Setting up ntp..."
chkconfig --level 345 ntpd on >>$logfile 2>&1

# finish setting up automount
#
echo "Setting up automount..."
rm -f /etc/auto.misc >>$logfile 2>&1
rm -rf /usr/local >>$logfile 2>&1
rm -rf /var/spool/mail >>$logfile 2>&1

echo "Checking for existing symlinks..."
if [ -h /usr/local ] ;
 then 
  echo "Found symlink to /usr/local....REMOVING" | tee -a $logfile
  rm -f /usr/local >>$logfile 2>&1
fi
if [ -h /ldcg ] ;
  then
   echo "Found symlink to /ldcg...REMOVING" | tee -a $logfile
   rm -f /ldcg >>$logfile 2>&1
fi
if [ -h /ldas ] ;
  then 
     echo "Found symlink to /ldas...REMOVING" | tee -a $logfile
    rm -f /ldas >>$logfile 2>&1
fi
if [ -h /ldas_outgoing ] ;
   then
    echo "Found symlink to /ldas_outgoing...REMOVING" | tee -a $logfile
    rm -f /ldas_outgoing >>$logfile 2>&1
fi
if [ -h /data ] ;
  then
   echo "Found symlink to /data...REMOVING" | tee -a $logfile
   rm -f /data >>$logfile 2>&1
fi
if [ -h /var/spool/mail ] ;
  then
   echo "Found symlink to /var/spool/mail...REMOVING" | tee -a $logfile
   rm -f /var/spool/mail >>$logfile 2>&1
fi
if [ -h /scratch ] ;
  then 
   echo "Found symlink to /scratch...REMOVING" | tee -a $logfile
   rm -f /scratch >>$logfile 2>&1
fi
echo "Creating new symlinks..."
ln -sf /mnt/usr_local /usr/local >>$logfile 2>&1
ln -sf /mnt/ldcg /ldcg >>$logfile 2>&1
ln -sf /mnt/ldas /ldas >>$logfile 2>&1
ln -sf /mnt/ldas_outgoing /ldas_outgoing >>$logfile 2>&1
ln -sf /mnt/data /data>>$logfile 2>&1
ln -sf /mnt/mail /var/spool/mail >>$logfile 2>&1
ln -sf /mnt/scratch /scratch >>$logfile 2>&1
ln -sf /home/globus/grid-mapfile /etc/grid-security/grid-mapfile >>$logfile 2>&1

if [ `cat /tmp/postinst.log | grep "error:" | wc -l` -ge 3 ] ;
then
 echo "There were some errors encountered during the post install process."
 echo "Please contact your system administrator and refer them to the log files in /tmp"
else
 echo "Finished. You should now reboot."
fi

