#!/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"
echo ""
switch ($type)
  case doc :
    cd /usr/andrew/dlib/atk
    echo "  Indexing the dynamic objects..."
    /usr/andrew/bin/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
    breaksw

  case dev :
    cd /usr/andrew/dlib/atk
    echo "  Indexing the dynamic objects..."
    /usr/andrew/bin/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..."
    /usr/andrew/bin/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 "============================================================="
    echo "If you are interested in using MIME mail, you need to set up"
    echo " \$HOME/.mailcap or /etc/mailcap.  A good start for your"
    echo "mailcap file is in /usr/andrew/etc/mailcap file."
    echo "See the /usr/andrew/README.ez.mail file for more information."
    echo "============================================================="
    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
      grep 'set hold' /usr/lib/Mail.rc >& /dev/null
      if ($status == 0) then
        echo "============================================================="
        echo "Your /usr/lib/Mail.rc has 'set hold' in it.  You need to remove this"
        echo "for messages to be able to retrieve mail properly."
        echo "Don't forget to do this, it can causes all sorts of grief."
        echo "See the /usr/andrew/README.ez.mail file for more information."
        echo "============================================================="
      endif
    endif
    breaksw

  case src :
    cd /usr/andrew/dlib/atk
    echo "  Indexing the dynamic objects..."
    /usr/andrew/bin/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 :
    set a = `which groff`
    if ("$a[1]" == "groff:") then
      echo "You do not have groff installed.  You will not be able to print anything"
    else
      echo "Good, groff is installed. You should be able to print."
    endif
    set a = `which ghostview`
    if ("$a[1]" == "ghostview:") then
      echo "You do not have ghostview installed.  You will not be able to preview anything"
    else
      echo "Good, ghostview is installed. You should be able to print."
    endif
    echo ""
    echo -n "What size paper do you use? Enter 'a4' or 'us': "
    set a = "$<"
    /usr/andrew/bin/setpapersize $a
    echo "You can set the paper size with the command: setpapersize"
    breaksw

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

echo ""
echo "Installation for AUIS63-$type is complete."
echo "Be sure to read the README files in /usr/andrew/README.*"
echo "Check out the preferences file in /usr/andrew/sample.preferences too."
echo ""
echo "Lastly, we'd like to know who is trying out AUIS. Please send e-mail"
echo "to tpg@mr.net just once. "
echo ""
echo "Thank you for looking at AUIS. We hope you find it of value."
exit
