summaryrefslogtreecommitdiff
path: root/prepare-connect
blob: 8a10b9104269abf0f235755a81d494eea82a7443 (plain)
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
#!/bin/sh

if [ -z "$1" ]; then
	echo "Usage: $0 <comment>" 1>&2
	exit 1
fi

comment=$1
count=`ls ~/ra/ra-*-$comment-*.tar.gz 2>/dev/null | wc -l`
if [ $count -gt 1 ]; then
	echo "More than 1 file from $comment in ~/ra. Leave only one file." 1>&2
	ls ~/ra-*-$comment-*.tar.gz
	exit 1
fi
if [ $count -eq 0 ]; then
	echo "No files with name $comment in ~/ra." 1>&2
	ls ~/ra-*-$comment-*.tar.gz
	exit 1
fi
file=`ls ~/ra/ra-*-$comment-*.tar.gz`
port=`echo $file | sed 's/.*ra-\([^-]\+\)-.*/\1/'`
keyfile=`echo $file | sed 's/.tar.gz$/-key/'`
tar xzf $file -O key > $keyfile
chmod 600 $keyfile
perl -e '$host="'ra-$comment'"; $/=undef; $_=<>; s/^Host\s+(${host}$).*?((?=^Host)|\s*\Z)//gsm; print' ~/.ssh/config > ~/.ssh/config.new
cat >> ~/.ssh/config.new <<EOF
Host ra-$comment
	HostName localhost
	User support
	Port $port
	IdentityFile $keyfile
	ForwardX11 no
EOF
mv -f ~/.ssh/config.new ~/.ssh/config