2020-09-21 12:39:58 +02:00
|
|
|
|
#!/bin/bash
|
|
|
|
|
|
2020-09-21 13:00:56 +02:00
|
|
|
|
[ -n "${SSH_AGENTS_DIR+x} ] && { AGENTS_DIR=${HOME}/.ssh/agents; export AGENTS_DIR; }
|
|
|
|
|
[ -n "${SSH_AGENT_SOCKETS_DIR+x} ] && { AGENTS_DIR=${HOME}/.ssh/agents; export AGENTS_DIR; }
|
2020-09-21 12:39:58 +02:00
|
|
|
|
agent-start-or-restart () {
|
|
|
|
|
|
|
|
|
|
local ssh_identity
|
|
|
|
|
local agentfile
|
|
|
|
|
local agentsocket
|
|
|
|
|
|
|
|
|
|
if [ -n "${1+x}" ]; then
|
|
|
|
|
ssh_identity="$1"
|
2020-09-21 13:00:56 +02:00
|
|
|
|
agentfile="${SSH_AGENTS_DIR}/agent-${ssh_identity}-$(hostname)"
|
|
|
|
|
agentsocket="${SSH_AGENTS_SOCKETS_DIR}/socket-${ssh_identity}-$(hostname)"
|
2020-09-21 12:39:58 +02:00
|
|
|
|
echo ssh-identität: $ssh_identity >&2
|
|
|
|
|
if [ -e $agentsocket ]; then
|
|
|
|
|
|
|
|
|
|
/bin/sh -c ". $agentfile >/dev/null 2>&1; ssh-add -l >&2; exit $?"
|
|
|
|
|
if [ $? -eq 2 ]; then
|
|
|
|
|
echo "agent is not running" >&2
|
|
|
|
|
rm "$agentsocket"
|
|
|
|
|
ssh-agent -a $agentsocket > $agentfile 2>/dev/null
|
|
|
|
|
echo "agent started" >&2
|
|
|
|
|
else
|
|
|
|
|
echo "agent is running" >&2
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "agent is not running" >&2
|
|
|
|
|
ssh-agent -a $agentsocket > $agentfile 2>/dev/null
|
|
|
|
|
echo "agent startet" >&2
|
|
|
|
|
|
|
|
|
|
fi
|
|
|
|
|
echo -n "agent for $ssh_identity: " >&2
|
|
|
|
|
echo $agentfile
|
|
|
|
|
return 0
|
|
|
|
|
else
|
|
|
|
|
echo no identity given - exit >&2
|
|
|
|
|
return 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
agent-start-or-restart $1
|
|
|
|
|
exit $?
|