46 lines
1.3 KiB
Bash
Executable file
46 lines
1.3 KiB
Bash
Executable file
#!/bin/bash
|
||
|
||
[ -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; }
|
||
agent-start-or-restart () {
|
||
|
||
local ssh_identity
|
||
local agentfile
|
||
local agentsocket
|
||
|
||
if [ -n "${1+x}" ]; then
|
||
ssh_identity="$1"
|
||
agentfile="${SSH_AGENTS_DIR}/agent-${ssh_identity}-$(hostname)"
|
||
agentsocket="${SSH_AGENTS_SOCKETS_DIR}/socket-${ssh_identity}-$(hostname)"
|
||
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 $?
|