summaryrefslogtreecommitdiff
path: root/prepare-connect
diff options
context:
space:
mode:
Diffstat (limited to 'prepare-connect')
-rwxr-xr-xprepare-connect34
1 files changed, 34 insertions, 0 deletions
diff --git a/prepare-connect b/prepare-connect
new file mode 100755
index 0000000..8a10b91
--- /dev/null
+++ b/prepare-connect
@@ -0,0 +1,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