#
# usage:        fin.sh
#
# abstract:     This Bourne Shell script outputs messages at the end
#		of an installation.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1992-2000 by The MathWorks, Inc.
# $Revision: 1.14 $  $Date: 2000/07/27 19:42:09 $
#----------------------------------------------------------------------------
#
#=======================================================================
# Functions:
#   clean_alone ()
#   clean_install ()
#=======================================================================
    clean_alone () { # Cleans out unneeded directories for standalone
                     # case. 
                     #
		     # Standalone mathlib/cppmath: (need only)
		     #
		     #    $MATLAB/extern
		     #    $MATLAB/bin
		     #    $MATLAB/etc/license.dat -> $MATLAB/license.dat
		     #    $MATLAB/install_matlabp.out
		     #    $MATLAB/install_matlabd.out
		     #    $MATLAB/ftp
		     #    $MATLAB/help
		     #    $MATLAB/license.txt
		     #
		     #    if -f $MATLAB/mathlib.html then
		     #        cp $MATLAB/mathlib.html $MATLAB/helpdesk.html
		     #
		     # Call clean_install to remove:
		     #
		     #    $MATLAB/install_matlab
		     #    $MATLAB/install
                     #
                     # Always returns a 0 status.
                     #
                     # usage: check_alone
                     #
        if [ "$cppmath_only" = "1" ]; then
#
# Set trap to ignore signals
#
	    trap "" 1 2 3 15
#
	    standalone=""
            if [ "$cppmath_only" = "1" ]; then
		standalone="$standalone'cppmathlib' "
	    fi
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ''
echo "    Note: Cleanup for standalone $standalone..."
echo '' 
#+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
	    if [ -f $MATLAB/etc/license.dat ]; then
#
# Clean out SERVER, DAEMON, and any unused FEATURE/INCREMENT lines when making
# the copy
#
	        cat $MATLAB/etc/license.dat | sed \
		    -e "/0123456789ABCDEFGHIJ/d" \
		    -e "/SERVER/d" \
		    -e "/DAEMON/d" > $MATLAB/license.dat
	        chmod 644 $MATLAB/license.dat
	    fi
#
# If help/mathlib.html exists make a copy as help/helpdesk.html
#
	    if [ -f $MATLAB/help/mathlib.html ]; then
		cp $MATLAB/help/mathlib.html $MATLAB/help/helpdesk.html
	    fi
#
#///////////////////////////////////////////////////////////////////////
            xlist='. .. bin extern ftp help install install_matlab install_matlabd.out install_matlabp.out license.dat license.txt'
#///////////////////////////////////////////////////////////////////////
#
	    echo $xlist > $temp_file
	    (cd $MATLAB; ls -a) >> $temp_file
#
	    cat $temp_file | awk '
#-----------------------------------------------------------------------
    NR == 1 { for (i = 1; i <= NF; i = i + 1) a[$i] = 1; next}
	    { if (a[$1] != 1) print $1 }' > $temp_file2
#-----------------------------------------------------------------------
	    (cd $MATLAB
	     while read path
             do
		 rm -rf $path
	     done) < $temp_file2
#
	    rm -f $temp_file $temp_file2
#
        fi
	return 0
    }
#=======================================================================
    clean_install () { # Cleans out the installation files.
		       #
		       # Remove:
		       #
		       #    $MATLAB/install_matlab
		       #    $MATLAB/install
		       #
                       # Always returns a 0 status.
                       #
                       # usage: clean_install
                       #
	cd $ML_ROOT_DIR
	if [ "$cppmath_only" = "1" ]; then
	    exec /bin/rm -rf install_matlab install
        fi
	return 0
    }
#=======================================================================
#
#			Finished install [2]
#			----------------
#
    . $dir/$cleanup_sh
#
    clean_alone
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo ''
echo '    ---------------------------------------------------------------------'
echo '    | Finished! This completes the:                                     |'
echo '    |                                                                   |'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    case "$whichi" in
	1)
	   if [ "$extract_only" = "1" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo '    |                  NORMAL install (extract files only)              |'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	   elif [ "$extract_fix_only" = "1" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo '    |                  NORMAL install (extract files with update)       |'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	   else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo '    |                  NORMAL install                                   |'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	   fi
	   ;;
	4)
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo '    |                  LICENSE MANAGER ONLY install                     |'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	   ;;
    esac
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo '    |                                                                   |'
echo '    |           for this host.                                          |'
echo '    ---------------------------------------------------------------------'
echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
    clean_install
#
    exit 0
