Files
a13labs.infra/ansible/roles/macos_dev_station/templates/ssh-agent-start.sh.j2
T

29 lines
955 B
Django/Jinja
Raw Normal View History

2026-07-05 20:55:48 +02:00
#!/usr/bin/env bash
# SSH agent starter — idempotent, safe to source from concurrent services.
# The ssh-agent daemon is already running; this just adds keys and exports the socket.
export SSH_AUTH_SOCK="{{ macos_dev_station_ssh_agent_socket }}"
# Wait for the agent socket to appear
__wait=0
while [ ! -S "$SSH_AUTH_SOCK" ] && [ "$__wait" -lt 15 ]; do
sleep 1
__wait=$(( __wait + 1 ))
done
# Add keys if the agent is running but has none loaded
if [ -S "$SSH_AUTH_SOCK" ]; then
if ssh-add -l 2>/dev/null | grep -q "The agent has no identities"; then
for _key in {{ macos_dev_station_ssh_agent_keys | map('quote') | join(' ') }}; do
if [ -f "$_key" ]; then
if [ -n "{{ macos_dev_station_ssh_agent_passphrase }}" ]; then
printf '%s\n' "{{ macos_dev_station_ssh_agent_passphrase }}" | ssh-add "$_key" 2>/dev/null || true
else
ssh-add "$_key" 2>/dev/null || true
fi
fi
done
fi
fi