#!/installer/root/bin/sh

echo "[Starting phase 2 installer.]"
cd $SYSTEM

# clear up some space in /
rm -f /tmp/syslog

#### Important environment variables inherited from the miniroot are:
#### SYSTEM, IPADDR, NETMASK, GATEWAY
#### The latter three will not be set if DHCP addressing was used.

# Figure out installer version:
if test -f /usr/ATHINSTALL ; then
  # Extract the install miniroot's version number.
  instversion=`cat /usr/ATHINSTALL`
  echo "[Installer miniroot version ${instversion}.]"
fi

#### Set defaults and useful environment variables.
export TZ=US/Eastern
umask 022
installer=$SYSTEM/installer
instroot=${installer}/root
root=/sysimage
PATH=${instroot}/bin:${instroot}/usr/bin:${instroot}/sbin:${instroot}/usr/sbin:${root}/bin:${root}/usr/bin:${root}/sbin:${root}/usr/sbin:/bin:/sbin:/usr/bin:/etc/athena:/usr/X11R6/bin:$PATH
case "${instversion}" in
  6*) ;;
  *) LD_LIBRARY_PATH=${instroot}/lib:${instroot}/usr/lib:/lib:/usr/lib:/usr/X11R6/lib:
esac
export PATH
export LD_LIBRARY_PATH
export ATHENA_LOGIN_SESSION=$$
defaultboot=linux
forcentfsresize=""
lilotimeout=100
grubtimeout=$((${lilotimeout} / 10))
bootoptions=linux
fstype=ext2
disk_setup=public
create_hibernation_partition=false
rc_public=true
rc_autoupdate=true
retain_tty_logins=false
lba32=false
extraliloopts=""
finalshell=false
convert_sata=auto
bootloadertarget=""
smp=true
dhcp=false
disk=none
diskset=""
hostname=""
# Default filesystem sizes, in MB:
bootsize=30
# Swapsize is determined dynamically; see below.
cachesize=512
mincachesize=128
rootsize=4000
minrootsize=3400
moduleconf=""
xdriver=""
rpm=rpm

# Deal with the old etherboot install media.
if ! test -f /usr/ATHINSTALL ; then
  # Replace /lib/ld-linux.so.2 with something up-to-date so that
  # $instroot binaries can run.
  LD_LIBRARY_PATH=/lib mkdir /lib/lib
  LD_LIBRARY_PATH=/lib ln /lib/ld-linux.so.2 /lib/libc-2.2.2.so \
      /lib/ld-2.2.2.so /lib/libc.so.6 /bin/ash.static /lib/lib 2> /dev/null
  LD_LIBRARY_PATH=/lib cp ${instroot}/bin/mv /lib/lib
  LD_LIBRARY_PATH=/lib cp $instroot/lib/ld-linux.so.2 /lib/ld-linux.so.2.new
  echo "/lib/mv /ld-linux.so.2 /ld-linux.so.2.old ; /lib/mv /ld-linux.so.2.new /ld-linux.so.2 " \
      | LD_LIBRARY_PATH=/lib chroot /lib /lib/ash.static
  rm -r /lib/lib /lib/ld-linux.so.2.old

  # Fix the damage that the etherboot installer has caused.
  echo "Resetting ethernet interface settings..."
  ${instroot}/vortex-diag -w -x 2> /dev/null
  mii-tool -R 2> /dev/null

  # Warn the users.
  printf "\a"
  cat <<EOF

  *********************************************************************
  *********************************************************************
  You are using old (etherboot-based) Linux Athena install media.  This
  software is known to misconfigure the permanent state of some 3com
  ethernet controllers.  We have attempted to repair this
  misconfiguration, but you should discontinue using this install media
  immediately; it will be desupported in the near future.
  *********************************************************************
  *********************************************************************

  To make a new install floppy, run the following on an Athena machine:

    attach bootkit
    cd /mit/bootkit/rhlinux

  ...and then follow the directions in the INSTRUCTIONS file in that
  directory.  Press the return key to continue.






EOF
  read response
fi

# Other config stuff that needs to be after the "etherboot punt"
# section above.
touch /tmp/lilo.addon
touch /tmp/grub.addon
# Figure out the version of Athena we're installing, and set
# the source of the config files appropriately.
athenaversion=`tail -1 $CONTROL | awk '{ print $1 }'`
athrel="${athenaversion%.*}"
passwd=${SYSTEM}/config/${athenaversion}/etc

# Introduce ourselves.
echo "Installing Linux Athena ${athenaversion}."
echo "Install source: ${SYSTEM}/${CONTROL}."
echo "Install started at `date`."

# Choose a default boot loader based on the Athena version.
if [ "${athenaversion%%.*}" -ge 10 -o \
  \( "${athenaversion%%.*}" = 9 -a "${athrel#*.}" -ge 1 \) ]; then
  bootloader=grub
else
  bootloader=lilo
fi

# Set various other variables based on the Athena version.
case ${athrel} in
  9.4)
    rpmopts="--nodeps"
    displayconf=system-config-display
    xconf=/etc/X11/xorg.conf
    moduleconf=/etc/modprobe.conf
    ;;
  *)
    rpmopts=""
    displayconf=redhat-config-xfree86
    xconf=/etc/X11/XF86Config
    moduleconf=/etc/modules.conf
    ;;
esac

# Create the mount point for the install target filesystems.
mkdir ${root} 2> /dev/null

# Answer basic configuration questions, either via research or user
# queries.
response="nil"
if [ -z "$IPADDR" ] ; then
  echo "You do not have a static address configured, so you must do"
  echo "a custom installation.  Press return to continue."
  read response
  response=y
  custom=yes
fi
while [ "$response" = nil ]
do
  echo
  echo "########################################################"
  echo "If you do not select a custom installation, *everything*"
  echo "currently on your disk will be deleted.  A custom install"
  echo "will allow you to create more complex configurations,"
  echo "such as a dual-boot system, which, if done correctly, can"
  echo "retain the data on non-Athena partitions."
  echo "########################################################"
  echo
  echo -n 'Do custom installation?  [Y/n]: '
  read response
  case "$response" in
  xyzzy)
    response=nil ; echo '*POOF*' ; ${instroot}/bin/sh
    ;;
  n*|N*)
    custom=no
    echo
    echo "########################################################"
    echo "You have five seconds to shut down power to this machine"
    echo "before everything currently stored on its disk is lost."
    echo "########################################################"
    sleep 10
    ;;
  *)
    custom=yes
    ;;
  esac
done

#### Find a default installation disk, prompting for a driver if needed.
# Scan for valid IDE disks.
for d in a b c d e f g h i j k l m n o p q r s t ; do
  if grep -q ide-disk /proc/ide/ide*/hd${d}/driver 2> /dev/null; then
    if [ "$disk" = none ] ; then
      disk=hd$d
    fi
    diskset="${diskset} hd$d"
  fi
done
diskset="${diskset} "
# Confirm the choice of disk if there are multiple IDE choices.
if [ "$disk" != none -a "$custom" = yes -a "${diskset}" != " hda " ] ; then
  response=nil
  while [ "$response" = nil ] ; do
    echo "The installer found "$disk" for installation.  Press return to"
    echo "accept this choice, choose another disk from the list below, or"
    echo "enter \"scsi\" to use a SCSI disk instead."
    echo "Options:${diskset}"
    echo -n "Choose: "
    read response
    if [ -z "$response" ] ; then
      :
    elif [ "$response" = scsi ] ; then
      disk=none
    elif echo "${diskset}"|grep -q " $response " ; then
      disk=$response
    else
      echo "Incorrect response."
      response=nil
    fi
  done
fi
# Punt to SCSI if need be.
if [ "$disk" = none ] ; then
  diskset=""
  ds=`grep -E ' sd[a-z]*( |$)| cciss/c[0-9]d[0-9]*( |$)' /proc/partitions | awk '{print $4}'`
  for d in $ds ; do diskset="${diskset} $d" ; done
  diskset="${diskset} "
  if [ "${diskset}" = " " ] ; then
    # This section will only ever be executed if no disk was found by the
    # installer and the user punted on the nice full-screen driver
    # selection provided by anaconda.
    kversion=`uname -r`
    modpath=`echo ${instroot}/lib/modules/$kversion/kernel/drivers`
    while ! grep -q ' sd$' /proc/devices ; do
      echo
      echo "No IDE drive found; a SCSI driver is required to proceed."
      echo "(There is no SMD support in this installer.)"
      echo "Enter the driver name for your SCSI controller, \"?\" for a list"
      echo "of choices, or \"custom\" to escape to a shell prompt so you"
      echo -n "can configure your driver manually: "
      read response
      case "$response" in
      custom)
        echo "Configure your driver, and type Control-D to exit the shell."
        MODPATH=$modpath ${instroot}/bin/sh
        ;;
      '?')
        find $modpath/scsi -type f -print|sed -e 's+.*/++' -e 's/\.o//g' \
	    |sort -u|column
        ;;
      "")
        echo "A driver name or alternative option is required."
        ;;
      *)
        MODPATH=$modpath insmod ${response}
        ;;
      esac
    done
  fi
  if [ "${diskset}" = " sda " ] ; then
    disk=sda
  elif [ "${diskset}" = " cciss/c0d0 " ] ; then
    disk=cciss/c0d0
  else
    response=nil
    while [ "$response" = nil ] ; do
      echo ; echo "You need to choose which SCSI drive you're installing to."
      echo "Choose a disk from the list below, or enter \"none\" to continue"
      echo "without a default disk.  (This will force you to use manual disk"
      echo "partitioning and a custom install.)  Options:${diskset}"
      echo -n "Choose: "
      read response
      if [ "$response" = none ] ; then
        disk=none ; custom=yes
      elif test "$response" && echo "${diskset}"|grep -q " $response " ; then
        disk=$response
      else
        echo "Incorrect response."
        response=nil
      fi
    done
  fi
fi
echo "Using ${disk} for installation."

# Turn off any SATA autoconversion unless we're using /dev/hd*:
if [ "${disk%%hd*}" ] ; then
  convert_sata=no
fi

# Determine swap size based on physical memory.
physmem=`grep MemTotal /proc/meminfo|sed -e 's/ kB$//' -e 's/.*[ 	]//'`
if [ "$physmem" -gt 256000 ] ; then
  swapsize=$((physmem/500))
else
  swapsize=512
fi
echo "Physical memory is $physmem kB, using a swap size of $swapsize MB."

rm /bin/sh
ln -s ${instroot}/bin/sh /bin/sh
${instroot}/dev/MAKEDEV -c ${instroot}/etc/makedev.d -d /dev -S ${disk} \
    | grep -E -v '^chown.*'|sed -e 's/-m 0660 //' > /tmp/makedev.script
/bin/sh /tmp/makedev.script 2>&1 | grep -v ": File exists"
rm /tmp/makedev.script
# Choose a disk partitioning model.
if [ "$custom" = yes ] ; then
  echo "NOTHING HAS BEEN WRITTEN TO DISK YET.  BACKUPS ARE *ALWAYS* A GOOD"
  echo "IDEA.  STOP AND MAKE ONE NOW."; echo
  if [ "$disk" = none ] ; then
    echo "No disk is configured; manual disk partitioning is forced."; echo
    disk_setup=custom
  else
    echo "If you select "1" here, the installation will overwrite *everything*"
    echo "on your installation drive (${disk})."
    echo ; echo 'Installation choices:'
    echo '1: Wipe out the entire disk and install Athena onto it.'
    echo '2: Add an Athena Linux install in unused disk space.'
    echo '3: Manual disk partitioning.'
    echo -n '4: Downsize an existing Windows (NTFS) partition, '
    echo 'making room for Athena.'

    response="nil"
    while [ "$response" = nil ]
    do
      echo -n 'Choose [1-4]: '
      read response
      case "$response" in
      1)
        disk_setup=public
        ;;
      2)
        disk_setup=addon
        ;;
      3)
        disk_setup=custom
        ;;
      4)
        disk_setup=resize
        ;;
      *)
        response=nil
        ;;
      esac
    done
  fi


  echo; echo -n 'Would you like a custom X configuration? [y/N]: '
  read response
  case "$response" in
  y*|Y*)
    custom_x=yes
    ;;
  *)
    custom_x=no
    ;;
  esac

  echo -n 'Would you like to customize your /etc/athena/rc.conf values? [y/N]: '
  read response
  case "$response" in
  y*|Y*)
    echo -n "PUBLIC value for rc.conf <${rc_public}>? "
    read public
    if test -n "${public}"; then
      rc_public=$public
    fi

    if [ "$rc_public" = false ] ; then
      echo -n "AUTOUPDATE value for rc.conf <${rc_autoupdate}>? "
      read autoupdate
      if test -n "${autoupdate}"; then
	rc_autoupdate=$autoupdate
      fi
    fi
    ;;
  esac

  if [ "$IPADDR" ] ; then
    echo "Would you like to use only DHCP addressing?"
    echo -n "(This requires preregistration.)  [y/N]: "
    read response
  else
    echo "You have chosen a DHCP installation."
    response=y
  fi
  case "${response}" in
  y*|Y*)
    dhcp=true
    IPADDR=dhcp
    while [ -z "$hostname" ] ; do
      echo "You must now choose a hostname for your machine."
      echo -n "Enter hostname [no default]: "
      read hostname
    done
    ;;
  esac 

  # Check for possible SATA conversion requirements.
  if [ -z "${disk%%hd*}" -a ${athrel} = 9.4 ] ; then
    s=`echo $convert_sata|tr a-z A-Z`
    t=`echo 'yes/no/auto'|sed -e "s+$convert_sata+$s+"`
    echo
    echo 'Would you like to force conversion to SATA drivers after the'
    echo 'installation is complete?  This is necessary if you are installing'
    echo 'with legacy ATA/IDE support turned on but Athena 9.4 will provide'
    echo -n "native SATA support.  [$t]: "
    
    read response
    case "$response" in
    "")
      ;;
    y*|Y*)
      convert_sata=yes
      ;;
    n*|N*)
      convert_sata=no
      ;;
    auto|AUTO)
      convert_sata=auto
      ;;
    esac
    echo "Set convert_sata to $convert_sata."
  fi

  echo
  echo -n 'Would you like to select any advanced install options? [y/N]: '
  read response
  case "$response" in
  y*|Y*)
    echo
    echo "The default boot loader for the Athena release you are installing"
    echo "is ${bootloader}, installed in the MBR of the disk containing either"
    echo "your boot partition (if you have one), or your root partition (otherwise)."
    echo -n "Would you like a different boot loader configuration? [y/N]: "
    read subresponse
    case "${subresponse}" in
    y*|Y*)
      subsubresponse="nil"
      while [ "$subsubresponse" = nil ]; do
        echo ; echo "Boot loader choices:"
        echo "1: Grub.  (Recommended.)"
        echo "2: LILO."
        echo "3: Custom.  (You'll get a shell when the install completes to roll your own.)"
        echo "4: None.  (No boot loader at all.  Your linux partition WILL NOT BE BOOTABLE"
        echo "           without further external intervention.)"
        echo -n "Choose [1-4]: "
        read subsubresponse
        case "$subsubresponse" in
        1)
          bootloader=grub
          ;;
        2)
          bootloader=lilo
          ;;
        3)
          bootloader=custom
          ;;
        4)
          bootloader=none
          ;;
        *)
	  echo "Invalid selection, try again."
          subsubresponse=nil
          ;;
        esac
      done
      if [ "${bootloader}" = lilo -o "${bootloader}" = grub ] ; then
        echo
        echo "The default boot loader location is the Master Boot Record of your primary"
        echo "disk.  You can also choose to install it on your boot (if it exists) or"
        echo "root (otherwise) partition, which will enable you to configure another boot"
        echo "loader in the MBR which will then invoke the linux boot loader,"
        echo "or even somewhere entirely different."
        echo "Selecting this option usually means your system WILL NOT BOOT into Athena"
        echo "linux without additional work."
        echo ; echo "Would you like to use a non-default boot loader location"
        echo -n "instead of the MBR of the boot/root disk? [y/N]: "
        read subresponse
        case "${subresponse}" in
        y*|Y*)
	  bootloadertarget="custom"
	  echo "You will be prompted for the boot loader location after"
	  echo "disk formatting."
          ;;
        esac
      fi
      ;;
    esac # End of boot loader questions.
    if [ "${bootloader}" != custom ] ; then
      echo
      echo "Would you like a shell after the install is done?"
      echo "(This will enable you to make any changes your system might require"
      echo -n "which are not directly supported by this installer.)  [y/N]: "
      read subresponse
      case "${subresponse}" in
      y*|Y*)
        finalshell=true
        ;;
      esac 
    fi
    echo

    # Newer versions of Athena default to using SMP and automatically install it.
    echo "**NOTE**: the default is now to use SMP by default!"
    if [ "${athenaversion%%.*}" -ge 10 -o \
      \( "${athrel}" = 9.4 -a "${athenaversion##*.}" -ge 45 \) ]; then
      echo -n "Would you like to automatically boot the the multiprocessor kernel? [Y/n]: "
    else
      echo -n "Would you like to install and boot from a multiprocessor kernel? [Y/n]: "
    fi
    read subresponse
    case "${subresponse}" in
    n*|N*)
      smp=false
      ;;
    esac 
    echo
    echo -n "Would you like to enable tty logins? [y/N]: "
    read subresponse
    case "${subresponse}" in
    y*|Y*)
      retain_tty_logins=true
      ;;
    esac 
    subresponse=x
    while [ "$subresponse" ] ; do
      echo
      echo "Swap size is currently $swapsize MB.  Press return to accept this"
      echo -n "value or enter something different [$swapsize]: "
      read subresponse
      if [ "$subresponse" ] ; then
        if [ "$subresponse" -gt 1 ] 2> /dev/null ; then
          swapsize=$subresponse
        else
          echo "Invalid entry; please enter the number of MB only."
        fi
      fi
    done
#    if [ "$disk_setup" = public ] ; then
#      echo
#      echo -n "Would you like to install a laptop hibernation partition? [y/N]: "
#      read subresponse
#      case "${subresponse}" in
#      y*|Y*)
#        create_hibernation_partition=true
#      ;;
#      esac 
#    fi
  ;;
  esac # End of advanced install options.
fi

#### Fetch some important files out of the installer and install them
#### in the miniroot.
if [ "$instversion" ] ; then
  # Put the rpm library stuff where rpm can find it; in the (static) /lib
  # in the miniroot /usr/lib/rpm points to /usrlibrpm, which we can
  # actually create.
  ln -sf ${instroot}/usr/lib/rpm /usrlibrpm
else
  # Assume we're running the old etherboot-based installer;
  # create symlinks for some required libraries (not on the corresponding
  # miniroot) which are needed for various install tools.
  # We don't warn the users here, because now it's done above.
  ln -sf ${instroot}/bin/bash /bin/bash
  ln -sf ${instroot}/lib/libtermcap.so.2.0.8 /usr/lib/libtermcap.so.2
  ln -sf ${instroot}/lib/libext2fs.so.2.4 /lib/libext2fs.so.2
  ln -sf ${instroot}/lib/libcom_err.so.2.0 /lib/libcom_err.so.2
  ln -sf ${instroot}/lib/libuuid.so.1.2 /lib/libuuid.so.1
  ln -sf ${instroot}/lib/libnss* /lib
  ln -sf ${instroot}/lib/libm.so.6 /lib/libm.so.6
  ln -sf ${instroot}/lib/libpthread.so.0 /lib/libpthread.so.0
  ln -sf ${instroot}/lib/ld-linux.so.2 /lib/ld-linux.so.2
  ln -sf ${instroot}/lib/libe2p.so.2 /lib/libe2p.so.2
  ln -sf ${instroot}/lib/libdl.so.2 /lib/libdl.so.2
  ln -sf ${instroot}/usr/lib/rpm /usr/lib/rpm
fi

# The rest we need regardless.
cp ${instroot}/etc/passwd /etc/passwd
cp ${instroot}/etc/group /etc/group
rm -f /etc/nsswitch.conf
cp ${installer}/nsswitch.conf /etc/nsswitch.conf

#### Partition and format the disk.

### Downsize an NTFS partition and then fall through to "addon".
if [ "$disk_setup" = resize ]; then
  echo; 
  printf "\a"
  echo "NTFS RESIZE INSTALL WARNING:"
  echo "This is experimental, and may very well trash your entire"
  echo "machine.  Make SURE you have backups of anything you care about."
  echo -n "Press return to continue, or reboot to abort: "
  read response
  echo

  # Some of the following partition geometry mangling code is copied from
  # the "disk=addon" block below; refer there for detailed commentary.

  # Dump the existing partition table.
  sfdisk -d -uS /dev/${disk} > /tmp/partitioning.old
  p=`sort -n -t= +2 /tmp/partitioning.old|grep 'Id= [7bcef]' \
      |tail -1|sed -e 's/ .*//'`

  # Punt if there are no appropriate partitions or if there's a derelict
  # Athena install.
  if [ -z "$p" ] ; then
    echo
    echo "There are no NTFS partitions on your primary disk ($disk)."
    echo
    echo -n "Press return to proceed to manual disk partitioning: "
    read response
    disk_setup=custom
  fi    
  # Punt if there are extended partitions hanging around, which we
  # assume to be remains of an old Athena install.
  if grep -E 'Id= 5|Id=85' /tmp/partitioning.old ; then
    echo "Your disk has one or more extended partitions, likely from"
    echo "an old Linux Athena or Linux install, so the installer will not"
    echo "automatically create more for you."
    echo
    echo "You can, however, replace this with a new Linux Athena install."
    echo -n "Press return to proceed: "
    read response
    disk_setup=addon
  fi
fi
if [ "$disk_setup" = resize ]; then
  # Grub around for disk geometry information for the calculations below.
  kbperdisk=`sfdisk -s /dev/${disk}`
  cylperdisk=`sfdisk -uS -g /dev/${disk}|awk '{OFMT="%.f"; print $2}'`
  headsperdisk=`sfdisk -uS -g /dev/${disk}|awk '{OFMT="%.f"; print $4}'`
  secpertrack=`sfdisk -uS -g /dev/${disk}|awk '{OFMT="%.f"; print $6}'`

  # Calculate some more useful numbers.
  secperdisk=`echo $cylperdisk\*$headsperdisk\*$secpertrack|bc`
  secpercyl=`echo $headsperdisk\*$secpertrack|bc`
  kbpercyl=`echo $kbperdisk/$cylperdisk|bc`
  bpersec=`echo $kbpercyl\*1024/$secpercyl|bc`

  poldsize=`grep $p /tmp/partitioning.old|sed -e 's/.*size= *//' -e 's/,.*//'`
  poldsizeb=`echo $poldsize\*$bpersec|bc`
  # s is the required shrinkage, in MB.
  s=`echo $rootsize+$cachesize+$swapsize+1000|bc`

  echo "Calculating NTFS parameters..."
  ntfsresize -f -i $p > /tmp/ntfs.info
  pntfsold=`grep 'Current volume size' /tmp/ntfs.info \
      | sed -e 's/.*: //' -e 's/ .*//' `
  pntfsdevold=`grep 'Current device size' /tmp/ntfs.info \
      | sed -e 's/.*: //' -e 's/ .*//' `
  pntfsmin=`grep 'You could resize at' /tmp/ntfs.info \
      | sed -e 's/You could resize at //' -e 's/ .*//' `

  # Push s up to half of the NTFS partition size if it's smaller.
  i=`echo "($pntfsold)/2000000"|bc`
  if [ $i -gt $s ] ; then
    echo "Upgrading requested Athena partition size from $s MB to $i MB."
    s=$i
  fi

  # Loop until we punt or come up with a workable disk layout.
  disk_setup=resize_pending
  while [ "$disk_setup" = resize_pending ] ; do

    # Calculate the differential geometry for the new disk layout.
    scyl=`echo $s*1024/$kbpercyl|bc`
    ssec=`echo $scyl\*$secpercyl|bc`
    skb=`echo $scyl\*$kbpercyl|bc`

    pnewsize=`echo $poldsize-$ssec|bc`
    pnewsizeb=`echo $pnewsize\*$bpersec|bc`
    pntfsnew=`echo $pnewsize\*$bpersec-512|bc`

    sed -e "/${p##*/}/s/$poldsize/$pnewsize/" \
	/tmp/partitioning.old > /tmp/partitioning.new

#    echo "$p: current size $poldsize sectors."
#    echo "$p: downsizing by $s MB, $scyl cylinders, $ssec sectors, $skb kb."
#    echo "$p: new size $pnewsize sectors, $pnewsizeb bytes."
#    echo "$p NTFS  minimum size is $pntfsmin bytes."
#    echo "$p NTFS      old size is $pntfsold bytes."
#    echo "$p partition old size is $pntfsdevold bytes (via ntfs code)."
#    echo "$p partition old size is $poldsizeb (via sfdisk and math)."
#    echo "$p NTFS      new size is $pntfsnew bytes."
#    echo "$p partition new size is $pnewsizeb bytes."

    # Calculate prettier numbers in MB for user information.
    # Note that we're using 1MB=1024*1024B, which is different from
    # modern convention, to be consistent with the calculations above.
    i=`echo "($pntfsold-$pntfsmin)/1048576"|bc`
    j=`echo $minrootsize+$mincachesize+$swapsize|bc`
    k=`echo "$pntfsold/1048576"|bc`
    l=`echo "$pntfsnew/1048576"|bc`
    m=`echo "($pntfsold-$pntfsnew)/1048576"|bc`
    n=`echo "$pntfsmin/1048576"|bc`

    echo
    echo "$p current NTFS size:        $k MB"
    echo "$p requested NTFS size:      $l MB"
    echo "$p requested NTFS shrinkage: $m MB"
    echo "$p min possible NTFS size:   $n MB"
    echo "$p possible NTFS shrinkage:  $i MB"
    echo
    echo "Note that, due to disk geometry conversion factors and,"
    echo "rounding errors, values are approximate to within a few MB."

    # The purpose of the next three lines is solely to obtain an
    # arithmetical comparison of pntfsnew and pntfsmin without overflowing
    # test(1).
    echo $pntfsnew > /tmp/c
    echo $pntfsmin >> /tmp/c
    if [ `sort -n /tmp/c|head -1` != "$pntfsmin" ] ; then
      echo
      echo "The installer is trying to shrink your NTFS filesystem by $m MB"
      echo "(out of $k MB total), while the filesystem can only actually be"
      echo "shrunk by $i MB.  A absolute  minimum Linux Athena install"
      echo "requires $j MB, while significantly more (at least 10GB)"
      echo "is greatly preferable."
      echo
      echo "You can try entering a smaller value in MB, or switch to a"
      echo "manual disk layout.  (Note that any unused space on the disk"
      echo "directly after your NTFS partition will also be used together"
      echo "with any shrinkage you specify.)"
      echo
      echo "Enter a number (only) of MB to allocate to Athena, or just"
      echo -n "press return to switch to manual disk layout: "
      read response
      while [ "`echo "$response"|sed -e 's/[0-9]*//'`" ] ; do
	echo -n "Invalid input; enter a number ONLY, or just press return: "
	read response
      done
      case "$response" in
      "") 
        disk_setup=custom
	;;
      *)
        s=$response
	;;
      esac
    else
      echo "Disk geometry looks OK.  Press return to accept, or enter a"
      echo -n "new value for NTFS shrinkage in MB: [accept] "
      read response
      while [ "`echo "$response"|sed -e 's/[0-9]*//'`" ] ; do
	echo -n "Invalid input; enter a number ONLY, or just press return: "
	read response
      done
      case "$response" in
      "") 
        disk_setup=resize
	;;
      *)
        s=$response
	;;
      esac
    fi  
  done
fi
if [ "$disk_setup" = resize ]; then
  echo "Starting ntfsresize dry run..."
  if ! ntfsresize -n -s $pntfsnew $p ; then
    echo
    echo "The ntfsresize dry run has failed.  (See the error message above.)"
    echo "You can attempt to force the resize anyway, or switch to a"
    echo -n "manual install.  Would you like to force the issue? [y/N]: "
    read response
    case "${response}" in
    y*|Y*)
      forcentfsresize="-f"
      ;;
    *)
      disk_setup=custom
      ;;
    esac
  fi
  if [ "$disk_setup" = resize ]; then
    echo "Resizing NTFS partition..."
    if ntfsresize $forcentfsresize -s $pntfsnew $p ; then
      echo "Resize succeeded; installing new partition table."
      sfdisk -uS -f /dev/${disk} < /tmp/partitioning.new
      disk_setup=addon
    else
      echo "The NTFS resizing has failed.  (See the error message above.)"
      disk_setup=custom
    fi
  fi
  if [ $disk_setup = custom ] ; then
    echo
    echo "If you continue with the install, you will be prompted to format"
    echo "your disk manually.  You can also manually use the ntfsresize"
    echo "program at that point to shrink your filesystem."
    echo
    echo -n "Press return to continue:"
    read response
  fi
fi

### Semiautomated add-on disk layout:

# Find a suitable logical partition, create an extended partition on it,
# and then create our partitions on logcal partitions numbers 5-7.  Punt to
# a custom install if there's already an extended partition and the user
# doesn't want to replace it with an Athena install.

if [ "$disk_setup" = addon ]; then

  # Find the first free partition tag.
  epartition=1
  while grep -Eq ${disk}${epartition}'( |$)' /proc/partitions ; do
    epartition=$(($epartition+1))
  done

  # Check for extended partitions that we might want to replace rather
  # than creating anew.
  p=1
  while [ "$p" -le 4 ] ; do
    i=`${instroot}/sbin/sfdisk -c /dev/${disk} ${p} | tail -1`
    if [ "$i" = 5 -o "$i" = 85 ] ; then
      echo
      echo "You already have an extended partition, ${disk}${p}."
      echo "If you have previously performed a dual-boot Athena Linux install,"
      echo "this is probably the partition created for that installation."
      echo -n "Would you like to replace it with a fresh Athena Linux install? [Y/n] "
      read response
      case "$response" in
      "n"|"N")
	disk_setup=custom
	epartition=0 # Avoid triggering the next block.
	;;
      *)
	epartition=$p
	;;
      esac
      break
    fi
    p=$(($p+1))
  done

  # If there aren't any primary partitions available, we should ship them 
  # off to the land of manual partitioning.
  if [ $epartition -gt 4 ] ; then
    echo "All primary partitions are already in use."
    echo "You'll have to partition the disk manually."
    disk_setup=custom
  fi

  # If we're not nuking an existing partition, then confirm
  # that there are no extended partitions hanging around.
  # This should never happen, unless there's a type of extended partition
  # that we fail to detect.
  if ! grep -Eq ${disk}${epartition}'( |$)' /proc/partitions ; then
    i=5
    while [ $i -le 16 ] ; do
      if grep -Eq ${disk}${i}'( |$)' /proc/partitions ; then
	echo
	echo "Your install disk currently has logical partitions based"
	echo "on an extended partition which the installer is not currently"
	echo "set to replace, and the installer can't cope with that."
	echo "You'll need to partition your disk manually."
	disk_setup=custom
	break
      fi
      i=$(($i+1))
    done    
  fi  

  # Proceed with the actual addon install if disk_setup has not been reset.
  if [ "$disk_setup" = addon ]; then
    echo "Found install partition $epartition."
    # Dump the old partition table, stripping any logical partitions.
    echo "Dump of original partition table follows:"
    sfdisk -d -uS /dev/${disk}
    sfdisk -d -uS /dev/${disk}| \
       grep -E -v "dev/${disk}[5-9]|dev/${disk}[0-9][0-9]" > /tmp/partitioning.old
    echo "Old partition table stripped of logical partitions:"
    cat /tmp/partitioning.old
    # Figure out our start sector and other disk geometry info,
    # since sfdisk often does the wrong thing by default.
    # Note that 'sfdisk -s' output is in kB (!!!) regardless of argument.
    # We use bc or awk for disk geometry math because the shell will overflow.

    # Grub around for disk geometry information for calculations below.
    kbperdisk=`sfdisk -s /dev/${disk}`
    cylperdisk=`sfdisk -uS -g /dev/${disk}|awk '{OFMT="%.f"; print $2}'`
    headsperdisk=`sfdisk -uS -g /dev/${disk}|awk '{OFMT="%.f"; print $4}'`
    secpertrack=`sfdisk -uS -g /dev/${disk}|awk '{OFMT="%.f"; print $6}'`

    # Calculate some more useful numbers.
    secperdisk=`echo $cylperdisk\*$headsperdisk\*$secpertrack|bc`
    secpercyl=`echo $headsperdisk\*$secpertrack|bc`
    kbpercyl=`echo $kbperdisk/$cylperdisk|bc`
    swapcyl=`echo $swapsize\*1024/$kbpercyl+1|bc`
    cachecyl=`echo $cachesize\*1024/$kbpercyl+1|bc`

    # Use the existing extended partition, or find numbers for a new one
    # if it doesn't.
    if grep -Eq ${disk}${epartition}'( |$)' /proc/partitions ; then
      # Use data from old partition.
      echo "Reusing existing extended partition."
      epartitionspec=`grep dev/${disk}${epartition} /tmp/partitioning.old | \
	  sed -e 's/.*start= *//' -e 's/ size=//' -e 's/, ID*//'`
      esecstart=${epartitionspec%,*}
      esecsize=${epartitionspec#*,}
    else
      # Find the starting sector and size by sorting the partitions by
      # starting sector and finding the largest hole.
      echo "Creating new extended partition."
      epartitionspec=`sed -e 's/\(start=\|size=\)/\1 /g' /tmp/partitioning.old | \
        sort -n -k 4 | \
        awk -F '[, =]*' -v "secpercyl=$secpercyl" -v "secperdisk=$secperdisk" \
          'BEGIN	  { prev_end = 0;
		    best_start = 0;
		    best_size = 0;
		  }
	  /^\/dev/  { start = $4;
		    end = $4 + $6;
		    if (end % secpercyl != 0)
		      end = end - (end % secpercyl) + secpercyl;
		    hole_size = $4 - prev_end;
		    if (hole_size > best_size) {
		      best_start = prev_end;
		      best_size = hole_size;
		    }
		    prev_end = end;
		  }
	  END	  { hole_size = secperdisk - prev_end;
		    if (hole_size > best_size) {
		      best_start = prev_end;
		      best_size = hole_size;
		    }
		    printf "%d,%d", best_start, best_size;
		  }'`
      esecstart=${epartitionspec%,*}
      esecsize=${epartitionspec#*,}
      # Create an extended partition filling the rest of the disk:
      echo "${esecstart},${esecsize},5"|sfdisk -uS -f /dev/${disk} -N $epartition
    fi

    # Dump the new partition table, stripping any logical partitions:
    sfdisk -d -uS /dev/${disk}| \
       grep -E -v "dev/${disk}[5-9]|dev/${disk}[0-9][0-9]" \
       > /tmp/partitioning.new

    # Create logical partitions for swap, cache, and root.
    # There is NO boot partition for this install.
    # sfdisk does not seem able consitently to make
    # partitions begin and end on a cylinder boundary
    # so we FORCE it to.
    swapsecsize=`echo $swapcyl\*$secpercyl-$secpertrack|bc`
    cachesecsize=`echo $cachecyl\*$secpercyl-$secpertrack|bc`
    swapsecstart=`echo $esecstart+$secpertrack|bc`
    echo "$swapsecstart,$swapsecsize,82" >> /tmp/partitioning.new
    cachesecstart=`echo $swapsecstart+$swapsecsize+$secpertrack|bc`
    echo "$cachesecstart,$cachesecsize,83" >> /tmp/partitioning.new
    rootsecstart=`echo $cachesecstart+$cachesecsize+$secpertrack|bc`
    echo "$rootsecstart,,83" >> /tmp/partitioning.new
    if [ -z "${disk%%cciss*}" ]; then
      swappartition=${disk}p5
      cachepartition=${disk}p6
      rootpartition=${disk}p7
    else
      swappartition=${disk}5
      cachepartition=${disk}6
      rootpartition=${disk}7
    fi
    bootpartition=${rootpartition}
    # Install the new partition table.
    sfdisk -uS -f /dev/${disk} < /tmp/partitioning.new

    # Check free space.
    if [ `sfdisk -s /dev/${rootpartition}` -lt $((minrootsize*1000)) ] ; then
      echo "The disk has been partitioned, but the space available"
      echo "for the Linux Athena install is insufficient.  You'll"
      echo -n "have to redo it manually.  Press return to continue: "
      disk_setup=custom
      read response
    fi
  fi
fi

### Manual disk setup:
while [ "$disk_setup" = custom ] ; do
cat <<EOF

You must now partition (and configure, if necessary) a local disk,
creating partitions for the root, swap, and AFS cache filesystems.  Then,
when prompted, enter the partition names for each of the above
filesystems.  Suggested sizes are:

boot: ${bootsize}MB    (if applicable)
swap: ${swapsize}MB   (or more, as required)
cache: ${cachesize}MB   ($mincachesize at a minimum)
root:  ${rootsize}+MB ($minrootsize at an *absolute* minimum; see below)

Note that the the required size for the root partition *will* get larger
with future Athena releases, and you should choose a root partition which
is as large as feasible to accommodate this and any additional software
or local file storage you wish to add.

EOF
if [ "${bootloader}" = lilo ] ; then
  cat <<EOF

In addition, since you are installing using the LILO boot loader (pre-9.1
Athena or by custom selection), if your disk is larger than about 8GB,
you need to do one of the following:

- ensure that your root partition is wholly within the first 8GB of the disk.
- create a separate boot partition (/boot) which is wholly within the
  first 8GB of the disk.
- on machines with a relaatively modern BIOS (post-1998 or so), set the
  lba32 option in your lilo.conf.  (You will be prompted for this later.)
EOF
fi
cat <<EOF

Here is a shell.  Run fdisk on the disk or disks on which you wish
to create the partitions for the Athena Linux install.  (You can also use
the "insmod" command to load drivers for additional disk types.)
*** Remember that what you type is being saved in the install.log file.
Example: "fdisk /dev/hda".  Type Control-D to exit the shell.
EOF
  MODPATH=$modpath ${instroot}/bin/sh
  echo "Now, enter the names of the partitions you have just created:"
  echo "(Example: hda1)"
  echo -n "Enter boot partition name, if any [none]: "
  read bootpartition
  echo -n "Enter root partition name: "
  read rootpartition
  echo -n "Enter swap partition name: "
  read swappartition
  echo -n "Enter cache partition name: "
  read cachepartition

  if [ "${bootloader}" = lilo ] ; then
    echo -n "Do you require the lba32 option to lilo?  [y/N]: "
    read response
    if [ "${response}" = y -o "${response}" = Y ] ; then
      lba32=true
    else
      lba32=false
    fi
  fi

  if [ -z "${bootpartition}" ] ; then
    bootpartition=${rootpartition}
  fi

  partitioning_state=ok
  echo "You have selected:"
  if [ "$bootpartition" != "$rootpartition" ] ; then
    echo "  boot partition: $bootpartition"
  fi
  echo "  swap partition: $swappartition"
  echo "  cache partition: $cachepartition"
  echo "  root partition: $rootpartition"
  if [ "${lba32}" = true ] ; then
    echo "LILO's lba32 option WILL be set."
  fi
  disk=${bootpartition%%[0-9]*}

  # Perhaps more sophisticated checking is called for here...
  for p in "$swappartition" "$cachepartition" "$rootpartition" "$bootpartition" ; do
    if [ -z "$p" ] || ! awk '{print $4}' < /proc/partitions|grep -q "^${p}$"; then
      partitioning_state=bad
      echo "Partitioning error: $p does not exist!"
    fi
  done
  if [ "${partitioning_state}" = bad ] ; then
    echo "One or more of the partitions you specified above does not exist."
    echo -n "Press return to try again... "
    read response
  else
    echo -n "Is this OK? [Y/n]: "
    read response
    case "$response" in
    ""|y*|Y*)
      disk_setup=done
      ;;
    esac
  fi
done

### Disk setup for the default whole-disk cluster install:
if [ "$disk_setup" = public ]; then
  # Just use the default public setup, using the entire disk.
  # ...except for saving any magic Dell partition.
  if [ "$create_hibernation_partition" = true ] ; then
    # Determine hibernation partition size.  There's no good way to get the
    # amount of video ram, so we use 256MB for that plus an extra 5MB to account for
    # random slop, fencepost issues, and whatever else.
    hibernate_size=`grep MemTotal /proc/meminfo | sed -e 's/.*:[ 	]*//' \
	-e 's/ .*/\/1024+261/'|bc`
    sed -e "2s/.*/,$hibernate_size,16/" -e '3s/.*/,,5/' \
	${installer}/partitions.sfdisk \
	| ${instroot}/sbin/sfdisk -uM -D /dev/${disk}
    hibernatepartition=${disk}2
  else
    sed -e "/82$/s/512/$swapsize/" ${installer}/partitions.sfdisk \
	| ${instroot}/sbin/sfdisk -uM -D /dev/${disk}
  fi
  if [ -z "${disk%%cciss*}" ]; then
    bootpartition=${disk}p1
    swappartition=${disk}p5
    cachepartition=${disk}p6
    rootpartition=${disk}p7
  else
    bootpartition=${disk}1
    swappartition=${disk}5
    cachepartition=${disk}6
    rootpartition=${disk}7
  fi
fi

#### End of disk setup.

### Choose boot loader target:
if [ "${bootloader}" = lilo -o "${bootloader}" = grub ] ; then
  if [ custom != "$bootloadertarget" ] ; then
    bootloadertarget=${disk}
  else
    while [ custom = "$bootloadertarget" ] ; do
      echo ; echo "Enter the name of the device where the boot loader"
      echo "is to be installed, or just press return to use the"
      echo -n "boot/root partition: "
      read bootloadertarget
      if [ -z "${bootloadertarget}" ] ; then
        bootloadertarget=${bootpartition}
      elif grep -Eq " ${bootloadertarget}"'( |$)' /proc/partitions ; then
        echo "Installing ${bootloader} on ${bootloadertarget}."
      else
        echo "${bootloadertarget} not found.  Try again."
        bootloadertarget=custom
      fi
    done
  fi
  echo "Installing boot loader on ${bootloadertarget}."
fi

### Find likely non-Athena partitions and inquire as to whether they
### should be boot options.
if [ "$disk_setup" != public ]; then
  plist=`grep "$disk[0-9]" /proc/partitions|sed -e "s/.*$disk/$disk/" -e "s/ .*//"`
  for p in $plist ; do
    # Punt partition if it's something we configured, or if it has the
    # "size 1" signature of an extended partition in /proc/partitions.
    if [ $p != "$bootpartition" -a $p != "$rootpartition" -a \
	$p != "$swappartition" -a $p != "$cachepartition" -a \
	$p != "$hibernatepartition" ] \
	&& ! grep -Eq " 1 $p"'( |$)' /proc/partitions ; then
      echo "Partition $p on your disk already has something on it."
      echo -n "Would you like to be able to boot to this partition? [y/N]: "
      read response
      if [ "$response" = "y" -o "$response" = "Y" ] ; then
	echo "You already have boot options called: ${bootoptions}"
	echo -n "What would you like to call this partition? [windows]: "
	read response
	if [ -z "${response}" ] ; then
	  response=windows
	fi
	bootoptions="${bootoptions}, ${response}"
	if [ ${bootloader} = lilo ] ; then
	  cat >> /tmp/lilo.addon <<EOF

other=/dev/${p}
	label=${response}
EOF
	elif [ ${bootloader} = grub ] ; then
	  i=${p#${disk}}
	  i=$((${i}-1))
	  cat >> /tmp/grub.addon <<EOF
title ${response}
	rootnoverify (GRUBDEV,$i)
	chainloader +1
EOF
	fi
      fi
    fi
  done # for p in $plist
  if [ "${bootoptions}" != "linux" ] ; then
    lilotimeout=150
    defaultboot=""
    while [ -z "${defaultboot}" ] ; do
      echo "Your options for the default boot are: ${bootoptions}"
      echo -n "Which would you like as the default?  [linux]: "
      read response
      if [ -z "${response}" -o "${response}" = linux ] ; then
	defaultboot=linux
      else
	if echo ${bootoptions} | grep -E -q ", (${response},|${response}$)" ; then
	  defaultboot=${response}
	else
	  echo "That's not valid, try again."
	fi
      fi
    done
  fi # non-linux boot options
fi

### Use ext3 for Athena 9.0.20 and newer.
if [ "${athenaversion%%.*}" -ge 10 -o \
  \( "${athenaversion%%.*}" = 9 -a "${athrel#*.}" -ge 1 \) -o \
  \( "${athenaversion%.*}" = 9.0 -a "${athenaversion##*.}" -ge 20 \) ] ; then
  fstype=ext3;
fi

### Create the new filesystems.
echo y > /tmp/yes
if [ ${bootpartition} != ${rootpartition} ] ; then
  mkfs.ext2 /dev/${bootpartition} < /tmp/yes
fi
mkswap /dev/${swappartition}
swapon /dev/${swappartition}
mkfs.ext2 /dev/${cachepartition} < /tmp/yes
mkfs.ext2 /dev/${rootpartition} < /tmp/yes
if [ ${fstype} = ext3 ] ; then
  if [ ${bootpartition} != ${rootpartition} ] ; then
    tune2fs -j /dev/${bootpartition}
  fi
  tune2fs -j /dev/${rootpartition}
fi
if [ "$create_hibernation_partition" = true ] ; then
  mkdosfs /dev/$hibernatepartition
  mkdir -p /mnt2
  mount -t msdos /dev/$hibernatepartition /mnt2
  $installer/tphdisk $hibernate_size > /mnt2/SAVE2DSK.BIN
  umount /mnt2
fi

### Mount filesystems in preparation for the install.
mkdir -p ${root}
mount -t ext2 /dev/${rootpartition} ${root}
mkdir ${root}/boot
if [ ${bootpartition} != ${rootpartition} ] ; then
  mount -t ext2 /dev/${bootpartition} ${root}/boot
fi
mkdir -p ${root}/usr/vice/cache
mount -t ext2 /dev/${cachepartition} ${root}/usr/vice/cache
mkdir ${root}/proc
mount -t proc proc ${root}/proc
mkdir ${root}/etc
mkdir -p ${root}/var/athena

### Create the Athena ext3 flag file.
if [ ${fstype} = ext3 ] ; then
  touch ${root}/var/athena/ext3.converted
fi

### Other Athena setup.
mkdir -p ${root}/usr/athena/info
mkdir -p ${root}/var/lib/rpm

### Create an appropriate fstab on the new root filesystem.
if [ ${bootpartition} != ${rootpartition} ] ; then
bootpartitionaddon="
/dev/${bootpartition}		/boot		${fstype}	defaults	1 2"
fi
cat > ${root}/etc/fstab <<EOF
/dev/${rootpartition}		/		${fstype}	defaults	1 1${bootpartitionaddon}
/dev/${cachepartition}		/usr/vice/cache	ext2	defaults	1 3
/dev/${swappartition}		swap		swap	defaults	0 0
none			/proc		proc	defaults	0 0
EOF

# additional 9.4-specific fstab entries and mount points
if [ ${athrel} = 9.4 ] ; then cat >> ${root}/etc/fstab <<EOF
none			/dev/shm	tmpfs	defaults	0 0
none			/dev/pts	devpts	gid=5,mode=620	0 0
/dev/cdrom		/mnt/cdrom	iso9660	noauto,owner,ro	0 0
/dev/fd0		/mnt/floppy	auto	noauto,owner	0 0
EOF
  mkdir -p ${root}/mnt/cdrom
  mkdir -p ${root}/mnt/floppy
fi

#### The following account for missing dependencies in some packages
#### post-install scripts.
#### These will just get stomped on when the real RPMS install.

mkdir -p ${root}/bin
mkdir -p ${root}/sbin
mkdir -p ${root}/usr/bin
cp ${instroot}/bin/cat ${root}/bin/cat
cp ${instroot}/bin/date ${root}/bin/date
cp ${instroot}/bin/rm ${root}/bin/rm
cp ${instroot}/bin/ln ${root}/bin/ln
cp ${instroot}/bin/sed ${root}/bin/sed
cp ${instroot}/bin/cp ${root}/bin/cp
cp ${instroot}/bin/mv ${root}/bin/mv
cp ${instroot}/bin/grep ${root}/bin/grep
cp ${instroot}/bin/egrep ${root}/bin/egrep
cp ${instroot}/bin/mkdir ${root}/bin/mkdir
cp ${instroot}/usr/bin/env ${root}/usr/bin/env
cp ${instroot}/usr/bin/wc ${root}/usr/bin/wc
cp ${instroot}/usr/bin/find ${root}/usr/bin/find
cp ${instroot}/sbin/install-info ${root}/sbin/install-info
cp ${instroot}/sbin/pidof ${root}/sbin/pidof
cp ${instroot}/bin/chmod ${root}/bin/chmod
cp ${instroot}/bin/uname ${root}/bin/uname
cp ${instroot}/bin/touch ${root}/bin/touch
# This next bit is a temporary hack until 9.4.25 is out and
# includes the relevant dependency.
# mkdir -p ${root}/usr/sbin
# cp /afs/dev/user/amb/tmp/groupadd ${root}/usr/sbin/groupadd

# New subtleties for a 2.6-based installer:
case "${instversion}" in
  6*) rpmopts=""
      # Use this instead of system-config-display to avoid root password
      # prompts:
      displayconf=/usr/share/system-config-display/system-config-display
      # Punt on SATA conversions since there should be no meaningful
      # delta between the install-time module set and what's installed:
      convert_sata=no
      rpm=/usr/bin/rpm
      mkdir /var/lib ; ln -s ${root}/var/lib/rpm /var/lib/rpm
      ;;
esac

####
#### Check the processor type, and downgrade the rpm list appropriately
#### if necessary.
RPMLIST=`tail -1 $CONTROL | awk '{ print $2 }'`
cp $RPMLIST ${root}/var/athena/release-rpms
awk '{print $1}' $RPMLIST > ${root}/var/athena/install-rpms
cpufamily=`grep -i '^cpu family' < /proc/cpuinfo | head -1 | \
    sed 's/^.*:[ 	]*//'`
case "$cpufamily" in
3|386*)
  echo "Downgrading RPM list to i386 and below."
  validcputypes="i386"
  ;;
4|486*)
  echo "Downgrading RPM list to i486 and below."
  validcputypes="i486 i386"
  ;;
5|586*)
  echo "Downgrading RPM list to i586 and below."
  validcputypes="i586 i486 i386"
  ;;
esac

if [ "$validcputypes" ] ; then
  rm -f ${root}/var/athena/install-rpms.new
  touch ${root}/var/athena/install-rpms.new
  for rpm in `cat ${root}/var/athena/install-rpms` ; do
    for arch in ${validcputypes} ; do
      crpm=`echo $rpm|sed -e 's/.i[3456]86.rpm$/.'${arch}'.rpm/'`
      if [ -f "${crpm}" ] ; then
        echo ${crpm} >> ${root}/var/athena/install-rpms.new
	break
      fi
    done
  done
  mv -f ${root}/var/athena/install-rpms.new ${root}/var/athena/install-rpms
fi

####
#### Set up RPM and install the package list.

# Some scripts depend on /dev/null (and maybe other things) so make
# sure they exist even before the dev package is installed.
mkdir ${root}/dev
${instroot}/dev/MAKEDEV -c ${instroot}/etc/makedev.d -d ${root}/dev \
    std cdrom hd sd ${disk}

####
#### Preliminary system setup:

# Make rpm transactions work cleanly:
mkdir -p ${root}/var/lock/rpm ${root}/etc
# Create a skeleton xfs config file so font installs can add to it:
mkdir -p ${root}/etc/X11/fs
cp ${installer}/fs.config ${root}/etc/X11/fs/config

# Initialize passwd and shadow files
cp ${passwd}/passwd ${root}/etc/passwd.local
cp ${root}/etc/passwd.local ${root}/etc/passwd
cp ${passwd}/shadow ${root}/etc/shadow.local
cp ${root}/etc/shadow.local ${root}/etc/shadow
cp ${passwd}/group ${root}/etc/group.local
cp ${root}/etc/group.local ${root}/etc/group
chmod 644 ${root}/etc/passwd.local ${root}/etc/passwd
chmod 600 ${root}/etc/shadow.local ${root}/etc/shadow
chmod 644 ${root}/etc/group.local ${root}/etc/group

####
#### Run the rpm transaction:

echo "Installing rpms..."
# rpm --root ${root} --initdb
if ! ${rpm} --root ${root} -Uvh ${rpmopts} \
    `cat ${root}/var/athena/install-rpms` ; then
  echo "The installation of the Linux Athena rpms has produced an error."
  echo "This is probably due to insuffient space or other filesystem"
  echo "errors, but may be due to harmless problems, especially if this"
  echo "was an Athena 9.4 install."
  if [ "${athrel}" != 9.4 ] ; then
    echo ; echo "Press return to try continuing the install anyway."
    read response
  fi
fi
if [ "${smp}" = true ] \
    && ! grep -q /kernel-smp-2 ${root}/var/athena/install-rpms; then
  echo "Installing additional SMP kernel..."
  smpkernel=`grep kernel-[0-9] ${root}/var/athena/install-rpms| \
      sed -e 's/kernel-/kernel-smp-/'`
  if ! ${rpm} --root ${root} -Uvh ${smpkernel} ${rpmopts}; then
    echo "Additional SMP kernel install failed!"
    smp=false
  fi
fi

####
#### Final configuration.

ifconfig lo 127.1
chroot ${root} /etc/athena/named
sleep 1

echo "Resetting clock at `date` from network time server."
chroot ${root} /etc/athena/gettime -s time.mit.edu
echo "Reset clock to `date`."
cp ${installer}/keyboard ${root}/etc/sysconfig/keyboard

chroot ${root} /usr/sbin/pwconv

kernelfile=`cd ${root}/boot ; ls vmlinuz-*|grep -v smp|tail -1`
kernelversion=`echo ${kernelfile}|sed -e 's/vmlinuz-//'`
echo "Installing with kernel version ${kernelversion}."

echo "Running kudzu..."
if [ "${athrel}" != 9.4 ] ; then
  # Our kernel version might not match the one that is being installed, 
  # which means kudzu might not find the modules we want.  So put in some
  # symlinks for a moment to trick it into thinking module files exist.
  mkdir ${root}/lib/modules/misc
  chroot ${root} /usr/bin/find /lib/modules -type f -exec ln -s {} /lib/modules/misc \; 2> /dev/null
  chroot ${root} /usr/sbin/kudzu -q
  rm -rf ${root}/lib/modules/misc
else
  # Run kudzu, pointing at current kernel modules.
  # Except that kudzu invokes the default display configurator,
  # which produces spurious root password prompts.  Since
  # display config is dealt with later anyway:
  mv ${root}/usr/bin/system-config-display \
      ${root}/usr/bin/system-config-display.real
  cp ${root}/bin/true ${root}/usr/bin/system-config-display
  chroot ${root} /usr/sbin/kudzu -q -k ${kernelversion}
  mv -f ${root}/usr/bin/system-config-display.real \
      ${root}/usr/bin/system-config-display
fi

# Check for any additional SCSIesque drivers required.
echo -n "Checking for disk driver module requirements... "
if [ ${athrel} = 9.4 ] && chroot ${root} lsmod|egrep -q '(ata_piix|ahci|cciss)' ; then
  scsimodcount=0
  for scsimod in ata_piix ahci cciss; do  
    if chroot ${root} lsmod|grep -q ${scsimod} ; then
      echo "alias scsi_hostadapter ${scsimod}" >> ${root}${moduleconf}.new
      echo -n "[${scsimod}]"
      scsimodcount=$((scsimodcount+1))
      if [ $scsimodcount == 1 ] ; then
        scsimodstring="install scsi_hostadapter /sbin/modprobe ${scsimod}"
      else
        scsimodstring="${scsimodstring} ; /sbin/modprobe ${scsimod}"
      fi
    fi
  done
  scsimodstring="${scsimodstring} ; :"
  if [ ${scsimodcount} -gt 1 ] ; then
    echo "${scsimodstring}" >> ${root}${moduleconf}
  fi
  cat ${root}${moduleconf}.new >> ${root}${moduleconf}
  rm -f ${root}${moduleconf}.new 
fi
echo " done."

# Part 1 of SATA conversion hack.
if [ $convert_sata = auto ] \
    && egrep -q '(ata_piix|Serial ATA)' ${root}/etc/sysconfig/hwconf ; then
  echo "Automatic SATA conversion selected and approrpiate drivers found."
  convert_sata=yes
fi
if [ -z "${disk%%hd*}" -a $convert_sata = yes ] ; then
  echo "Switching disk setup to use SATA devices."
  echo "alias scsi_hostadapter ata_piix" >> ${root}${moduleconf}
  for f in ${root}/etc/fstab ${root}/boot/grub/grub.conf ; do
    if test -f $f ; then
      sed -e 's+/dev/hd+/dev/sd+g' < $f > $f.new
      mv -f $f.new $f
    fi
  done
fi

if [ -z "${disk%%sd*}" -o -z "${disk%%cciss/*}" -o ${fstype} = ext3 -o convert_sata = yes ] ; then
  # An initrd is built by the kernel postinstall, but needs to be done
  # again here because any SCSI entries have only just been added to
  # modwhatever.conf by kudzu.
  echo "Rebuilding initrd..."
  chroot ${root} /sbin/mkinitrd -v -f /boot/initrd-${kernelversion}.img ${kernelversion}
  ird="
	 initrd=/boot/initrd-${kernelversion}.img"
  if [ "${smp}" = true ] || grep -q /kernel-smp-2 ${root}/var/athena/install-rpms; then
    chroot ${root} /sbin/mkinitrd -v -f /boot/initrd-${kernelversion}smp.img ${kernelversion}smp
    smpird="
	 initrd=/boot/initrd-${kernelversion}smp.img"
  fi
  echo "Done rebuilding initrd."
fi

# Install the boot loader.
echo "Installing boot loader..."
if [ "${bootloader}" = grub ] ; then
  # Fake /etc/mtab on the install target so that df, and thus the
  # grub-install script, will work.
  grep ${root} /etc/mtab|sed -e "s+${root}+/+" -e "s+//+/+" > ${root}/etc/mtab
  # Install grub on our target disk, and save old MBR before we write over it.
  dd if=/dev/${bootloadertarget} of=${root}/boot/grub/old-MBR bs=512 count=1
  chroot ${root} /sbin/grub-install /dev/${bootloadertarget}

  # Paths need to be relative to the partition in which grub is installed.
  if [ ${bootpartition} = ${rootpartition} ]; then
    boot="/boot"
  fi
  # Are we using an initrd?
  if [ -n "${ird}" ]; then
    ird="
	initrd ${boot}/initrd-${kernelversion}.img"
    smpird="
	initrd ${boot}/initrd-${kernelversion}smp.img"
  fi
  grubdev=`awk '$2 == '"\"/dev/${disk}\""' {print $1}' \
	${root}/boot/grub/device.map`
  grubbootpartition=$((`echo ${bootpartition} | \
	sed -e 's,'"${disk}"',,' | sed -e 's,^[a-z],,'` - 1))
  grubroot=`echo ${grubdev} | sed -e "s/)/,${grubbootpartition})/"`
  cat > ${root}/boot/grub/grub.conf.new <<EOF
timeout=${grubtimeout}
splashimage=${grubroot}${boot}/grub/splash.xpm.gz
title Linux-Athena
	root   ${grubroot}
	kernel ${boot}/${kernelfile} ro root=/dev/${rootpartition}${ird}
title Linux-Athena (single user mode)
	root   ${grubroot}
	kernel ${boot}/${kernelfile} single ro root=/dev/${rootpartition}${ird}
EOF
  if [ "${smp}" = true ] || grep -q /kernel-smp-2 ${root}/var/athena/install-rpms; then
    cat >> ${root}/boot/grub/grub.conf.new <<EOF
title Linux-Athena (multiprocessor mode)
	root   ${grubroot}
	kernel ${boot}/${kernelfile}smp ro root=/dev/${rootpartition}${smpird}
EOF
  fi
  cat /tmp/grub.addon|sed -e "s/GRUBDEV/`echo ${grubdev} | \
    sed -e 's/[\(\)]//g'`/" >> ${root}/boot/grub/grub.conf.new
  if [ "${defaultboot}" = linux -a "${smp}" = false ] ; then
    grubdefault=0
  elif [ "${defaultboot}" = linux -a "${smp}" = true ] ; then
    grubdefault=2
  else
    # Find the index in grub.conf.new of our defaultboot string.
    grubdefault=`grep "^title" ${root}/boot/grub/grub.conf.new | \
	grep -n "^title ${defaultboot}$"|sed -e 's/:.*//'`
    if [ "${grubdefault}" ] ; then
      grubdefault=$((${grubdefault}-1))
    else
      # Something went wrong with parsing grub.conf; just default to linux.
      grubdefault=0
    fi
  fi
  cat > ${root}/boot/grub/grub.conf <<EOF
# grub.conf created by Linux Athena installer
default=${grubdefault}
EOF
  cat ${root}/boot/grub/grub.conf.new >> ${root}/boot/grub/grub.conf
  rm ${root}/boot/grub/grub.conf.new

elif [ "${bootloader}" = lilo ] ; then
  ## Create two LILO configuration files:
  ## - /etc/lilo.conf contains all requested boot options.
  ## - /etc/lilo.conf.simple contains an entry only for linux.
  ## The second will be used if configuration of the first fails.
  if [ "${lba32}" = true ] ; then
    extraliloopts="${extraliloopts}
lba32"
    fi
    cat > ${root}/etc/lilo.conf.simple << EOF
boot=/dev/${bootloadertarget}
map=/boot/map
install=/boot/boot.b
prompt
timeout=${lilotimeout}${extraliloopts}
default=linux

image=/boot/${kernelfile}
	label=linux${ird}
	read-only
	root=/dev/${rootpartition}
EOF
  sed -e "s/default=linux/default=${defaultboot}/" < \
      ${root}/etc/lilo.conf.simple > ${root}/etc/lilo.conf
  cat /tmp/lilo.addon >> ${root}/etc/lilo.conf

  # Run lilo, with successive fallback and a final punt to a shell.
  if chroot ${root} lilo ; then
    rm ${root}/etc/lilo.conf.simple
  else
    echo "Problems occured installing the boot loader (LILO); attempting to install"
    echo "a stripped-down loader with only the Athena Linux boot option."
    echo "After reboot, you will find the complete version of the LILO"
    echo "configuration in /etc/lilo.conf.broken."
    echo "(Install pausing for 60 seconds for this message to be read.)"
    printf "\a" ; sleep 1 ; printf "\a" ; sleep 1 ; printf "\a" ; sleep 60
    mv ${root}/etc/lilo.conf ${root}/etc/lilo.conf.broken
    mv ${root}/etc/lilo.conf.simple ${root}/etc/lilo.conf
    if ! chroot ${root} lilo ; then
      echo "BUGHALT.  FIND A WIZARD."
      echo "THE INSTALL HAS DIED AND CANNOT BE REVIVED WITHOUT EXPERT ATTENTION."
      echo "SEE THE ERROR MESSAGES ABOVE AND ${root}/etc/lilo.conf."
      echo "WHAT YOU TYPE IN THIS SHELL WILL BE SAVED IN THE install.log."
 #    echo "YOU ARE NOW IN DDT."
      ${instroot}/bin/sh
    fi
  fi
else
  echo "You have chosen to install a custom boot loader."
  echo "You will be left in a shell to do so after the install."
fi

# Part 2 of SATA conversion hack.
if [ -z "${disk%%hd*}" -a $convert_sata = yes ] ; then
  if test -f ${root}/boot/grub/grub.conf ; then
    sed -e 's+/dev/hd+/dev/sd+g' < ${root}/boot/grub/grub.conf \
	> ${root}/boot/grub/grub.conf.new
    mv -f ${root}/boot/grub/grub.conf.new ${root}/boot/grub/grub.conf
  fi
fi

# Set permissions on floppy devices.
chmod 666 ${root}/dev/fd[0-9]*

# Obtain and check hostname; prompt if necessary.
if [ "${dhcp}" = false ] ; then
  hostname=`chroot ${root} /usr/athena/bin/host $IPADDR | \
        sed 's#^.*domain name pointer \(.*\)$#\1#' | sed 's;\.*$;;' | \
        tr '[A-Z]' '[a-z]'`
  if echo $hostname|grep -q "not found" ; then
    hostname=""
    printf "\a"; sleep 1 ; printf "\a"; sleep 1 ;printf "\a"
    echo "The IP address you selected, $IPADDR, does not have an associated"
    echo "hostname.  Please confirm that you're using the correct address."
    while [ -z "$hostname" ] ; do
      echo -n "Enter hostname [no default]: "
      read hostname
    done
  fi
fi

cat > ${root}/etc/sysconfig/network <<EOF
NETWORKING=yes
FORWARD_IPV4=false
HOSTNAME=$hostname
EOF

if [ "${dhcp}" = false ] ; then
  echo "GATEWAY=$GATEWAY" >> ${root}/etc/sysconfig/network
fi

cat > ${root}/etc/sysconfig/network-scripts/ifcfg-eth0 <<EOF
DEVICE=eth0
IPADDR=$IPADDR
NETMASK=$NETMASK
ONBOOT=yes
EOF
if [ "${dhcp}" = false ] ; then
  echo "BOOTPROTO=static" >> ${root}/etc/sysconfig/network-scripts/ifcfg-eth0
else
  echo "BOOTPROTO=dhcp" >> ${root}/etc/sysconfig/network-scripts/ifcfg-eth0
fi

echo -n "Athena Workstation (linux) Version " > ${root}/etc/athena/version
echo -n "$athenaversion " >> ${root}/etc/athena/version
date >> ${root}/etc/athena/version

MACHINE=`uname -m`
OS=`uname -s`

# Update various settings in /etc/athena/rc.conf.
sed -e "s/localhost.localdomain/${hostname}/" \
    -e "s/PUBLIC=false/PUBLIC=${rc_public}/" \
    -e "s/ADDR=[\.0-9]*/ADDR=${IPADDR}/" \
    -e "s/AUTOUPDATE=true/AUTOUPDATE=${rc_autoupdate}/" \
    ${root}/etc/athena/rc.conf > /tmp/rc.conf
mv /tmp/rc.conf ${root}/etc/athena/rc.conf

# Configure PCMCIA.
pcic=
# Determine controller type.
devs=`chroot ${root} /usr/sbin/kudzu -p -b pci -c socket`
if [ -n "$devs" ]; then
  pcic=yenta_socket
elif [ "${athrel}" = 9.4 ] ; then
  # Kudzu is assumed to have dealt with it.
  :
else
  # Check for tcic or i82365.
  devs=`chroot ${root} /sbin/probe`
  res=`echo "$devs" | grep -c "TCIC-2 probe: not found"`
  if [ "${res}" = 0 ]; then
    # We've got SOMETHING.  (We didn't find a "TCIC-2 not found".)
    # Is it tcic or Intel?
    res=`echo "$devs" | grep -c "TCIC-2"`
    if [ "${res}" != 0 ]; then
      pcic=tcic
    else    # check for "Intel PCIC"?
      pcic=i82365
    fi
  fi
fi
if [ -n $pcic ] ; then
  # Write out the PCMCIA config file.
  pcmcia_file=${root}/etc/sysconfig/pcmcia
  if [ -n "$pcic" ]; then
    echo PCMCIA=yes > $pcmcia_file
    echo PCIC=$pcic >> $pcmcia_file
  else
    echo PCMCIA=no > $pcmcia_file
    echo PCIC= >> $pcmcia_file
  fi
  echo PCIC_OPTS= >> $pcmcia_file
  echo CORE_OPTS= >> $pcmcia_file
fi

# Ditch the losing network drivers that Redhat insists on installing on
# our Intellistations.
if lspci -n|grep -q 8086:2449 && grep -q eepro100 ${root}${moduleconf};then
  sed -e 's/eepro100/e100/g' < ${root}${moduleconf} \
      > ${root}${moduleconf}.new
  mv -f ${root}${moduleconf}.new ${root}${moduleconf}
fi
if [ "$athrel" = "9.1" ]; then
    if lspci -n|grep -q 14e4:16a6 && grep -q tg3 ${root}${moduleconf};then
      sed -e 's/tg3/bcm5700/g' < ${root}${moduleconf} \
          > ${root}${moduleconf}.new
      mv -f ${root}${moduleconf}.new ${root}${moduleconf}
    fi
fi

# Rerun the xorgs font postinstall now that all dependencies are *really*
# in place:
cp ${installer}/rebuild-fontdirs.sh ${root}
echo "Rebuilding font directories.  Ignore any chkfontpath errors here:"
chroot ${root} /rebuild-fontdirs.sh
rm -f ${root}/rebuild-fontdirs.sh ${root}/etc/X11/fs/config.rpmnew

# Configure X, starting xfs first so that a server can start.
echo "Configuring X..."
# First, clean up anything the previous kudzu invocation left behind.
rm -f ${root}${xconf}
# Run the crufty old stuff for 9.0 and earlier.
if [ "${athrel%.*}" -le "8" -o \
    \( "${athrel%.*}" -eq "9" -a ${athrel#*.} -le 1 \) ]; then
  cp ${installer}/Xconfigurator.athena ${root}/Xconfigurator.athena
  chroot ${root} /etc/init.d/xfs start
  if [ "$custom_x" = yes ] ; then
    chroot ${root} /usr/sbin/mouseconfig
    chroot ${root} /Xconfigurator.athena
  else
    chroot ${root} /usr/sbin/mouseconfig --kickstart
    if lspci -n|grep -q '102b:0525' ; then
      # Install canned Matrox G400 configuration, because clock rates
      # which the card claims to support don't work on about 15% of the
      # cards.
      cp ${installer}/XF86Config-4.g400 ${root}/etc/X11/XF86Config-4
      rm -f ${root}/etc/X11/X
      ln -s ../../usr/X11R6/bin/XFree86 ${root}/etc/X11/X
    elif chroot ${root} /Xconfigurator.athena --kickstart \
        && test -f ${root}/etc/X11/XF86Config-4 ; then
      # Autoconfiguration was successful, just tweak the video mode.
      sed -e 's/1600x1200/1280x1024/' \
  	    ${root}/etc/X11/XF86Config-4 > ${root}/etc/X11/XF86Config-4.new
      mv -f ${root}/etc/X11/XF86Config-4.new ${root}/etc/X11/XF86Config-4
    elif lspci -n|grep -E -q '1002:(50..|524.|534.|544.|545.)' ; then
      # Install canned ATI Rage 128 configuration.
      cp ${installer}/XF86Config-4.r128 ${root}/etc/X11/XF86Config-4
      rm -f ${root}/etc/X11/X
      ln -s ../../usr/X11R6/bin/XFree86 ${root}/etc/X11/X
    elif lspci -n|grep -q 1002: ; then
    # Install canned ATI congfiguration.
      cp ${installer}/XF86Config-4.ati ${root}/etc/X11/XF86Config-4
      rm -f ${root}/etc/X11/X
      ln -s ../../usr/X11R6/bin/XFree86 ${root}/etc/X11/X
    else
    # Punt and retain console logins.
      retain_tty_logins=true
    fi
    chmod -f 644 ${root}/etc/X11/XF86Config-4
  fi
  rm -f ${root}/Xconfigurator.athena
else
  # Installing at 9.2 or later.
  # Set custom driver flags.
  if lspci -n|grep -q 1002:5b62 ; then
    echo "Forcing vesa driver for Dell gx620 configuration."
    xdriver="--set-driver=vesa" 
  elif lspci -n|grep -q 8086:7125 && lspci -n|grep -q 10de:002d ; then
    xdriver="--set-driver=nv" 
    echo "Forcing nv driver for Dell gx110 configuration."
  fi
  if [ "$custom_x" = yes ] ; then
    chroot ${root} ${displayconf} --reconfig
  else
    if lspci -n|grep -q '102b:0525' ; then
      # Install canned Matrox G400 configuration, because clock rates
      # which the card claims to support don't work on about 15% of the
      # cards.
      cp ${installer}/XF86Config-4.g400 ${root}${xconf}
    elif chroot ${root} ${displayconf} --reconfig \
	--set-depth=24 --set-resolution=1280x1024 ${xdriver} \
	2> /tmp/xconfig.err && test -f ${root}${xconf} ; then
      if grep -q "HorizSync: None" /tmp/xconfig.err || \
	  grep -q "ddcprobe returned bogus values" /tmp/xconfig.err ; then
        echo "Automated X configuration had problems; adding 1024x768 mode."
        sed -e 's/Modes /Modes "1024x768" /' \
    	      ${root}${xconf} > ${root}${xconf}.new
        mv -f ${root}${xconf}.new ${root}${xconf}
      fi
    elif lspci -n|grep -E -q '1002:(50..|524.|534.|544.|545.)' ; then
      # Install canned ATI Rage 128 configuration if autoconfig failed.
      cp ${installer}/XF86Config-4.r128 ${root}${xconf}
    elif lspci -n|grep -q 1002: ; then
      # Install canned ATI congfiguration if autoconfig failed.
      cp ${installer}/XF86Config-4.ati ${root}${xconf}
    else
      # Punt and retain console logins.
      retain_tty_logins=true
    fi
    chmod -f 644 ${root}${xconf}
  fi
fi

# Change default runlevel to 5 (X11) and disable console logins unless
# directed otherwise.
if [ "${retain_tty_logins}" = false ] ; then
  sed -e 's/id:3/id:5/' -e '/tty[123456]/s/^/#/' < ${root}/etc/inittab \
      > /tmp/inittab
  for i in 1 2 3 4 5 6; do
    echo "$i:2345:once:echo \"Type CTRL-ALT-F7 to log in.\" > /dev/tty$i" \
	>> /tmp/inittab
  done
  mv /tmp/inittab ${root}/etc/inittab
fi

# Copy AFS config files from AFS, since we don't know if the ones we got
# from the AFS RPM are the most up to date ones available.
for file in CellAlias CellServDB SuidCells; do
  cp /afs/athena.mit.edu/service/${file} ${root}/usr/vice/etc/${file}
  chown root:root ${root}/usr/vice/etc/${file}
  chmod a+r ${root}/usr/vice/etc/${file}
done

# Interim fix for 9.4.43 installs on the Dell gx755, since 9.4.43 doesn't
# support its network hardware even though the installer does.
if ! grep -q eth0 ${root}/etc/modprobe.conf \
      && lspci -n | grep -q 8086:10bd \
      && [ "$athenaversion" = 9.4.43 ] ; then
  echo "Installing temporary e1000e driver for the Dell gx755."
  echo "alias eth0 e1000e" >> ${root}/etc/modprobe.conf
  cp ${SYSTEM}/installer/e1000-${kernelversion}.ko \
      $root/lib/modules/${kernelversion}/kernel/drivers/net/e1000e.ko
  chroot $root depmod $kernelversion
fi

# This sometimes fails as result of implied dependencies vs. the actual
# install order, and rerunning it is harmless.
if test -f ${root}/usr/bin/update-gdk-pixbuf-loaders ; then
  echo "Rerunning update-gdk-pixbuf-loaders."
  chroot ${root} /usr/bin/update-gdk-pixbuf-loaders i386-redhat-linux
fi

# The final just-in-case shell.
if [ "${bootloader}" = custom -o "${finalshell}" = true ] ; then
  echo "The install is complete.  A shell will now start which will enable you"
  echo "to make final customizations and boot loader changes.  The system will"
  echo "reboot when you exit the shell.  Remember that what you type in this"
  echo "shell will be saved in install.log (Type Control-D to exit the shell.)"
  chroot ${root} /bin/bash
fi

echo "Install finished at `date`."
