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
|
|
|
|
2019-02-08 10:37:29 +01:00
|
|
|
start_agent() {
|
2021-09-10 22:23:37 +02:00
|
|
|
ssh-agent -a "$1" > /dev/null
|
2019-02-12 09:23:21 +01:00
|
|
|
ssh-add
|
2015-06-13 01:03:31 +02:00
|
|
|
}
|
|
|
|
|
2021-09-10 22:23:37 +02:00
|
|
|
# Allow overriding the start_agent function easily.
|
|
|
|
if [ -r "${PREFIX}/etc/ssh/start_agent.sh" ]; then
|
|
|
|
. "${PREFIX}/etc/ssh/start_agent.sh"
|
|
|
|
fi
|
|
|
|
|
|
|
|
export SSH_AUTH_SOCK="${PREFIX}/var/run/ssh-agent"
|
|
|
|
|
2019-02-12 09:41:30 +01:00
|
|
|
MESSAGE=$(ssh-add -L 2>&1)
|
2016-10-28 22:50:39 +02:00
|
|
|
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
|
2021-09-10 22:23:37 +02:00
|
|
|
rm -f "${SSH_AUTH_SOCK}"
|
|
|
|
start_agent "${SSH_AUTH_SOCK}"
|
2016-10-28 22:50:39 +02:00
|
|
|
elif [ "$MESSAGE" = "The agent has no identities." ]; then
|
2019-02-12 09:23:21 +01:00
|
|
|
ssh-add
|
2015-06-13 01:03:31 +02:00
|
|
|
fi
|