#!/bin/sh # # SSH Agent Wrapper script: SAW v0.1 # # This is a simple script to wrapper a command by starting an SSH agent # for just that command, then kill it. To use it, simply prepend "saw" # to the command. # # Usage: # saw # # Example: # saw svn ci -m "blah" # # If you fix something, please send the updated version to # Paul Millar likely_identity_files="id_dsa id_rsa identity" if [ $# -lt 1 ]; then echo "saw []" echo " Runs command by first starting an ssh-agent, running , then killing the agent" exit 0 fi if [ -r "$SSH_FILE" ]; then echo "Ignoring file $SSH_FILE as it cannot be read." unset SSH_FILE fi if [ -z "$SSH_FILE" ]; then for id_file in $likely_identity_files; do if [ -r ~/.ssh/${id_file} -a -r ~/.ssh/${id_file}.pub ]; then SSH_FILE=$id_file fi done fi if [ -z "$SSH_FILE" ]; then echo "Cannot find a likely identity file: please specify one with SSH_FILE" exit 1 fi eval `ssh-agent -s` > /dev/null if [ $? -ne 0 ]; then echo "Failed to start ssh-agent, stopping." exit 1 fi ssh-add ~/.ssh/$SSH_FILE if [ $? -ne 0 ]; then echo "Failed to add the identity, stopping." eval `ssh-agent -k` > /dev/null exit 1 fi cmd="$1" shift $cmd "$@" rc=$? eval `ssh-agent -k` >/dev/null exit $rc