3 #=======================================================================
5 # File ID: 307e8876-e099-11e0-94c2-ef2688b28a12
7 # Create/terminate SSH tunnel or set up VNC connection.
9 # Author: Øyvind A. Holm <sunny@sunbase.org>
10 # License: GNU General Public License version 2 or later.
11 #=======================================================================
35 " -n "$progname" -- "$@
")"
36 test "$?" = "0" ||
exit 1
49 -c|
--connect) opt_connect
=1; shift ;;
50 -h|
--help) opt_help
=1; shift ;;
51 -k|
--kill) opt_kill
=1; shift ;;
52 -l|
--list) opt_list
=1; shift ;;
53 -q|
--quiet) opt_quiet
=$
(($opt_quiet + 1)); shift ;;
54 -t|
--tunnel) opt_tunnel
=1; shift ;;
55 -V|
--vnc) opt_vnc
=$2; shift 2 ;;
56 -v|
--verbose) opt_verbose
=$
(($opt_verbose + 1)); shift ;;
57 --version) echo $progname $VERSION; exit 0 ;;
59 *) echo $progname: Internal error
>&2; exit 1 ;;
62 opt_verbose
=$
(($opt_verbose - $opt_quiet))
64 rcfile
="$HOME/.sshtrc"
66 if test "$opt_help" = "1"; then
67 test $opt_verbose -gt 0 && { echo; echo $progname $VERSION; }
70 Create/terminate SSH tunnel or set up VNC connection.
72 Usage: $progname [options]
77 Connect to SSH tunnel from outside.
83 List PID of active tunnel.
85 Be more quiet. Can be repeated to increase silence.
87 Create SSH tunnel if none exist yet.
89 Increase level of verbosity. Can be repeated.
90 -V DISPLAY [QUALITY], --vnc DISPLAY [QUALITY]
91 Connect via VNC to display DISPLAY. QUALITY can be 0 (worst, but
92 great compression) to 9 (best quality). If QUALITY is not specified,
93 top quality and no compression is used.
95 Print version information.
98 is a regular shell script used for setting constants:
101 Port number for SSH tunnel. Choose something random above 1024,
102 preferably not listed in /etc/services .
104 SSH username and host on the format USER@HOST .
106 SSH username used with -c/--connect option.
108 Command to set up the SSH tunnel. If not defined, a default value is
116 echo "$progname: $*" >&2
119 test -e "$rcfile" && .
"$rcfile"
121 if test -z "$SSHT_PORT"; then
122 msg SSHT_PORT environment variable is not defined
125 if test -z "$SSHT_HOST"; then
126 msg SSHT_HOST environment variable is not defined
129 if test -z "$SSHT_CMD"; then
130 SSHT_CMD
="ssh -A -Y -q -N -R $SSHT_PORT:localhost:22 $SSHT_HOST"
134 SSHT_PID
=$
(pgrep
-f -x "$SSHT_CMD")
136 if test "$opt_connect" = "1"; then
137 if test -z "$SSHT_USERNAME"; then
138 msg SSHT_USERNAME environment variable is not defined
141 sess
-t c_ssht.c
-- ssh -A -Y -p $SSHT_PORT -l $SSHT_USERNAME localhost
142 elif test "$opt_kill" = "1"; then
143 test -n "$SSHT_PID" ||
{ msg No tunnel found
; exit 1; }
145 elif test "$opt_list" = "1"; then
146 test -n "$SSHT_PID" && echo $SSHT_PID
147 elif test "$opt_tunnel" = "1"; then
148 test -n "$SSHT_PID" && {
149 msg Tunnel already active
at PID
$SSHT_PID
152 # FIXME: Create some standardised version of this
153 ps x |
grep "bash -c while :; do date; sleep 2; done" |
154 grep -v "grep " |
awk '{print $1}' |
xargs -r kill
155 sess
-t c_ssht.t
-- $SSHT_CMD &
156 elif test -n "$opt_vnc"; then
158 pkill
-9 -f "ssh -L 590$opt_vnc:localhost:590$opt_vnc"
159 msg Creating
ssh tunnel...
160 sess
-d ssh_tunnel
-- \
161 ssh -L 590$opt_vnc:localhost
:590$opt_vnc -C -N -f $SSHT_HOST
163 if test -n "$1"; then
164 quality_str
="-quality $1"
165 msg Starting xtightvncviewer with quality
$1...
166 sess
-- xtightvncviewer
-encodings tight
-depth 16 -compresslevel 9 \
167 -nocursorshape $quality_str localhost
:$opt_vnc
169 msg Starting xtightvncviewer with top quality...
170 sess
-- xtightvncviewer
-encodings tight
-truecolour -nojpeg \
171 -nocursorshape localhost
:$opt_vnc
173 msg Destroying
ssh tunnel...
174 pkill
-9 -f "ssh -L 590$opt_vnc:localhost:590$opt_vnc"
176 msg No option specified