summaryrefslogtreecommitdiff
path: root/xqssh
blob: 9e43fed3d6a90ff4f229655df7583dabbf1ec39d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#!/bin/sh
# Usage: xqssh <server> <local_display_number>
SSH=$(which ssh)
if [ "x$SSH" = "x" ]; then
    echo openssh is required in order to use xqssh.
    exit 1
fi
QUERY=$(ssh $1 xqproxy -display $2 -query)
echo "$QUERY"
SESSIONID=$(echo "$QUERY" | awk '/ACCEPT/ {print substr($3,12)}')
COOKIE=$(echo "$QUERY" | awk '/ACCEPT/ {print substr($7,12,32)}')
if [ "x$SESSIONID" = "x" ] || [ "x$COOKIE" = "x" ]; then
    exit 1
fi
xauth add :$2 MIT-MAGIC-COOKIE-1 $COOKIE
PORT=$(expr 6000 + $2)
ssh -R $PORT:localhost:$PORT -fN $1
ssh $1 xqproxy -display $2 -manage -sessionid $SESSIONID
exit 0