File: dxpcssh

package info (click to toggle)
dxpc 3.9.2-1
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 1,140 kB
  • ctags: 1,253
  • sloc: cpp: 12,036; sh: 2,823; makefile: 78
file content (91 lines) | stat: -rwxr-xr-x 2,974 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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
89
90
91
#!/bin/bash
#
# dxpcssh - dxpc over SSH2
# Wicher Minnaard <wicher@huizehennep.demon.nl>
# August 23 '05
#
# Sets up an xclient <--> dxpc <--> sshtunnel <--> dxpc <--> xserver (you!)
# construction. Assumes you have set up passwordless SSH logins. Does not
# require the OpenSSH X11 forwarding option.
# Sets up _new_ ~/.Xauthority files on server and client, so backup the old ones
# if you really like 'em.
# Also, it requires you to have a script called xauthcp in $PATH on the remote
# host. xauthcp was written by Bruce Mah <bmah@cs.berkeley.edu> and modified for
# sh-shells by Dirk Eddelbttel <Dirk.Eddelbuettel@qed.econ.queensu.ca>.
# Thanks for the hints!
# xauth is listed below. If anyone thinks of a way to do the xauthcp-stuff
# from inside  this script, please implement it (and drop me a line).



if [ $# -ne 3 ]
then
echo "Usage: $0 remote-host remote-SSHD-port (buildup | teardown)"
exit -1
fi

REMOTEHOST=$1
REMOTESSHDPORT=$2
DISPLAYNUMBER=$((`ssh -p $REMOTESSHDPORT $REMOTEHOST id -u` - 1000))
DXPCPORT=$((4000+$DISPLAYNUMBER))
rm ~/.Xauthority &>/dev/null
ssh -p $REMOTESSHDPORT $REMOTEHOST rm ~/.Xauthority &>/dev/null
mcookie | sed -e 's/^/add :0 . /' | xauth -q &>/dev/null
LOCALDISPLAY=`xauth list | cut -d " " -f 1`

if [ $3 = buildup ]
then
	xauth nextract - $LOCALDISPLAY | ssh -p $REMOTESSHDPORT $REMOTEHOST /usr/bin/X11/xauth nmerge - &>/dev/null
	ssh -p $REMOTESSHDPORT $REMOTEHOST xauthcp $LOCALDISPLAY $REMOTEHOST:/unix:$DISPLAYNUMBER
	ssh -p $REMOTESSHDPORT $REMOTEHOST xauthcp $LOCALDISPLAY $REMOTEHOST:$DISPLAYNUMBER

	ssh -p $REMOTESSHDPORT $REMOTEHOST dxpc -k &>/dev/null
	ssh -f -p $REMOTESSHDPORT $REMOTEHOST DISPLAY="$LOCALDISPLAY" dxpc -p $DXPCPORT -f -d $DISPLAYNUMBER
	sleep 5
	ssh -N -f -p $REMOTESSHDPORT -g -L $DXPCPORT:$REMOTEHOST:$DXPCPORT $REMOTEHOST 
	dxpc -k &>/dev/null
	dxpc -p $DXPCPORT -f -ba localhost
	
	echo "Done. Start programs by issuing:"
	echo "ssh -f -p $REMOTESSHDPORT $REMOTEHOST DISPLAY=\"$REMOTEHOST:$DISPLAYNUMBER\" _your_program_"
fi

if [ $3 = teardown ]
then
	fuser -k $DXPCPORT/tcp &>/dev/null
	ssh -p $REMOTESSHDPORT $REMOTEHOST dxpc -k &>/dev/null
	ssh -p $REMOTESSHDPORT $REMOTEHOST killall dxpc &>/dev/null
	dxpc -k &>/dev/null
	killall dxpc &>/dev/null
	echo "Teared down the tunnel."
fi


##!/bin/sh
##
## xauthcp
## Bruce A. Mah <bmah@CS.Berkeley.EDU>
##
## 12 Jul 96edd@qed.econ.queensu.ca Rewritten as a (ba)sh script
##
## Copy xauth keys used to access one display to another.  This ability
## is primarily useful when using a proxy X server.  In such a situation,
## client processes need to access the proxy using the xauth keys of the
## real server (assuming the proxy takes no explicit actions to deal
## with xauth keys).
#
#if [ $# -ne 2 ]
#then
#echo $0 source-display dest-display
#exit -1
#fi
#
#src=$1
#dst=$2
#tmpfile=/tmp/xauthcp.$$
#
#rm -f $tmpfile
#xauth list $src | \
#awk -v dst=$dst '{ print "xauth add", dst, $2, $3, "; "}' > $tmpfile
#source $tmpfile
#rm -f $tmpfile