#
#
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice (including the next
# paragraph) shall be included in all copies or substantial portions of the
# Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.
#
USAGE="Usage: $0 [-c <class>] :<display> [<X server arguments>]"
progname=$0
function fatal_error
{
print -u2 "${progname}: $*"
exit 1
}
#########
#
# Default values
#
# Users must not modify this script to change them - change via SMF properties
#
DISPLAY="0"
DEFDEPTH=""
CLASSES=""
TCP_LISTEN=""
SERVERARGS=""
CONSOLE=""
CONFIG_FILE=""
while getopts :c: opt; do
c) CLASSES+=" :${OPTARG}" ;;
esac
done
if (( $# > 1 )) ; then
case $1 in
:*)
# Strip leading ":" from $1 to get display number
DISPLAY="${1#:}"
shift
;;
esac
fi
REMOTE="false"
case $a in
REMOTE="true"
;;
*)
# Do nothing
;;
esac
done
if [[ "${REMOTE}" == "true" ]] ; then
CLASSES+=" :remote"
else
CLASSES+=" :local"
fi
# Arguments:
# 1) name of SMF property to find in one of the service instances
# 2) name of variable to store the value of the property in, if found
# Also sets variable with name of $2_INSTANCE to the service instance the
# property was found in, for use in later messages.
function getprop {
# Make ${propval} be a reference to the variable named as the second arg
nameref propval=$2
nameref propinst="${2}_INSTANCE"
# The "" instance is to get the properties from the base service without
# any instance specifier
propinst="svc:/application/x11/x11-server${instance}"
if [[ "${propval}" == "\"\"" ]] ; then
propval=""
fi
return 0
fi
done
return 1
}
# Get the platform name that uses Xvnc instead of Xorg and clean it up.
# Determine if this is a supported platform for VNC.
ISVNCPLATFORM=false
if [[ ("${hwname}" != "") ]]; then
if [[ $? -eq 0 ]] ; then
ISVNCPLATFORM=true
fi
fi
if [[ ("${ISVNCPLATFORM}" != "true") && (-e "${MDESC}") ]]; then
if [[ $? -eq 0 ]] ; then
ISVNCPLATFORM=true
fi
fi
# Check if this is a platform that should use Xvnc or Xorg.
# Configure x11-server to run Xvnc instead of Xorg for ${VNCPLATFORM}
if ${ISVNCPLATFORM} ; then
SERVERARGS="-SecurityTypes=TLSNone -DisconnectClients=false -NeverShared -IdleTimeout=3600 -interface 169.254.182.77 -screenlock"
svccfg -s application/x11/x11-server setprop \
# Need single quotes due to some shells having issue with spaces.
svccfg -s application/x11/x11-server setprop \
options/server_args = astring: '"-SecurityTypes=TLSNone -DisconnectClients=false -NeverShared -IdleTimeout=3600 -interface 169.254.182.77 -screenlock"'
fi
else
# This check is needed in case the system is booted from a cloned archive.
if ! ${ISVNCPLATFORM} ; then
SERVERARGS=""
svccfg -s application/x11/x11-server setprop \
svccfg -s application/x11/x11-server setprop \
fi
fi
ORIGINAL_XSERVER="${XSERVER}"
if [[ -f ${XSERVER} ]] ; then
# via the /usr/X -> openwin or X11 link
else
# Automatically select replacements for removed X servers
*/Xsun)
;;
*/Xvfb)
;;
;;
;;
*)
fatal_error "${XSERVER} is not an executable"
;;
esac
XSERVER="${newserver}"
fi
# Make sure ${XSERVER} is a known X server binary
function is_known_xserver {
esac
return 1
}
if ! is_known_xserver "${ORIGINAL_XSERVER}" ; then
if ! is_known_xserver "${XSERVER}" ; then
fatal_error "${XSERVER} is not a valid X server"
fi
fi
# Xsun based
DEPTHARG="-defdepth ${DEFDEPTH:-24}"
;;
# Xorg based
if [[ "${DEFDEPTH}" != "" ]] ; then
DEPTHARG="-depth ${DEFDEPTH}"
fi
;;
esac
# Should not happen, but just in case
if [[ "${TCP_LISTEN}" == "" ]] ; then
if [[ "${REMOTE}" == "true" ]] ; then
TCP_LISTEN="true"
else
TCP_LISTEN="false"
fi
fi
if [[ "${TCP_LISTEN}" == "false" ]] ; then
LISTENARG="-nolisten tcp"
else
LISTENARG="-listen tcp"
fi
if [[ ("${CONSOLE}" == "true") && ("${DISPLAY}" == "0") ]] ; then
CONSOLE="-C"
else
CONSOLE=""
fi
# Currently only Xorg accepts a command line flag for choosing config files.
# If other X servers add such flags in the future, they should be added here.
# Only filenames without directory paths are allowed (similar to when a
# non-root user runs Xorg -config) to avoid security issues.
CONFIGARG=""
if [[ ! -z "${CONFIG_FILE}" ]] ; then
case ${CONFIG_FILE} in
*/*) fatal_error "Illegal value for config_file property" ;;
esac
esac
fi
ALLARGS="${DEPTHARG} ${LISTENARG} ${SERVERARGS} ${CONSOLE} ${CONFIGARG} $*"
# Remove unneeded arguments for Xvnc.
ALLARGS=${ALLARGSVNC}
fi
exec ${XSERVER} :${DISPLAY} ${ALLARGS}