#
# usage:        ruser.sh
#
# abstract:     This Bourne Shell script determines if the user
#		executing this program is superuser (uid=0).
#
# note(s):      1. This routine must be called using a . (period)
#		2. Requires the 'id' command to execute without user
#		   intervention.
#
# Copyright (c) 1992-1999 The MathWorks, Inc. 
# $Revision: 1.26 $  $Date: 2002/06/12 20:21:06 $
#----------------------------------------------------------------------------
#
# 			Check for superuser. [all]
#			-------------------
#
    cmd="id"
    . $dir/$searchp_sh
    if [ "$pathlist" != "" ]; then
        user=`id`
        if [  `expr "$user" : 'uid=0(root)'` -ne 11 ]; then
            . $dir/$clearsc_sh
#
# Check that user has the ability to write into $MATLAB/update
#
    	    (cat /dev/null > $MATLAB/update/$$a) 2>/dev/null
    	    if [ $? -ne 0 ]; then
        	rm $MATLAB/update/$$a > /dev/null 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '------------------------------------------------------------------------------'
    echo "    You are not superuser . . ."
    echo ""      
    echo "    You CANNOT install a working MATLAB. You do not have permission"
    echo "    to write into MATLAB directories."
    echo ""      
    echo '------------------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        	. $dir/$abort_sh
	    else
        	rm $MATLAB/update/$$a > /dev/null 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '--------------------------------------------------------------------------------'
    echo "    You are not superuser . . ."
    echo " "      
    echo "    You can still install a working MATLAB."
    echo " "      
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		if [ "$minimal_install" = "0" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    However, you may not have permission to complete any of the following" 
    echo "    steps if you encounter them during installation:"

    echo " "
    echo '        B1. Create symbolic links to scripts in $MATLAB/bin directory.'
    echo " "
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    Also, the following step is skipped:"
    echo " "
    echo '        C2. Build symbolic links /etc/lmboot_TMW, /etc/lmdown_TMW.'
    echo " "
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    Use the '-m' option with 'install_matlab' to automatically skip"
    echo "    any of these steps."
    echo " "
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
		fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    Use the '-u' option with 'install_matlab' to automatically skip"
    echo "    this check for superuser."
    echo " "
    echo '    $MATLAB/etc/license.dat file should be owned by a privileged user.'
    echo '--------------------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
        	if [ "$batch" = "1" ]; then
            	    echo 'Continue? ([y]/n) y'
        	else
	    	    . $dir/$cont_sh
        	fi
    	        usermode=1
	    fi
        fi
    else
	. $dir/$clearsc_sh
#
# Check that user has the ability to write into $MATLAB/update
#
    	(cat /dev/null > $MATLAB/update/$$a) 2>/dev/null
    	if [ $? -ne 0 ]; then
            rm $MATLAB/update/$$a > /dev/null 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '------------------------------------------------------------------------'
    echo "    Warning!  The 'id' command used to check for superuser is missing."
    echo ""
    echo "    You CANNOT install a working MATLAB. You do not have permission"
    echo "    to write into MATLAB directories."
    echo ""      
    echo '--------------------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
      	    . $dir/$abort_sh
	else
            rm $MATLAB/update/$$a > /dev/null 2>&1
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo '------------------------------------------------------------------------'
    echo "    Warning!  The 'id' command used to check for superuser is missing."
    echo ""
    echo "    If you are not superuser you can still install a working MATLAB."
    echo ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    if [ "$minimal_install" = "0" ]; then
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    However, you may not have permission to complete any of the following" 
    echo "    steps if you encounter them during installation:"
    echo ""
    echo '        B1. Create symbolic links to scripts in $MATLAB/bin directory.'
    echo ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    It also skips step:"
    echo ""
    echo '        C2. Build symbolic links /etc/lmboot_TMW, /etc/lmdown_TMW.'
    echo ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    Use the '-m' option with 'install_matlab' to automatically skip"
    echo "    any of these steps."
    echo ""
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
	    fi
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    echo "    Use the '-u' option with 'install_matlab' to automatically skip"
    echo "    this check for superuser."
    echo ""
    echo '    $MATLAB/etc/license.dat file should be owned by a privileged user.'
    echo '--------------------------------------------------------------------------------'
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            if [ "$batch" = "1" ]; then
            	echo 'Continue? ([y]/n) y'
            else
	    	. $dir/$cont_sh
            fi
	fi
    fi
