2017-11-16 23:37:17 +01:00
|
|
|
#!/bin/sh
|
2016-10-28 22:50:39 +02:00
|
|
|
# source-ssh-agent: Script to source for ssh-agent to work.
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
# Check if accidentaly executed instead of sourced:
|
|
|
|
if echo "$0" | grep -q source-ssh-agent; then
|
2016-10-28 22:50:39 +02:00
|
|
|
echo "source-ssh-agent: Do not execute directly - source me instead!"
|
|
|
|
exit 1
|
2015-06-13 01:03:31 +02:00
|
|
|
fi
|
|
|
|
|
2016-10-28 22:50:39 +02:00
|
|
|
export SSH_AUTH_SOCK=$PREFIX/tmp/ssh-agent
|
2015-06-13 01:03:31 +02:00
|
|
|
|
|
|
|
start_agent () {
|
2016-10-28 22:50:39 +02:00
|
|
|
rm -f $SSH_AUTH_SOCK
|
|
|
|
ssh-agent -a $SSH_AUTH_SOCK > /dev/null
|
|
|
|
ssh-add
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2016-10-28 22:50:39 +02:00
|
|
|
MESSAGE=`ssh-add -L 2>&1`
|
|
|
|
if [ "$MESSAGE" = 'Could not open a connection to your authentication agent.' -o \
|
|
|
|
"$MESSAGE" = 'Error connecting to agent: Connection refused' -o \
|
|
|
|
"$MESSAGE" = 'Error connecting to agent: No such file or directory' ]; then
|
|
|
|
start_agent
|
|
|
|
elif [ "$MESSAGE" = "The agent has no identities." ]; then
|
|
|
|
ssh-add
|
2015-06-13 01:03:31 +02:00
|
|
|
fi
|