#! /bin/sh
#
# usage:        lmdebug [-c licensefile] [-l logfile] [lmdebug_logfile]
#
# abstract:     This Bourne Shell script creates a log of diagnostic
#               information for the license manager.
#
# options:
#
#               -c licensefile
#
#                  Path of the license file.
#                  DEFAULT: $MATLAB/etc/license.dat
#
#               -l logfile
#
#                  Path of the license manager log file.
#                  DEFAULT: /usr/adm/license.log4
#
#               lmdebug_logfile
#
#                  Path of the file where the diagnostic output from this
#                  program is put.
#                  DEFAULT: lmdebug.log in the current directory
#
# note(s):      1. This script executes without changing the current directory.
#                  This means that relative pathnames can be used in command
#                  options.
#
# Copyright (c) 1986-95 by The MathWorks, Inc.
# $Revision: 1.22 $  $Date: 1995/05/30 17:14:21 $
#----------------------------------------------------------------------------
#   
#**************************************************************************
# Determine the path of the MATLAB root directory - always one directory
# up from the path to this command.
#**************************************************************************
#
    filename=$0
#
# Now it is either a file or a link to a file.
#
    cpath=`pwd`
#
# Follow up to 8 links before giving up. Same as BSD 4.3
#
    n=1
    maxlinks=8
    while [ $n -le $maxlinks ]
    do
#
# Get directory correctly!
#
        newdir=`echo "$filename" | awk '
                        { tail = $0
                          np = index (tail, "/")
                          while ( np != 0 ) {
                             tail = substr (tail, np + 1, length (tail) - np)
                             if (tail == "" ) break
                             np = index (tail, "/")
                          }
                          head = substr ($0, 1, length ($0) - length (tail))
                          if ( tail == "." || tail == "..")
                             print $0
                          else
                             print head
                        }'`
        if [ ! "$newdir" ]; then
            newdir="."
        fi
        (cd $newdir) > /dev/null 2>&1
        if [ $? -ne 0 ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Internal error 1: We could not determine the path of the'
    echo '                  MATLAB root directory.'
    echo ''
    echo "                  original command path = $0"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            exit 1
        fi
        cd $newdir
#
# Need the function pwd - not the built in one
#
        newdir=`/bin/pwd`
#
        newbase=`expr //$filename : '.*/\(.*\)' \| $filename`
        lscmd=`ls -l $newbase 2>/dev/null`
        if [ ! "$lscmd" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Internal error 2: Could not determine the path of the'
    echo '                  MATLAB root directory.'
    echo ''
    echo "                  original command path = $filename"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            exit 1
        fi
#
# Check for link portably
#
        if [ `expr "$lscmd" : '.*->.*'` -ne 0 ]; then
            filename=`echo "$lscmd" | awk '{ print $NF }'`
        else
#
# It's a file
#
            dir="$newdir"
            command="$newbase"
#
            cd $dir/..
            MATLAB=`/bin/pwd`; export MATLAB
            break
        fi
    done
    if [ $n -gt $maxlinks ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Internal error 3: More than $maxlinks links in path to'
    echo "                  this script. That's too many!"
    echo ''
    echo "                  original command path = $filename"
    echo "                  current  command path = $filename"
    echo ''
    echo '                  Please contact:'
    echo '' 
    echo '                      MathWorks Technical Support'
    echo ''
    echo '                  for further assistance.'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        exit 1
    fi
#
    licensefile=$MATLAB/etc/license.dat
    lmlogfile=
    lmdebug_logfile=lmdebug.log
#
# Parse the arguments
#
#     -c licensefile
#     -l logfile
#     lmdebug_logfile
#
    stat="OK"
    while [ "$stat" = "OK" -a  $# -gt 0 ]; do
        case "$1" in
            -c)
                shift
                if [ $# -gt 0 ]; then
                    case "$1" in
                        -*)
                            stat=""
                            ;;
                         *)
                            licensefile="$1"
                            shift
                            ;;
                    esac
                else
                    stat=""
                fi
                ;;
            -l)
                shift
                if [ $# -gt 0 ]; then
                    case "$1" in
                        -*)
                            stat=""
                            ;;
                         *)
                            lmlogfile="$1"
                            shift
                            ;;
                    esac
                else
                    stat=""
                fi
                ;;
             -*)
                stat="";
                ;;
              *)
                lmdebug_logfile=$1
                shift
                if [ $# -gt 0 ]; then
                    stat=""
                fi
                ;;
        esac
    done
    if [ "$stat" = "" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
   echo ''
   echo '    Usage: lmdebug [-c licensefile] [-l logfile] [lmdebug_logfile]'
   echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        exit 1
    fi
#
    if [ -f $MATLAB/etc/util/arch.sh ]; then
#       
        cd $cpath
#
        trap " echo ''; echo '    Sorry! lmdebug aborted . . .'; echo ''; exit 1" 1 2 3 15
#
        send_mail=support@mathworks.com
        subject=$lmdebug_logfile
#
#
        echo ''
        echo '               ****  License Manager Debug Script  ****'
        echo ''
        echo '              (c) Copyright 1984-94 The MathWorks, Inc.'
        echo '                  All Rights Reserved'
        echo ''
#
#
        echo 'This script creates and optionally emails to The MathWorks'
        echo 'a file containing diagnostic information to help troubleshoot'
        echo 'MATLAB and license manager installation problems.'
        echo ''
#
# Determine the Machine Architecture
#
        . $MATLAB/etc/util/arch.sh
   	if [ "$Arch" = "unknown" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        echo ''
        echo '    Sorry! We could not determine the machine architecture for your'
        echo '           host. Please contact:'
        echo ''
        echo '               MathWorks Technical Support'
        echo ''
        echo '           for further assistance.'
        echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            exit 1
        fi
#
# Determine the license manager logfile
#
        if [ "$lmlogfile" = "" ]; then
            if [ "$Arch" != "sol2" ]; then
                lmlogfile=/usr/adm/license.log4
            else
                lmlogfile=/usr/sadm/license.log4
            fi
        fi
#
# Determine the type of ps command
#
        . $MATLAB/etc/util/whichps.sh
#
        mesg='Please enter your name:         '
        . $MATLAB/etc/util/echon.sh
        read name
#
        mesg='Please enter your phone number: '
        . $MATLAB/etc/util/echon.sh
        read phone
#
#
        echo ""
        echo "Creating $lmdebug_logfile.  Please wait . . ."
#
         if [ -f $lmdebug_logfile ]; then
             rm -f $lmdebug_logfile
         fi
#
        echo "***************  lmdebug version 1.1  *****************" >$lmdebug_logfile
        echo ''                                 >>$lmdebug_logfile
        echo "* Name: $name"                    >>$lmdebug_logfile
        echo "* Phone number: $phone"           >>$lmdebug_logfile
        echo "*"                                >>$lmdebug_logfile
        echo "* MATLAB root: $MATLAB"           >>$lmdebug_logfile
#
        cmd="hostname"
        . $MATLAB/etc/util/searchp.sh
        if [ "$pathlist" != "" ]; then
            echo "* Hostname: `hostname` "      >>$lmdebug_logfile
        else
            echo "* Hostname: hostname command not on your path . . ." >>$lmdebug_logfile
        fi
#
        echo "* Architecture: $Arch "           >>$lmdebug_logfile
        echo "* Date: `date` "                  >>$lmdebug_logfile      
#
        cmd="uname"
        . $MATLAB/etc/util/searchp.sh
        if [ "$pathlist" != "" ]; then
            echo "* Uname reports: `uname -a` " >>$lmdebug_logfile
        else
            echo "* Uname reports: uname command not on your path . . ." >>$lmdebug_logfile
        fi
#
        echo "" >>$lmdebug_logfile
        echo "#***************** output of lmhostid *****************" >>$lmdebug_logfile
        echo ''                    >>$lmdebug_logfile
        $MATLAB/etc/lmhostid       >>$lmdebug_logfile

        if [ "$Arch" = "sun4" ]; then
           /usr/etc/showrev        >>$lmdebug_logfile
        fi
        echo ''                    >>$lmdebug_logfile
#
#
        echo "******************* which matlab **********************" >>$lmdebug_logfile
        cmd="matlab"
        . $MATLAB/etc/util/searchp.sh
        if [ "$pathlist" != "" ]; then
           echo ''                                     >>$lmdebug_logfile
           ls -l $pathlist                             >>$lmdebug_logfile
           echo ''                                     >>$lmdebug_logfile
        else
           echo ''                                     >>$lmdebug_logfile
           echo "Did not find matlab command on path." >>$lmdebug_logfile
           echo ''                                     >>$lmdebug_logfile
        fi
#
#
        echo "******************* which cmex ************************" >>$lmdebug_logfile
        cmd="cmex"
        . $MATLAB/etc/util/searchp.sh
        if [ "$pathlist" != "" ]; then
           echo ''                                   >>$lmdebug_logfile
           ls -l $pathlist                           >>$lmdebug_logfile
           echo ''                                   >>$lmdebug_logfile
        else
           echo ''                                   >>$lmdebug_logfile
           echo "Did not find cmex command on path." >>$lmdebug_logfile
           echo ''                                   >>$lmdebug_logfile
        fi

#
#
        echo "******************* which fmex ************************" >>$lmdebug_logfile
        cmd="fmex"
        . $MATLAB/etc/util/searchp.sh
        if [ "$pathlist" != "" ]; then
           echo ''                                   >>$lmdebug_logfile
           ls -l $pathlist                           >>$lmdebug_logfile
           echo ''                                   >>$lmdebug_logfile
        else
           echo ''                                   >>$lmdebug_logfile
           echo "Did not find fmex command on path." >>$lmdebug_logfile
           echo ''                                   >>$lmdebug_logfile
        fi
#
#
        echo "#***************** /etc/lmboot link *******************" >>$lmdebug_logfile
        if [ -f /etc/lmboot ]; then
           echo ''                              >>$lmdebug_logfile
           ls -l /etc/lmboot                    >>$lmdebug_logfile
           echo ''                              >>$lmdebug_logfile
        else
           echo ''                              >>$lmdebug_logfile
           echo "Did not find /etc/lmboot link" >>$lmdebug_logfile
           echo ''                              >>$lmdebug_logfile
        fi

#
#
        echo "************** license manager log file ***************" >>$lmdebug_logfile
        if [ -f $lmlogfile ]; then
           echo ''                        >>$lmdebug_logfile
           ls -l $lmlogfile               >>$lmdebug_logfile
           echo ''                        >>$lmdebug_logfile
        else
           echo ''                        >>$lmdebug_logfile
           echo "Did not find $lmlogfile" >>$lmdebug_logfile
           echo ''                        >>$lmdebug_logfile
        fi
#
#

        echo "****************** license.dat file *******************" >>$lmdebug_logfile
        if [ -f $licensefile ]; then
           echo ''                          >>$lmdebug_logfile
           cat $licensefile                 >>$lmdebug_logfile
           echo ''                          >>$lmdebug_logfile
        else
           echo ''                          >>$lmdebug_logfile
           echo "Did not find $licensefile" >>$lmdebug_logfile
           echo ''                          >>$lmdebug_logfile
        fi
#
#
        echo "***************** local options file ******************" >>$lmdebug_logfile
        if [ -f $licensefile ]; then
           path=`cat $licensefile | awk '/DAEMON/ {print $4; exit}'`
           if [ "$path" ]; then
             if [ -f $path ]; then
                echo ''                                   >>$lmdebug_logfile
                cat $path                                 >>$lmdebug_logfile
                echo ''                                   >>$lmdebug_logfile
             else
                echo ''                                   >>$lmdebug_logfile
                echo 'Local options file listed, but not found.'  >>$lmdebug_logfile
                echo ''                                   >>$lmdebug_logfile
             fi                                           >>$lmdebug_logfile
           else
              echo ''                                     >>$lmdebug_logfile
              echo 'Not used'                             >>$lmdebug_logfile
              echo ''                                     >>$lmdebug_logfile
           fi
        else
           echo ''                                        >>$lmdebug_logfile
           echo "No license file - can't tell . . ."      >>$lmdebug_logfile
           echo ''                                        >>$lmdebug_logfile
        fi
#
#
        echo "************* license manager server host? ************" >>$lmdebug_logfile
        if [ -f $licensefile ]; then
            licensefile=$licensefile
            localhostid=`$MATLAB/etc/lmhostid | sed -e "1d" -e '2s/^[^"]*"//' -e '2s/".*//'`
            lmfilehostids=`cat $licensefile | awk '/SERVER/ {print $3}'`
            onserver=0
            for i in $lmfilehostids
            do
                if [ "$localhostid" = "$i" ]; then
                    onserver=1
                    break
                fi
            done
            echo ''                             >>$lmdebug_logfile
            if [ "$onserver" = "1" ]; then
                echo 'Yes'                      >>$lmdebug_logfile
            else
                echo 'No'                       >>$lmdebug_logfile
            fi
            echo ''                             >>$lmdebug_logfile
        else
            echo ''                                   >>$lmdebug_logfile
            echo "No license file - can't tell . . ." >>$lmdebug_logfile
            echo ''                                   >>$lmdebug_logfile
        fi
#
#
# Check for old and new fragments.
#
        echo "************ Code segment to start daemons ************" >>$lmdebug_logfile
        echo ''                               >>$lmdebug_logfile
        if [ -f $licensefile ]; then
            case "$Arch" in
                sgi)
                    filelist='/etc/rc2.d/S*'
                    qfilelist='"/etc/rc2.d/S*"'
                    ;;
                sol2)
                    filelist='/etc/rc3.d/S*'
                    qfilelist='"/etc/rc3.d/S*"'
                    ;;
                alpha)
                    filelist='/sbin/rc3.d/S*'
                    qfilelist='"/sbin/rc3.d/S*"'
                    ;;
                *)
                    filelist='/etc/*rc*'
                    qfilelist='"/etc/*rc*"'
                    ;;
                
            esac
#
# old fragments
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "OLD style code segment(s):"   >> $lmdebug_logfile
    echo '--------------------------'   >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            fragment='/etc/lmgrd'
            fraglist=`grep $fragment $filelist 2>/dev/null | awk '
		     BEGIN {found = ""}
                     {nextfile = substr($1, 1, index($1,":") - 1)
		      found = "1"
                      if ( nextfile != lastfile ) {
                          oldlist = oldlist " " lastfile
                          lastfile = nextfile
                      }}
                      END { if (found != "") {
			        if (lastfile != "" )
				    oldlist = oldlist " " lastfile
                                print oldlist
			    }}'`
            if [ "$fraglist" != "" ]; then
#
# old fragments: Watch out for multiple instances in one file
#
                for i in $fraglist
                do
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    file = $i"                >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    cat $i | awk ' BEGIN {start = 1}
                        /MATLAB/,/fi/ { if ( start ) {
                                            print ""
                                            print
                                            start = 0 
                                        }
                                        else
                                            print
                                        next }
                                      { start = 1; next }
                                      END { print "" }' >> $lmdebug_logfile
                done
            else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''                                             >> $lmdebug_logfile
    echo "    Nothing found in files $qfilelist"        >> $lmdebug_logfile
    echo ''                                             >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '--------------------------'   >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
# new fragments
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''                             >> $lmdebug_logfile
    echo "NEW style code segment(s):"   >> $lmdebug_logfile
    echo '--------------------------'   >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            fragment='/etc/lmboot'
            fraglist=`grep $fragment $filelist 2>/dev/null | awk '
		     BEGIN {found = ""}
                     {nextfile = substr($1, 1, index($1,":") - 1)
		      found = "1"
                      if ( nextfile != lastfile ) {
                          oldlist = oldlist " " lastfile
                          lastfile = nextfile
                      }}
                      END { if (found != "") {
			        if (lastfile != "" )
				    oldlist = oldlist " " lastfile
                                print oldlist
			    }}'`
            if [ "$fraglist" != "" ]; then
#
# old fragments: Watch out for multiple instances in one file
#
                for i in $fraglist
                do
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    file = $i"                >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
                    cat $i | awk ' BEGIN {start = 1}
                        /MATLAB/,/fi/ { if ( start ) {
                                            print ""
                                            print
                                            start = 0 
                                        }
                                        else
                                            print
                                        next }
                                      { start = 1; next }
                                      END { print "" }' >> $lmdebug_logfile
                done
            else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''                                             >> $lmdebug_logfile
    echo "    Nothing found in files $qfilelist"        >> $lmdebug_logfile
    echo ''                                             >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '--------------------------'   >> $lmdebug_logfile
    echo ''                             >> $lmdebug_logfile
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        fi
#
        if [ "$psCmdSysV" = "TRUE" ]; then
        echo "************ output of ps -ef | grep lm ***************" >>$lmdebug_logfile
            echo ''                     >>$lmdebug_logfile
            ps -ef | grep lm            >>$lmdebug_logfile
        else
        echo "************ output of ps agx | grep lm **************" >>$lmdebug_logfile
            echo ''                     >>$lmdebug_logfile
            ps agx | grep lm           >>$lmdebug_logfile
        fi
        echo ''                         >>$lmdebug_logfile
#
#
        echo "************** tail of license.log file ***************" >>$lmdebug_logfile
        if [ -f $lmlogfile ]; then
                echo ''                         >>$lmdebug_logfile
                echo "    logfile = $lmlogfile" >>$lmdebug_logfile
                echo ''                         >>$lmdebug_logfile
                tail -50 $lmlogfile             >>$lmdebug_logfile
                echo ''                         >>$lmdebug_logfile
        else
                echo ''                         >>$lmdebug_logfile
                echo "Did not find $lmlogfile"  >>$lmdebug_logfile
                echo ''                         >>$lmdebug_logfile
        fi
#
#
        echo "#**************** output of lmstat -a *****************" >>$lmdebug_logfile
        echo ''                 >>$lmdebug_logfile
        $MATLAB/etc/lmstat -a   >>$lmdebug_logfile 2>&1
        echo ''                 >>$lmdebug_logfile
#
# 
        echo "#***************** output of finger *******************" >>$lmdebug_logfile
        echo ''                                         >>$lmdebug_logfile
        cmd="finger"
        . $MATLAB/etc/util/searchp.sh
        if [ "$pathlist" != "" ]; then
            finger $name                >>$lmdebug_logfile 2>&1
        else
            echo ''                                      >>$lmdebug_logfile
            echo 'finger command not on your path . . .' >>$lmdebug_logfile
.log
        fi
        echo ''                                          >>$lmdebug_logfile
#
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '-----------------------------------------------------------------'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        mesg='Email this diagnostic report to The MathWorks? (y/[n]) '
        . $MATLAB/etc/util/echon.sh
        read ans
        if [ `expr "$ans" : '[Yy].*'` -ne 0 ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo 'Supply a username at The MathWorks to send the mail to. If your'
    echo 'technical support contact has given you one use it. Otherwise,'
    echo 'hit <return> to use the default. The mail will be sent to'
    echo ''
    echo '                   username@mathworks.com'
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            mesg='Username? ([support]) '
            . $MATLAB/etc/util/echon.sh
            read ans
            if [ "$ans" ]; then
                send_mail="$ans@mathworks.com"                            
            fi
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#
            case "$Arch" in
                hp300|hp700|sol2)
            /usr/bin/mailx -s $lmdebug_logfile $send_mail <<%
~r $lmdebug_logfile
%
                  ;;
		sgi)
            /usr/sbin/Mail -s $lmdebug_logfile $send_mail <<%
~r $lmdebug_logfile
%
                  ;;
		alpha)
            /usr/bin/Mail -s $lmdebug_logfile $send_mail <<%
~r $lmdebug_logfile
%
                  ;;
		sun4|dec_risc)
            /usr/ucb/mail -s $lmdebug_logfile $send_mail <<%
~r $lmdebug_logfile
%
                  ;;
                ibm_rs)
            /usr/bin/mail -s $lmdebug_logfile $send_mail <<%
~r $lmdebug_logfile
%
                  ;;
		*)
            mail -s $lmdebug_logfile $send_mail <<%
~r $lmdebug_logfile
%
                  ;;
            esac
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo "Mail command issued - sent to $send_mail"
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        fi
#
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo ''
    echo '-----------------------------------------------------------------'
    echo ''
    echo 'The diagnostic information is stored in the file'
    echo ''
    echo "    $lmdebug_logfile"
    echo ''
    echo 'If your computer is not connected to email or you encountered'
    echo 'an error while trying to email this file, please print and FAX to:'
    echo ''
    echo '    MathWorks Technical Support    FAX: (508) 653-2997'
    echo ''
    echo '-----------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    else
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '-----------------------------------------------------------------'
    echo ''
    echo 'ERROR: You are executing lmdebug in directory'
    echo ''
    echo "       $dir"
    echo ''
    echo "       The util subdirectory is missing; cannot go on . . ."
    echo ''
    echo '-----------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        exit 1
    fi
