1#!/bin/sh 2# 3# Copyright (c) 2006-2009 by Karl J. Runge <runge@karlrunge.com> 4# 5# ssvnc_cmd: 6# 7# A wrapper that calls ss_vncviewer to use the enhanced TightVNC viewer. 8# 9# The enhanced TightVNC viewer features are: 10# 11# - SSL support for connections using the co-bundled stunnel program. 12# - rfbNewFBSize VNC support (screen resizing) 13# - cursor alphablending with x11vnc at 32bpp 14# - xgrabserver support for fullscreen mode (for old window mgrs) 15# 16# 17# Your platform (e.g. Linux.i686) is autodetected and enhanced 18# vncviewer and stunnel binaries for it are used (see the ./bin directory). 19# 20# See the build.unix script if your platform is not in this package. 21# You can also set the env. var. UNAME=os.arch to any "os.arch" you want 22# to override the autodetetion. 23# 24# Usage: 25# 26# ssvnc_cmd [ss_vncviewer-args] hostname:N [vncviewer-args] 27# 28# if, instead, this script is named "tightvncviewer" or "-viewer" is the 29# first argument it calls the vncviewer directly (there is no encryption) 30# and must be invoked as: 31# 32# tightvncviewer [vncviewer-args] hostname:N 33# or 34# 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.) 38# 39# See the script util/ss_vncviewer for details about its arguments: 40# 41# -verify pemfile 42# -mycert pemfile 43# -proxy phost:pport 44# -alpha 45# -grab 46# 47# N.B. if this script is named "tightvncviewer" the vncviewer is called 48# directly, and there won't be any SSL or SSH encryption tunnels. 49# 50# If the *very first* argument is "-cotvnc" then it is assumed you are on 51# Darwin and want to run the Chicken of the VNC viewer via our wrapper. 52# 53# 54# See the TightVNC viewer documentation for on its cmdline arguments. 55# 56# For convenience, here is the TightVNC 1.3dev5 viewer -help output: 57# 58# TightVNC viewer version 1.3dev5 59# 60# Usage: vncviewer [<OPTIONS>] [<HOST>][:<DISPLAY#>] 61# vncviewer [<OPTIONS>] [<HOST>][::<PORT#>] 62# vncviewer [<OPTIONS>] -listen [<DISPLAY#>] 63# vncviewer -help 64# 65# <OPTIONS> are standard Xt options, or: 66# -via <GATEWAY> 67# -shared (set by default) 68# -noshared 69# -viewonly 70# -fullscreen 71# -noraiseonbeep 72# -passwd <PASSWD-FILENAME> (standard VNC authentication) 73# -user <USERNAME> (Unix login authentication) 74# -encodings <ENCODING-LIST> (e.g. "tight copyrect") 75# -bgr233 76# -owncmap 77# -truecolour 78# -depth <DEPTH> 79# -compresslevel <COMPRESS-VALUE> (0..9: 0-fast, 9-best) 80# -quality <JPEG-QUALITY-VALUE> (0..9: 0-low, 9-high) 81# -nojpeg 82# -nocursorshape 83# -x11cursor 84# -autopass 85# 86# Option names may be abbreviated, e.g. -bgr instead of -bgr233. 87# See the manual page for more information. 88# 89# Note: the enhanced tightvnc viewer (SSVNC) has many more options, run 90# this script as "ssvnc_cmd Vnc://a:0 -help" or "tightvncviewer -help" 91# to seem them. 92 93if [ "X$1" = "X-h" -o "X$1" = "X-helpxxx" -o "X$1" = "X--help" ]; then 94 tail -n +2 "$0" | sed -e '/^$/ q' -e 's/^#//' 95 exit 96fi 97 98# Include /usr/bin... to be sure to get regular utilities: 99# 100PATH=$PATH:/usr/bin:/bin 101export PATH 102 103if [ "X$FULLNAME" = "XKarl J. Runge" ]; then 104 if [ "X$NOPOPUFIX" = "X" ]; then 105 VNCVIEWER_POPUP_FIX=1 106 export VNCVIEWER_POPUP_FIX 107 fi 108 PATH=`echo "$PATH" | sed -e 's,runge/bin/override,-------------,'` 109fi 110 111# Set this for ss_vncviewer to pick up: 112# 113if [ "X$1" = "X-cotvnc" ]; then 114 shift 115 DARWIN_COTVNC=1 116 export DARWIN_COTVNC 117elif [ "X$DARWIN_COTVNC" = "X" -a "X$DISPLAY" = "X" ]; then 118 uname=`uname` 119 if [ "X$uname" = "XDarwin" ]; then 120 DARWIN_COTVNC=1 121 export DARWIN_COTVNC 122 fi 123fi 124 125use_ours=0 126if [ "X$VNCVIEWERCMD" = "X" ]; then 127 VNCVIEWERCMD="vncviewer" 128 export VNCVIEWERCMD 129 if [ "X$DARWIN_COTVNC" != "X1" ]; then 130 use_ours=1 131 fi 132fi 133 134# work out os.arch platform string and check for binaries: 135# 136name=$UNAME 137if [ "X$name" = "X" ]; then 138 name=`uname -sm | sed -e 's/ /./g' -e 's,/.*,,' -e 's/Linux\.i.86/Linux.i686/'` 139fi 140 141dL="-L" 142if uname -sr | egrep 'SunOS 5\.[5-8]' > /dev/null; then 143 dL="-h" 144fi 145 146f="$0" 147for t in 1 2 3 4 5 6 148do 149 if [ $dL "$f" ]; then 150 f0="$f" 151 f=`ls -l "$f" | sed -e 's/^.* -> //'` 152 if echo "$f" | grep '^/' > /dev/null; then 153 : 154 else 155 f="`dirname "$f0"`/$f" 156 fi 157 else 158 break 159 fi 160done 161dir=`dirname "$f"` 162PATH="$dir:$PATH" 163SSVNC_BASEDIR="$dir" 164export SSVNC_BASEDIR 165SSVNC_BASEDIRNAME="$dir/$name" 166export SSVNC_BASEDIRNAME 167SSVNC_UNAME="$name" 168export SSVNC_UNAME 169 170nearby=0 171if [ -x "$dir/vncviewer" -a -x "$dir/stunnel" ]; then 172 nearby=1 173fi 174if [ "X$name" = "X." ]; then 175 : 176 #type vncviewer 177 #type stunnel 178elif [ ! -d "$dir/$name" -a $nearby = 0 ]; then 179 echo 180 echo "Cannot find platform dir for your OS `uname -sm`:" 181 echo 182 echo " $dir/$name" 183 echo 184 PATH=$PATH:/usr/sbin:/usr/local/sbin:/dist/sbin 185 186 quit=0 187 if type vncviewer >/dev/null 2>/dev/null; then 188 : 189 else 190 echo "vncviewer not found in PATH." 191 quit=1 192 fi 193 if type stunnel >/dev/null 2>/dev/null; then 194 : 195 else 196 echo "stunnel not found in PATH." 197 quit=1 198 fi 199 echo 200 if [ "X$quit" = "X1" ]; then 201 echo "You can set the \$UNAME env. var. to override the OS setting." 202 echo "Or, if available, run the ./build.unix script to build it." 203 echo "Or install external \"vncviewer\" and \"stunnel\" packages." 204 exit 1 205 fi 206 echo "Using externel \"vncviewer\" and \"stunnel\" found in PATH." 207 208else 209 STUNNEL=stunnel 210 #STUNNEL_EXTRA_OPTS=${STUNNEL_EXTRA_OPTS:-"maxconn = 1"} 211 #export STUNNEL STUNNEL_EXTRA_OPTS 212 SSVNC_VIEWER_INTERNAL=1 213 export SSVNC_VIEWER_INTERNAL 214fi 215 216if [ "X$DARWIN_COTVNC" != "X1" -a "X$VNCVIEWERCMD" = "Xvncviewer" ]; then 217 hstr=`$VNCVIEWERCMD -h 2>&1 | head -5` 218 if echo "$hstr" | grep 'SSVNC.*TightVNC.*version 1\.3' > /dev/null; then 219 # we need to avoid raw encoding 220 use_ours=1 221 fi 222fi 223 224# Put our os.arch and other utils dirs at head of PATH to be sure to 225# pick them up: 226# 227PATH="$dir:$dir/$name:$dir/util:$PATH" 228if echo "$dir" | grep '^/' > /dev/null; then 229 : 230else 231 dir=`pwd`/$dir 232 PATH="$dir:$dir/$name:$dir/util:$PATH" 233fi 234 235if [ -f "$dir/util/ultraftp.jar" ]; then 236 SSVNC_ULTRA_FTP_JAR="$dir/util/ultraftp.jar" 237 export SSVNC_ULTRA_FTP_JAR 238fi 239 240base=`basename "$0"` 241if [ "X$1" = "X-ssl" ]; then 242 shift 243 base="ssvnc_cmd" 244fi 245 246do_viewer_directly="" 247if [ "X$1" = "X-viewer" ]; then 248 do_viewer_directly=1 249 shift 250fi 251if [ "X$base" = "Xtightvncviewer" ]; then 252 do_viewer_directly=1 253fi 254 255# If ours (and not cotvnc), force the use of tight encoding for localhost 256# redir connection: 257# 258# 259if [ $use_ours = 1 ]; then 260 # avoid system vncviewer app-defaults 261 #XFILESEARCHPATH="/tmp/path/nowhere"; export XFILESEARCHPATH 262 263 SSVNC_USE_OURS=1; export SSVNC_USE_OURS 264 265 if [ "X$SSVNC_TURBOVNC" != "X" ]; then 266 if echo "$VNCVIEWERCMD" | grep '\.turbovnc' > /dev/null; then 267 : 268 else 269 if type "$VNCVIEWERCMD.turbovnc" > /dev/null 2>/dev/null; then 270 VNCVIEWERCMD="$VNCVIEWERCMD.turbovnc" 271 fi 272 fi 273 fi 274 275 if [ "X$do_viewer_directly" = "X1" ]; then 276 $VNCVIEWERCMD -encodings 'copyrect tight zrle zlib hextile' "$@" 277 else 278 ss_vncviewer "$@" -encodings 'copyrect tight zrle zlib hextile' 279 fi 280else 281 if [ "X$do_viewer_directly" = "X1" ]; then 282 $VNCVIEWERCMD "$@" 283 else 284 ss_vncviewer "$@" 285 fi 286fi 287