#!/bin/sh

if [ -z "${SSH_AUTH_SOCK:-}" ] && [ -r "$HOME/.ssh/agent-environment" ]; then
	# Read ssh-agent -s output as data, as the service user, on each connection.
	agent_socket=$(sed -n \
		's/^SSH_AUTH_SOCK=\([^;]*\); export SSH_AUTH_SOCK;$/\1/p' \
		"$HOME/.ssh/agent-environment" | tail -n 1)
	if [ -S "$agent_socket" ]; then
		export SSH_AUTH_SOCK="$agent_socket"
	fi
fi

exec ssh "$@"
