#!/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 $ANDREWDIR."
  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.  $ANDREWDIR/etc/$nm:t  src"
  exit 1
endif

set type = $1		# Type of package

if (! -d $ANDREWDIR) then
  echo "Mmmm - doesn't look to me like AUIS is installed. Where is
$ANDREWDIR?"
  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 $ANDREWDIR/help	$ANDREWDIR/help" >! /tmp/helpindex.idx
    $ANDREWDIR/etc/mkindex -v /tmp/helpindex.idx $ANDREWDIR/lib/help.index  > /dev/null
    breaksw

  case full :
    cd $ANDREWDIR/dlib/atk
    echo "  Indexing the dynamic objects..."
    foreach i (a b c d e f g h i j k l m n o p q r s t u v w x y z)
    $ANDREWDIR/bin/doindex $i*.do > /dev/null
    end
    echo "  Indexing the help files..."
    echo "dir $ANDREWDIR/help	$ANDREWDIR/help" >! /tmp/helpindex.idx
    $ANDREWDIR/etc/mkindex -v /tmp/helpindex.idx $ANDREWDIR/lib/help.index  > /dev/null
    if (-e $ANDREWDIR/bin/runapp.real) then
      mv $ANDREWDIR/bin/runapp $ANDREWDIR/bin/runapp.faker
      mv $ANDREWDIR/bin/runapp.real $ANDREWDIR/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 $ANDREWDIR/lib/help.overviews.* | sort | uniq >! $ANDREWDIR/lib/help.overviews.tmp
    rm $ANDREWDIR/lib/help.overviews; 
    cp $ANDREWDIR/lib/help.overviews.tmp $ANDREWDIR/lib/help.overviews; 
    rm $ANDREWDIR/lib/help.overviews.tmp
    cat $ANDREWDIR/lib/help.programs.* | sort | uniq >! $ANDREWDIR/lib/help.programs.tmp
    rm $ANDREWDIR/lib/help.programs; 
    cp $ANDREWDIR/lib/help.programs.tmp $ANDREWDIR/lib/help.programs; 
    rm $ANDREWDIR/lib/help.programs.tmp
    breaksw

  case mail :
    cd $ANDREWDIR/dlib/atk
    echo "  Indexing the dynamic objects..."
    foreach i (a b c d e f g h i j k l m n o p q r s t u v w x y z)
    $ANDREWDIR/bin/doindex $i*.do  > /dev/null
    end
    echo "  Indexing the help files..."
    echo "dir $ANDREWDIR/help	$ANDREWDIR/help" >! /tmp/helpindex.idx
    $ANDREWDIR/etc/mkindex -v /tmp/helpindex.idx $ANDREWDIR/lib/help.index  > /dev/null
    if (-e $ANDREWDIR/bin/runapp.real) then
      mv $ANDREWDIR/bin/runapp $ANDREWDIR/bin/runapp.faker
      mv $ANDREWDIR/bin/runapp.real $ANDREWDIR/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"
    echo  "your mailcap file is in $ANDREWDIR/etc/mailcap file."
    echo "See the $ANDREWDIR/doc/README.ez file for more information."
    echo "============================================================="
    echo "Created new help overview and programs"
    cat $ANDREWDIR/lib/help.overviews.* | sort | uniq >! $ANDREWDIR/lib/help.overviews.tmp
    rm -f $ANDREWDIR/lib/help.overviews; 
    cp $ANDREWDIR/lib/help.overviews.tmp $ANDREWDIR/lib/help.overviews; 
    rm -f $ANDREWDIR/lib/help.overviews.tmp
    cat $ANDREWDIR/lib/help.programs.* | sort | uniq >! $ANDREWDIR/lib/help.programs.tmp
    rm -f $ANDREWDIR/lib/help.programs; 
    cp $ANDREWDIR/lib/help.programs.tmp $ANDREWDIR/lib/help.programs; 
    rm -f $ANDREWDIR/lib/help.programs.tmp    
    set d = `grep domain /etc/resolv.conf`
    if ($#d == 2) then	# Be sure it appears reasonable
      echo "$ANDREWDIR/etc/AndrewSetup domain set to '$d[2]'"
      sed -es/mr.net/$d[2]/ $ANDREWDIR/etc/AndrewSetup >! $ANDREWDIR/etc/AndrewSetup.new
      mv $ANDREWDIR/etc/AndrewSetup.new $ANDREWDIR/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 $ANDREWDIR/doc/README.ez file for more information."
        echo "============================================================="
      endif
    endif
    breaksw

  case src :
    cd $ANDREWDIR/dlib/atk
    echo "  Indexing the dynamic objects..."
     foreach i (a b c d e f g h i j k l m n o p q r s t u v w x y z)
    $ANDREWDIR/bin/doindex $i*.do  > /dev/null
    end
    echo "  Indexing the help files..."
    echo "dir $ANDREWDIR/help	$ANDREWDIR/help" >! /tmp/helpindex.idx
    $ANDREWDIR/etc/mkindex -v /tmp/helpindex.idx $ANDREWDIR/lib/help.index  > /dev/null
    if (-e $ANDREWDIR/bin/runapp.real) then
      mv $ANDREWDIR/bin/runapp $ANDREWDIR/bin/runapp.faker
      mv $ANDREWDIR/bin/runapp.real $ANDREWDIR/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 $ANDREWDIR/lib/help.overviews.* | sort | uniq >! $ANDREWDIR/lib/help.overviews.tmp
    rm -f $ANDREWDIR/lib/help.overviews; 
    cp $ANDREWDIR/lib/help.overviews.tmp $ANDREWDIR/lib/help.overviews; 
    rm -f $ANDREWDIR/lib/help.overviews.tmp
    cat $ANDREWDIR/lib/help.programs.* | sort | uniq >! $ANDREWDIR/lib/help.programs.tmp
    rm -f $ANDREWDIR/lib/help.programs; 
    cp $ANDREWDIR/lib/help.programs.tmp $ANDREWDIR/lib/help.programs; 
    rm -f $ANDREWDIR/lib/help.programs.tmp    
    breaksw

  case wp :
    echo " Help application not available in this package." 
#   echo "  Indexing the help files..."
#    echo "dir $ANDREWDIR/help	$ANDREWDIR/help" >! /tmp/helpindex.idx
#    $ANDREWDIR/etc/mkindex -v /tmp/helpindex.idx $ANDREWDIR/lib/help.index  > /dev/null
    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.ez file in $ANDREWDIR/doc."
echo "Check out the preferences file in"
echo "$ANDREWDIR/sample.preferences too."
echo "Lastly, we'd like to know who is trying out AUIS."
echo "Please send e-mail to"
echo "info-andrew-request@andrew.cmu.edu."  
exit
