#!/bin/sh


VARS=~/.keychain/$HOSTNAME-sh
KEY=/home/tom/.ssh/2015-01-tom
LINK=/tmp/ssh-agent.tom

# FIXME: we don't want to start an agent automatically on terminal nodes.
# How to express that?
restart_agent () {
	ssh-agent | head -n2 >$VARS
	cat $VARS
	. $VARS
	rm -f $LINK
	(cd $(dirname $LINK) ; ln -sf $SSH_AUTH_SOCK $(basename $LINK))
	SSH_AUTH_SOCK=$LINK
}

add_keys () {
# Expiring these keys is just plain annoying.
#    ssh-add -t 7d $KEY
# Zero is forever
    ssh-add -t 0 $KEY
}
[ -z "$SSH_AUTH_SOCK" ] && restart_agent
[ ! -S "$SSH_AUTH_SOCK" ] && restart_agent
ssh-add -L | grep $KEY || add_keys
