- Create ~/.ssh dir if missing before writing agent-environment - Suppress ssh-add errors (no keys yet is fine) - Skip entire block if ssh-agent binary is not installed Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
27 lines
653 B
Bash
Executable File
27 lines
653 B
Bash
Executable File
SSH_ENV="$HOME/.ssh/agent-environment"
|
|
|
|
function start_agent {
|
|
echo "Initialising new SSH agent..."
|
|
mkdir -p "$HOME/.ssh"
|
|
chmod 700 "$HOME/.ssh"
|
|
/usr/bin/ssh-agent | sed 's/^echo/#echo/' >"$SSH_ENV"
|
|
echo succeeded
|
|
chmod 600 "$SSH_ENV"
|
|
. "$SSH_ENV" >/dev/null
|
|
/usr/bin/ssh-add 2>/dev/null || true
|
|
}
|
|
|
|
# Source SSH settings, if applicable — skip entirely if ssh-agent is not available
|
|
if ! command -v ssh-agent >/dev/null 2>&1; then
|
|
return 0
|
|
fi
|
|
|
|
if [ -f "$SSH_ENV" ]; then
|
|
. "$SSH_ENV" >/dev/null
|
|
ps -ef | grep $SSH_AGENT_PID | grep ssh-agent$ >/dev/null || {
|
|
start_agent
|
|
}
|
|
else
|
|
start_agent
|
|
fi
|