#!/bin/csh -f
#	Complete the installation of a package.

if ($#argv == 0 || "x$1" == "x-h") then
  set nm = $0
  echo "Usage:  $nm:t  [src mail etc...]"
  echo ""
  echo "Completes the installation of an AUIS63 package.  These packages"
  echo "are simply a sequence of tar files that lay files into /usr/andrew."
  echo "After this is done, we usually need to do just a little bit of work -"
  echo "thats what this shell is for."
  echo ""
  echo "E.g.  /usr/andrew/etc/$nm:t  src"
  exit 1
endif

set type = $1		# Type of package

if (! -d /usr/andrew) then
  echo "Mmmm - doesn't look to me like AUIS is installed. Where is
/usr/andrew?"
  exit 2
endif

touch /.test.for.root
if ($status != 0) then
  echo "This needs to be run under the ROOT userid"
  exit 3
endif
rm -f /..test.for.root
echo "Good, you are running as root."

echo "Completing the installation for AUIS63-$type"
switch ($type)
  case doc :
    echo "  Indexing the help files..."
    echo "dir /usr/andrew/help	/usr/andrew/help" >! /tmp/helpindex.idx
    /usr/andrew/etc/mkindex -v /tmp/helpindex.idx /usr/andrew/lib/help.index > /dev/null
    breaksw

  case dev :
    cd /usr/andrew/dlib/atk
    echo "  Indexing the dynamic objects..."
    doindex *.do > /dev/null
    echo "  Indexing the help files..."
    echo "dir /usr/andrew/help	/usr/andrew/help" >! /tmp/helpindex.idx
    /usr/andrew/etc/mkindex -v /tmp/helpindex.idx /usr/andrew/lib/help.index > /dev/null
    if (-e /usr/andrew/bin/runapp.real) then
      mv /usr/andrew/bin/runapp /usr/andrew/bin/runapp.faker
      mv /usr/andrew/bin/runapp.real /usr/andrew/bin/runapp
      echo "Installed real version of runapp"
    else
      echo "No fake version of runapp was installed."
    endif
    echo "Created new help overview and programs"
    cat /usr/andrew/lib/help.overviews.* | sort | uniq >! /usr/andrew/lib/help.overviews
    cat /usr/andrew/lib/help.programs.* | sort | uniq >! /usr/andrew/lib/help.programs
    breaksw

  case mail :
    cd /usr/andrew/dlib/atk
    echo "  Indexing the dynamic objects..."
    doindex *.do > /dev/null
    echo "  Indexing the help files..."
    echo "dir /usr/andrew/help	/usr/andrew/help" >! /tmp/helpindex.idx
    /usr/andrew/etc/mkindex -v /tmp/helpindex.idx /usr/andrew/lib/help.index > /dev/null
    if (-e /usr/andrew/bin/runapp.real) then
      mv /usr/andrew/bin/runapp /usr/andrew/bin/runapp.faker
      mv /usr/andrew/bin/runapp.real /usr/andrew/bin/runapp
      echo "Installed real version of runapp"
    else
      echo "No fake version of runapp was installed."
    endif
    echo "Created new help overview and programs"
    cat /usr/andrew/lib/help.overviews.* | sort | uniq >! /usr/andrew/lib/help.overviews
    cat /usr/andrew/lib/help.programs.* | sort | uniq >! /usr/andrew/lib/help.programs
    set d = `grep domain /etc/resolv.conf`
    if ($#d == 2) then	# Be sure it appears reasonable
      echo "/usr/andrew/etc/AndrewSetup domain set to '$d[2]'"
      sed -es/mr.net/$d[2]/ /usr/andrew/etc/AndrewSetup >! /usr/andrew/etc/AndrewSetup.new
      mv /usr/andrew/etc/AndrewSetup.new /usr/andrew/etc/AndrewSetup
    endif
    breaksw

  case src :
    cd /usr/andrew/dlib/atk
    echo "  Indexing the dynamic objects..."
    doindex *.do > /dev/null
    echo "  Indexing the help files..."
    echo "dir /usr/andrew/help	/usr/andrew/help" >! /tmp/helpindex.idx
    /usr/andrew/etc/mkindex -v /tmp/helpindex.idx /usr/andrew/lib/help.index > /dev/null
    if (-e /usr/andrew/bin/runapp.real) then
      mv /usr/andrew/bin/runapp /usr/andrew/bin/runapp.faker
      mv /usr/andrew/bin/runapp.real /usr/andrew/bin/runapp
      echo "Installed real version of runapp"
    else
      echo "No fake version of runapp was installed."
    endif
    echo "Created new help overview and programs"
    cat /usr/andrew/lib/help.overviews.* | sort | uniq >! /usr/andrew/lib/help.overviews
    cat /usr/andrew/lib/help.programs.* | sort | uniq >! /usr/andrew/lib/help.programs
    breaksw

  case wp :
    breaksw

  default :
    echo "Unknown package type - $type"
    exit 1
endsw

echo "Installation for AUIS63-$type is complete."
exit
