#
# usage:        getlmhid.sh
#
# abstract:     This Bourne Shell script gets lmhostid.
#
# note(s):      1. This routine must be called using a . (period)
#
# Copyright (c) 1992-95 by The MathWorks, Inc.
# $Revision: 1.7 $  $Date: 1995/05/02 12:56:01 $
#----------------------------------------------------------------------------
#
#			Get lmhostid [-l option]
#               	------------
#
# We assume that we have not changed directories since the orginal
# invocation (at $WD).
#
    file=license.dat
#
    cmd="hostname"
    . $dir/$searchp_sh
    if [ "$pathlist" = "" ]; then
        Hostname=`uname -n`
    else
        Hostname=`hostname`
    fi
#
    if [ "$Arch" != "lnx86" ]; then
        HostID=`$etc_lmhostid_exe | sed -e "1d" -e '2s/^[^"]*"//' -e '2s/".*//'`
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo "                     Preparing Your 'license.dat' File"
echo '--------------------------------------------------------------------------------'
echo "| A 'license.dat' file is required to run MATLAB and in some cases to decrypt  |"
echo '| toolbox files during installation. This file contains license server         |' 
echo '| information and FEATURE lines with passcodes. A passcode file containing the |'
echo '| FEATURE lines is generated by The MathWorks using a string called the        |'
echo "| 'lmhostid' or license server hostid.                                         |"
echo "            The 'lmhostid' for this host ($Hostname) is:     $HostID"
echo '| If your license server is another host. login to that host and in the MATLAB |'
echo "| root directory repeat the command, './install_matlab -l'.                    |"
echo '|                                                                              |'
echo "| The passcode file needs to be merged into an existing 'license.dat' file.    |"
echo '| First time users may place a copy of the passcode file in $MATLAB and it     |'
echo "| will be merged in automatically with a skeleton 'license.dat' file created   |"
echo '| during installation. Existing users should manually merge the most recent    |'
echo "| passcode file with your existing 'license.dat' file,                         |"
echo '| $MATLAB/etc/license.dat. If you need a passcode file PLEASE contact:         |'
echo '|                                                                              |'
echo '|           The MathWorks, Inc.           (508) 653-1415                       |'
echo '|    email: service@mathworks.com     FAX (508) 653-2997                       |'
echo '|                                                                              |'
echo '| See the MATLAB installation guide for the structure of the license file.     |'
echo '--------------------------------------------------------------------------------'
        . $dir/$cleanup_sh
        exit 0
    else
	defaultfile=
        if [ "$CD_LM_INSTALL" = "" ]; then
	    File=$MATLAB/etc/license.dat
	    . $dir/$actualp_sh
            if [ "$Filepath" != "" ]; then
		defaultfile='$MATLAB/etc/license.dat'
	    fi
	fi
#--------------------------------------------------------------------------
    echo ''
    echo "Please specify the path to your license file? [$defaultfile]"
    echo 'For the default press return (will exit if no default) . . .'
    echo ''
#--------------------------------------------------------------------------
	while true
	do
            mesg='Path>  '
            . $dir/$echon_sh
            read ans
	    if [ `expr "//$ans" : '//[ 	]*$'` -eq 0 ]; then
           	File=$ans
      	    else
		if [ "$defaultfile" = "" ]; then
                    . $dir/$cleanup_sh
                    exit 0
		else
		    Filepath=$defaultfile
		    break
		fi
	    fi
	    . $dir/$actualp_sh
            if [ "$Filepath" != "" ]; then
		break
	    else
#--------------------------------------------------------------------------
    echo ''
    echo '    Sorry! Path does not exist . . .'
    echo '           Please try again.'
    echo ''
#--------------------------------------------------------------------------
	    fi
	done
	licensefile=`eval echo $Filepath`
        HostID=`$etc_lmhostid_exe -c $licensefile | sed -e "1d" -e '2s/^[^"]*"//' -e '2s/".*//'`
#
	. $dir/$clearsc_sh
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
echo "                  Preparing Your Linux 'license.dat' File"
echo '--------------------------------------------------------------------------------'
echo "| A 'license.dat' file is required to run MATLAB and in some cases to decrypt  |"
echo '| toolbox files during installation. This file contains FEATURE lines with     |' 
echo '| passcodes. A passcode file containing those FEATURE lines is generated       |'
echo "| by The MathWorks using a string called the 'lmhostid' or license hostid.     |"
echo '| The license hostid for Linux is currently the SiteID and is supplied by The  |'
echo '| MathWorks.                                                                   |'
echo '|                                                                              |'
echo "      The 'lmhostid' by searching the specified license file is:  $HostID"
echo '|                                                                              |'
echo "| The passcode file needs to be merged into an existing 'license.dat' file.    |"
echo '| First time users may place a copy of the passcode file in $MATLAB and it     |'
echo "| will be merged in automatically with a skeleton 'license.dat' file created   |"
echo '| during installation. Existing users should manually merge the most recent    |'
echo "| passcode file with your existing 'license.dat' file,                         |"
echo '| $MATLAB/etc/license.dat. If you need a passcode file PLEASE contact:         |'
echo '|                                                                              |'
echo '|           The MathWorks, Inc.           (508) 653-1415                       |'
echo '|    email: service@mathworks.com     FAX (508) 653-2997                       |'
echo '|                                                                              |'
echo '| See the MATLAB installation guide for the structure of the license file.     |'
echo '--------------------------------------------------------------------------------'
        . $dir/$cleanup_sh
        exit 0
    fi
