#
# usage:        tapecln.sh
#
# abstract:     This Bourne Shell script rewinds the tape and then creates
#		and sources a boot file to continue the installation.
#
# note(s):      1. This routine must be called using a . (period)
#
#		2. Screen format
#
#-------------------------------------------------------------------------
#    			    T4. Cleanup
#
# Rewinding tape . . . (please wait)
#
# You may now remove the tape . . .
#
# REMEMBER: ALWAYS tar the contents of the first file on the MATLAB
#           distribution tape into $MATLAB if you wish to extract
#           additional products at a later time.
#
#-------------------------------------------------------------------------
# Finished! This completes tape extraction WITHOUT tape directory removal.
#-------------------------------------------------------------------------
# Removing $MATLAB/update/tape directory . . . (please wait)
#
# Finished! This completes tape extraction WITH tape directory removal.
#
#-------------------------------------------------------------------------
# Removing $MATLAB/update/tape directory . . . (please wait)
#
# Now proceed to the 'MATLAB Installation' 
#
# Continue? ([y]/n)
#
#-------------------------------------------------------------------------
#
# Copyright (c) 1994-1998 The Mathworks, Inc. All Rights Reserved.
# $Revision: 1.9 $  $Date: 1998/12/24 17:31:45 $
#----------------------------------------------------------------------------
#
#                                    Cleanup
#                                    -------
#
# Output the screen
#
    . $dir/$clearsc_sh
#--------------------------------------------------------------------------
echo '                           T4. Cleanup'
echo ''
#--------------------------------------------------------------------------
    mesg='Rewinding tape . . . (please wait) '
    . $dir/$echon_sh
#
    . $dir/$trewind_sh
#--------------------------------------------------------------------------
    echo ''
#--------------------------------------------------------------------------
#
#--------------------------------------------------------------------------
    echo ''
    echo 'You may now remove the tape . . .'
    echo ''
    echo 'REMEMBER: ALWAYS tar the contents of the first file on the MATLAB'
    echo '          distribution tape into $MATLAB if you wish to extract'
    echo '          additional products at a later time.'
    echo ''
#--------------------------------------------------------------------------
#
# Build arguments for state
#
#	lmhostid_only=0		
#	licdat_only=0
#    -x	extract_only=0
#    -X	extract_fix_only=0
#    -t	terse=0
#    -s	skip_welcome=0
#       remove_tape_dir=0
#       textract_rm_only=0
#	textract_only=0
#    -b	batch=0
#    -u	usermode=0
#       check_tmw_al=0
#    -m minimal_install=0
#
    args=''
    if [ "$extract_only" != 0 ]; then
	args="$args -x"
    fi
    if [ "$extract_fix_only" != 0 ]; then
	args="$args -X"
    fi
    if [ "$terse" != 0 ]; then
	args="$args -t"
    fi
    if [ "$skip_welcome" != 0 ]; then
	args="$args -s"
    fi
    if [ "$batch" != 0 ]; then
	args="$args -b"
    fi
    if [ "$usermode" != 0 ]; then
	args="$args -u"
    fi
    if [ "$minimal_install" != 0 ]; then
	args="$args -m"
    fi
    . $dir/$cleanup2_sh
#
#--------------------------------------------------------------------------
#
# Create and source temp_boot file to:
#
# 1. Remove the tape directory if required
# 2. Output Part II message if required
# 2. Output Continue message if required
# 3. If continue then exec $MATLAB/install_matlab args and -s
#
    temp_boot=/tmp/$$boot; export temp_boot
    cat > $temp_boot << 'EOF'
#
    trap "rm -f $temp_boot; exit 1" 0 1 2 3 15
#
    if [ "$textract_only" = "1" ]; then 
#--------------------------------------------------------------------------
    echo ''
    echo 'Finished! This completes tape extraction WITHOUT tape directory removal.'
    echo ''
#--------------------------------------------------------------------------
	exit 0
    fi
#
    if [ "`echo -n`" != "" ]; then
#--------------------------------------------------------------------------
    echo 'Removing $MATLAB/update/tape directory . . . (please wait) \c'
#--------------------------------------------------------------------------
	rm -rf $TAPE_DIR >/dev/null 2>&1
#--------------------------------------------------------------------------
    echo ''
#--------------------------------------------------------------------------
	    if [ "$textract_rm_only" = "1" ]; then
#--------------------------------------------------------------------------
    echo ''
    echo 'Finished! This completes tape extraction WITH tape directory removal.'
    echo ''
#--------------------------------------------------------------------------
		exit 0
	    else
#--------------------------------------------------------------------------
    echo ''
    echo "Now proceed to the 'MATLAB Installation'" 
#--------------------------------------------------------------------------
	    fi 
#--------------------------------------------------------------------------
    echo ''
    echo "Continue? ([y]/n) \c"
#--------------------------------------------------------------------------
    else
#--------------------------------------------------------------------------
    echo -n 'Removing $MATLAB/update/tape directory . . . (please wait) '
#--------------------------------------------------------------------------
         rm -rf $TAPE_DIR >/dev/null 2>&1
#--------------------------------------------------------------------------
    echo ''
#--------------------------------------------------------------------------
	    if [ "$textract_rm_only" = "1" ]; then
#--------------------------------------------------------------------------
    echo ''
    echo 'Finished! This completes tape extraction WITH tape directory removal.'
    echo ''
#--------------------------------------------------------------------------
		exit 0
	    else
#--------------------------------------------------------------------------
    echo ''
    echo "Now proceed to the 'MATLAB Installation'" 
#--------------------------------------------------------------------------
	    fi 
#--------------------------------------------------------------------------
    echo ''
    echo -n "Continue? ([y]/n) "
#--------------------------------------------------------------------------
    fi
#
    read ans
    if [ `expr "//$ans" : '//[Nn].*'` -gt 0 ]; then
#--------------------------------------------------------------------------
    echo ''
    echo '    install_matlab stopped prematurely . . .'
    echo ''
#--------------------------------------------------------------------------
	exit 0
    fi
#
    cd $MATLAB
    exec $MATLAB/install_matlab -s $args
#
EOF
    chmod +x $temp_boot
    . $temp_boot
