#
# CheckBecomeUser ensures that the specified RAC user is set up correctly.
# ( no login privileges, never expires, has /usr/sbin in PATH )
#
function CheckBecomeUser()
{
	# ---- arg 1 is the "become" username

	if [ ! ".$1" = "." ]; then

	 	useradd -f-1 -s /sbin/nologin -mp '!!' $1 >/dev/null 2>&1
		grep "export PATH=/usr/sbin:" /home/$1/.bash_profile >/dev/null 2>&1

		if [ ! $? -eq 0 ]; then

			echo "export PATH=/usr/sbin:$PATH" >>/home/$1/.bash_profile
			chmod +x /home/$1/.bash_profile
		fi

 		chown -R $1:$1 /var/racvnc /home/$1 2>/dev/null
	fi

	return 0
}

#
# Configuration parameters for the init.sh startup script
#
displayNumber=1
geometry="1024x768"
depth=8
desktopName=Dell_Remote_Service
vncClasses="/var/racvnc/classes"
vncUserDir="/var/racvnc"
xauthorityFile="/var/racvnc/.Xauthority"
host=`uname -n`
vncPort=5981	# 5980 + $displayNumber
httpPort=5881	# 5880 + $displayNumber
desktopLog="$vncUserDir/$host:$displayNumber.log"
cookie=`mcookie`

#	-httpd $vncClasses
#	-httpport $httpPort

# arguments for the Xvnc command
args=":$displayNumber \
	-desktop $desktopName \
	-auth $xauthorityFile \
	-geometry $geometry \
	-depth $depth \
	-rfbwait 120000 \
	-rfbauth $vncUserDir/passwd \
	-rfbport $vncPort"


#
# CheckDisplayNumber checks if the given display number is available.  A
# display number n is taken if something is listening on the VNC server port
# (5900+n) or the X server port (6000+n).
#

CheckDisplayNumber()
{
	return 0
}
#sub CheckDisplayNumber
#{
#    local ($n) = @_;
#
#    socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
#    eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
#    if (!bind(S, pack('S n x12', $AF_INET, 6000 + $n))) {
#        close(S);
#        return 0;
#    }
#    close(S);
#
#    socket(S, $AF_INET, $SOCK_STREAM, 0) || die "$prog: socket failed: $!\n";
#    eval 'setsockopt(S, &SOL_SOCKET, &SO_REUSEADDR, pack("l", 1))';
#    if (!bind(S, pack('S n x12', $AF_INET, 5900 + $n))) {
#        close(S);
#        return 0;
#    }
#    close(S);
#
#    if (-e "/tmp/.X$n-lock") {
#        warn "\nWarning: $host:$n is taken because of /tmp/.X$n-lock\n";
#        warn "Remove this file if there is no X server $host:$n\n";
#        return 0;
#    }
#
#    if (-e "/tmp/.X11-unix/X$n") {
#        warn "\nWarning: $host:$n is taken because of /tmp/.X11-unix/X$n\n";
#        warn "Remove this file if there is no X server $host:$n\n";
#        return 0;
#    }
#
#    return 1;
#}

