#!/bin/sh if [ -z "$1" ]; then echo "Usage: $0 " 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/ra-*-$comment-*.tar.gz exit 1 fi if [ $count -eq 0 ]; then echo "No files with name $comment in ~/ra." 1>&2 ls ~/ra/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 <