Skip to content

Instantly share code, notes, and snippets.

@mark-adams
Last active August 29, 2015 14:12
Show Gist options
  • Save mark-adams/e380aa87361118653173 to your computer and use it in GitHub Desktop.
Save mark-adams/e380aa87361118653173 to your computer and use it in GitHub Desktop.
Modified gpg-agent upstart script for Ubuntu 14.10 so that it properly sets ssh-agent environment variables
# This modified version of the gpg-agent.conf script should replace the version in
# /usr/share/upstart/sessions/ on Ubuntu 14.10
#
# Description: Sets SSH_AUTH_SOCK and SSH_AGENT_PID global environment variables if SSH
# support is enabled in the gpg-agent configuration.
#
# Suggested it as a patch to Ubuntu's gpg2 package via
# https://code.launchpad.net/~kramsmada/ubuntu/vivid/gnupg2/1407513-gpg-agent-set-ssh-env-vars/+merge/245538
#
description "GPG Agent"
author "Stéphane Graber <[email protected]>"
start on starting xsession-init
pre-start script
GNUPGHOME=$HOME/.gnupg
[ -d $GNUPGHOME ] || { stop; exit 0; }
[ -z "$GPG_AGENT_INFO" ] || { stop; exit 0; }
grep -qs '^[[:space:]]*use-agent' "$GNUPGHOME/gpg.conf" "$GNUPGHOME/options" || { stop; exit 0; }
eval "$(gpg-agent --daemon --sh)" >/dev/null
initctl set-env --global GPG_AGENT_INFO=$GPG_AGENT_INFO
grep -qs "^enable-ssh-support$" "$GNUPGHOME/gpg-agent.conf"
if [ $? -eq 0 ]; then
initctl set-env --global SSH_AUTH_SOCK=$SSH_AUTH_SOCK
initctl set-env --global SSH_AGENT_PID=$SSH_AGENT_PID
fi
end script
post-stop script
GPG_AGENT_PID=$(echo $GPG_AGENT_INFO | cut -d : -f2)
kill $GPG_AGENT_PID 2>/dev/null || true
initctl unset-env --global GPG_AGENT_INFO
grep -qs "^enable-ssh-support$" "$GNUPGHOME/gpg-agent.conf"
if [ $? -eq 0 ]; then
initctl unset-env --global SSH_AUTH_SOCK
initctl unset-env --global SSH_AGENT_PID
fi
end script
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment