| gabriel rosenkoetter on Sat, 10 Aug 2002 18:30:09 +0200 |
|
... this. -- gabriel rosenkoetter gr@eclipsed.net #!/bin/sh
#
####
# Copyright (c), 2001 gabriel rosenkoetter.
#
# Feel free to use, modify, and redistribute this. I'm not silly
# enough to imagine that this is hard enough that someone else
# wouldn't come up with it originally, but do me the favor of leaving
# my copyright notice if you're just handing my script around. Thanks.
####
# usage:
#
# agent-keeper [program]
#
# ... where [program] is whatever you want to have a conception of
# your ssh-agent (if you leave it blank, ${SHELL} will be used).
#
# If there's no ssh-agent running, it wasn't agent-keeper that started
# the existing ssh-agent(s), or ${AF} references a stale ssh-agent
# (that is, the ${SSH_AUTH_SOCK} listed in it doesn't reference a
# useable named socket), a new ssh-agent is started and ssh-add is
# fed ${KEYS} (it will ask you for passphrases if your keys need
# them; with a proper ssh-add implementation, it will launch
# x11-ssh-askpass or similar to get the keys when it doesn't have a
# useable tty, as it won't if you've done all this from your X11,
# OpenWindows, whatever setup).
#
# If, on the other hand, an existing ssh-agent is found, the correct
# ${ENV} settings are made and handed to the child of agent-keeper.
# (This is by far the more usual case.)
#
# You're likely to want to change the ${SHELL} and ${KEYS} settings,
# you might as well leave ${AF} alone as long as it doesn't collide
# with other software you're using.
SHELL=`which zsh`
KEYS="${HOME}/.ssh/id_dsa ${HOME}/.ssh/id_rsa1"
AF=${HOME}/.ssh-agent
# You probably don't need to change anything below this.
if [ "x$1" = "x" ]; then
EXEC="exec ${SHELL}"
else
EXEC="exec $1"
fi
if [ -f ${AF} ]; then
# We've got a stored agent file...
eval `cat ${AF}`
if [ -r ${SSH_AUTH_SOCK} \
-a -S ${SSH_AUTH_SOCK} \
-a -O ${SSH_AUTH_SOCK} ]; then
# ... and it seems to apply to a useful ssh-agent.
${EXEC}
fi
fi
# Didn't find an extant, working ssh-agent socket
ssh-agent > ${AF}
eval `cat ${AF}`
ssh-add ${KEYS}
${EXEC}
Attachment:
pgpsBmpSltShr.pgp
|
|