ssvnc_cmd 7.24 KB
Newer Older
runge's avatar
runge committed
1 2
#!/bin/sh
#
3
# Copyright (c) 2006-2009 by Karl J. Runge <runge@karlrunge.com>
runge's avatar
runge committed
4
#
runge's avatar
runge committed
5
# ssvnc_cmd:
runge's avatar
runge committed
6
#
runge's avatar
runge committed
7
#    A wrapper that calls ss_vncviewer to use the enhanced TightVNC viewer. 
runge's avatar
runge committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#
# The enhanced TightVNC viewer features are:
#
#	- SSL support for connections using the co-bundled stunnel program.
#	- rfbNewFBSize VNC support (screen resizing)
#	- cursor alphablending with x11vnc at 32bpp
#	- xgrabserver support for fullscreen mode (for old window mgrs)
#
#
# Your platform (e.g. Linux.i686) is autodetected and enhanced
# vncviewer and stunnel binaries for it are used (see the ./bin directory).
#
# See the build.unix script if your platform is not in this package.
# You can also set the env. var. UNAME=os.arch to any "os.arch" you want
# to override the autodetetion.
#
# Usage:
#
26
#     ssvnc_cmd [ss_vncviewer-args] hostname:N [vncviewer-args]
runge's avatar
runge committed
27
#
28 29 30
#  if, instead, this script is named "tightvncviewer" or "-viewer" is the
#  first argument it calls the vncviewer directly (there is no encryption)
#  and must be invoked as:
31 32
#
#     tightvncviewer [vncviewer-args] hostname:N
33 34
#  or
#     ssvnc_cmd -viewer [vncviewer-args] hostname:N
35 36
#
# In both cases, "hostname:N" is the host and VNC display to connect to,
37
# e.g. snoopy:0. (-listen N and -appshare N modes works too.)
runge's avatar
runge committed
38
#
runge's avatar
runge committed
39
# See the script util/ss_vncviewer for details about its arguments:
runge's avatar
runge committed
40 41 42 43 44 45 46
#
#	-verify pemfile
#	-mycert pemfile
#	-proxy  phost:pport
#	-alpha
#	-grab
#
47 48
# N.B. if this script is named "tightvncviewer" the vncviewer is called
# directly, and there won't be any SSL or SSH encryption tunnels.
runge's avatar
runge committed
49 50 51 52 53 54 55
#
# If the *very first* argument is "-cotvnc" then it is assumed you are on
# Darwin and want to run the Chicken of the VNC viewer via our wrapper.
#
#
# See the TightVNC viewer documentation for on its cmdline arguments.
#
56
# For convenience, here is the TightVNC 1.3dev5 viewer -help output:
runge's avatar
runge committed
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88
#
#       TightVNC viewer version 1.3dev5
#       
#       Usage: vncviewer [<OPTIONS>] [<HOST>][:<DISPLAY#>]
#              vncviewer [<OPTIONS>] [<HOST>][::<PORT#>]
#              vncviewer [<OPTIONS>] -listen [<DISPLAY#>]
#              vncviewer -help
#       
#       <OPTIONS> are standard Xt options, or:
#               -via <GATEWAY>
#               -shared (set by default)
#               -noshared
#               -viewonly
#               -fullscreen
#               -noraiseonbeep
#               -passwd <PASSWD-FILENAME> (standard VNC authentication)
#               -user <USERNAME> (Unix login authentication)
#               -encodings <ENCODING-LIST> (e.g. "tight copyrect")
#               -bgr233
#               -owncmap
#               -truecolour
#               -depth <DEPTH>
#               -compresslevel <COMPRESS-VALUE> (0..9: 0-fast, 9-best)
#               -quality <JPEG-QUALITY-VALUE> (0..9: 0-low, 9-high)
#               -nojpeg
#               -nocursorshape
#               -x11cursor
#               -autopass
#       
#       Option names may be abbreviated, e.g. -bgr instead of -bgr233.
#       See the manual page for more information.
#  
89 90 91
# Note: the enhanced tightvnc viewer (SSVNC) has many more options, run
# this script as "ssvnc_cmd Vnc://a:0 -help" or "tightvncviewer -help"
# to seem them.
runge's avatar
runge committed
92

93 94
if [ "X$1" = "X-h" -o "X$1" = "X-helpxxx" -o "X$1" = "X--help" ]; then
	tail -n +2 "$0" | sed -e '/^$/ q' -e 's/^#//' 
runge's avatar
runge committed
95 96 97 98 99 100 101 102
	exit
fi

# Include /usr/bin... to be sure to get regular utilities:
#
PATH=$PATH:/usr/bin:/bin
export PATH

103
if [ "X$FULLNAME" = "XKarl J. Runge" ]; then
104 105 106 107
	if [ "X$NOPOPUFIX" = "X" ]; then
		VNCVIEWER_POPUP_FIX=1
		export VNCVIEWER_POPUP_FIX
	fi
108 109 110
	PATH=`echo "$PATH" | sed -e 's,runge/bin/override,-------------,'`
fi

runge's avatar
runge committed
111
# Set this for ss_vncviewer to pick up:
runge's avatar
runge committed
112 113 114 115 116
#
if [ "X$1" = "X-cotvnc" ]; then
	shift
	DARWIN_COTVNC=1
	export DARWIN_COTVNC
runge's avatar
runge committed
117 118 119 120 121 122
elif [ "X$DARWIN_COTVNC" = "X" -a "X$DISPLAY" = "X" ]; then
	uname=`uname`
	if [ "X$uname" = "XDarwin" ]; then
		DARWIN_COTVNC=1
		export DARWIN_COTVNC
	fi
runge's avatar
runge committed
123
fi
runge's avatar
runge committed
124 125

use_ours=0
runge's avatar
runge committed
126 127 128
if [ "X$VNCVIEWERCMD" = "X" ]; then
	VNCVIEWERCMD="vncviewer"
	export VNCVIEWERCMD
129
	if [ "X$DARWIN_COTVNC" != "X1" ]; then
runge's avatar
runge committed
130 131 132 133 134 135 136 137
		use_ours=1
	fi
fi

# work out os.arch platform string and check for binaries:
#
name=$UNAME
if [ "X$name" = "X" ]; then
138
	name=`uname -sm | sed -e 's/ /./g' -e 's,/.*,,' -e 's/Linux\.i.86/Linux.i686/'`
runge's avatar
runge committed
139 140
fi

141 142 143 144 145
dL="-L"
if uname -sr | egrep 'SunOS 5\.[5-8]' > /dev/null; then
	dL="-h"
fi

runge's avatar
runge committed
146
f="$0"
runge's avatar
runge committed
147
for t in 1 2 3 4 5 6
runge's avatar
runge committed
148
do
149
	if [ $dL "$f" ]; then
runge's avatar
runge committed
150 151 152 153 154 155 156 157 158 159 160 161
		f0="$f"
		f=`ls -l "$f" | sed -e 's/^.* -> //'`
		if echo "$f" | grep '^/' > /dev/null; then
			:
		else
			f="`dirname "$f0"`/$f"
		fi
	else
		break
	fi
done
dir=`dirname "$f"`
runge's avatar
runge committed
162
PATH="$dir:$PATH"
163 164
SSVNC_BASEDIR="$dir"
export SSVNC_BASEDIR
165 166
SSVNC_BASEDIRNAME="$dir/$name"
export SSVNC_BASEDIRNAME
167 168
SSVNC_UNAME="$name"
export SSVNC_UNAME
runge's avatar
runge committed
169 170 171 172 173

nearby=0
if [ -x "$dir/vncviewer" -a -x "$dir/stunnel" ]; then
	nearby=1
fi
174 175 176 177 178
if [ "X$name" = "X." ]; then
	:
	#type vncviewer
	#type stunnel
elif [ ! -d "$dir/$name" -a $nearby = 0 ]; then
runge's avatar
runge committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206
	echo
	echo "Cannot find platform dir for your OS `uname -sm`:"
	echo
	echo "    $dir/$name" 
	echo
	PATH=$PATH:/usr/sbin:/usr/local/sbin:/dist/sbin

	quit=0
	if type vncviewer >/dev/null 2>/dev/null; then
		:
	else
		echo "vncviewer not found in PATH." 
		quit=1
	fi
	if type stunnel >/dev/null 2>/dev/null; then
		:
	else
		echo "stunnel not found in PATH."
		quit=1
	fi
	echo
	if [ "X$quit" = "X1" ]; then
		echo "You can set the \$UNAME env. var. to override the OS setting."
		echo "Or, if available, run the ./build.unix script to build it."
		echo "Or install external \"vncviewer\" and \"stunnel\" packages."
		exit 1
	fi
	echo "Using externel \"vncviewer\" and \"stunnel\" found in PATH."
runge's avatar
runge committed
207

runge's avatar
runge committed
208
else
runge's avatar
runge committed
209
	STUNNEL=stunnel
210 211
	#STUNNEL_EXTRA_OPTS=${STUNNEL_EXTRA_OPTS:-"maxconn = 1"}
	#export STUNNEL STUNNEL_EXTRA_OPTS
runge's avatar
runge committed
212 213
	SSVNC_VIEWER_INTERNAL=1
	export SSVNC_VIEWER_INTERNAL
runge's avatar
runge committed
214 215
fi

216
if [ "X$DARWIN_COTVNC" != "X1" -a "X$VNCVIEWERCMD" = "Xvncviewer" ]; then
runge's avatar
runge committed
217
	hstr=`$VNCVIEWERCMD -h 2>&1 | head -5`
218
	if echo "$hstr" | grep 'SSVNC.*TightVNC.*version 1\.3' > /dev/null; then
runge's avatar
runge committed
219 220 221
		# we need to avoid raw encoding
		use_ours=1
	fi
runge's avatar
runge committed
222 223 224 225 226 227 228 229 230 231 232 233 234
fi

# Put our os.arch and other utils dirs at head of PATH to be sure to
# pick them up:
#
PATH="$dir:$dir/$name:$dir/util:$PATH"
if echo "$dir" | grep '^/' > /dev/null; then
	:
else
	dir=`pwd`/$dir
	PATH="$dir:$dir/$name:$dir/util:$PATH"
fi

235 236 237 238 239
if [ -f "$dir/util/ultraftp.jar" ]; then
	SSVNC_ULTRA_FTP_JAR="$dir/util/ultraftp.jar"
	export SSVNC_ULTRA_FTP_JAR
fi

runge's avatar
runge committed
240 241 242 243 244
base=`basename "$0"`
if [ "X$1" = "X-ssl" ]; then
	shift	
	base="ssvnc_cmd"
fi
runge's avatar
runge committed
245

246 247 248 249 250 251 252 253 254
do_viewer_directly=""
if [ "X$1" = "X-viewer" ]; then
	do_viewer_directly=1
	shift	
fi
if [ "X$base" = "Xtightvncviewer" ]; then
	do_viewer_directly=1
fi

runge's avatar
runge committed
255 256 257 258 259
# If ours (and not cotvnc), force the use of tight encoding for localhost
# redir connection:
#
#
if [ $use_ours = 1 ]; then
260 261 262
	# avoid system vncviewer app-defaults
	#XFILESEARCHPATH="/tmp/path/nowhere"; export XFILESEARCHPATH

263 264
	SSVNC_USE_OURS=1; export SSVNC_USE_OURS

265 266 267 268 269 270 271 272 273 274
	if [ "X$SSVNC_TURBOVNC" != "X" ]; then
		if echo "$VNCVIEWERCMD" | grep '\.turbovnc' > /dev/null; then
			:
		else
			if type "$VNCVIEWERCMD.turbovnc" > /dev/null 2>/dev/null; then
				VNCVIEWERCMD="$VNCVIEWERCMD.turbovnc"
			fi
		fi
	fi

275
	if [ "X$do_viewer_directly" = "X1" ]; then
runge's avatar
runge committed
276
		$VNCVIEWERCMD -encodings 'copyrect tight zrle zlib hextile' "$@"
runge's avatar
runge committed
277 278 279
	else
		ss_vncviewer "$@" -encodings 'copyrect tight zrle zlib hextile'
	fi
runge's avatar
runge committed
280
else
281
	if [ "X$do_viewer_directly" = "X1" ]; then
runge's avatar
runge committed
282
		$VNCVIEWERCMD "$@"
runge's avatar
runge committed
283 284 285
	else
		ss_vncviewer "$@"
	fi
runge's avatar
runge committed
286
fi