Advertisement
Guest User

Untitled

a guest
Mar 1st, 2020
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.76 KB | None | 0 0
  1. #
  2. # Provides for an easier use of GPG by setting up gpg-agent.
  3. #
  4. # Authors:
  5. #   Sorin Ionescu <[email protected]>
  6. #
  7. # Personal modification references:
  8. # - https://github.com/sorin-ionescu/prezto/blob/master/modules/gpg/init.zsh
  9. # - https://github.com/sorin-ionescu/prezto/blob/master/modules/ssh/init.zsh
  10. # - https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/ssh-agent/ssh-agent.plugin.zsh
  11. # - https://github.com/ohmyzsh/ohmyzsh/blob/master/plugins/gpg-agent/gpg-agent.plugin.zsh
  12.  
  13. # Return if requirements are not found.
  14. if (( ! $+commands[gpg-agent] )); then
  15.   return 1
  16. fi
  17.  
  18. # Set the default paths to gpg-agent files.
  19. _gpg_agent_conf="${GNUPGHOME:-$HOME/.gnupg}/gpg-agent.conf"
  20. # FIXME previously:
  21. # _gpg_agent_env="${TMPDIR:-/tmp}/gpg-agent.env.$UID"
  22.  
  23. # Load environment variables from previous run
  24. # FIXME is this required?
  25. # source "$_gpg_agent_env" 2> /dev/null
  26.  
  27. # Start gpg-agent if not started.
  28. # FIXME GPG_AGENT_INFO is obsolete according to `man gpg`, this was previously:
  29. # if [[ -z "$GPG_AGENT_INFO" && ! -S "${GNUPGHOME:-$HOME/.gnupg}/S.gpg-agent" && ! -S "/run/user/$(id -u)/gnupg/S.gpg-agent" ]]; then
  30. if [[ ! -S "$(gpgconf --list-dirs agent-socket)" ]]; then
  31.   # Start gpg-agent if not started.
  32.   # FIXME `command` was required here to avoid aliases, pattern might still need to be improved
  33.   # FIXME is `--daemon` correct here? Arch Linux systemd socket for GPG defaults to `--supervised`
  34.   if ! command ps -U "$LOGNAME" -o pid,ucomm | grep -q -- "${${${(s.:.)GPG_AGENT_INFO}[2]}:--1} gpg-agent"; then
  35.     eval "$(gpg-agent --daemon | tee "$_gpg_agent_env")"
  36.   fi
  37. fi
  38.  
  39. # Inform gpg-agent of the current TTY for user prompts.
  40. export GPG_TTY="$(tty)"
  41.  
  42. # Integrate with the SSH module.
  43. if command grep '^enable-ssh-support' "$_gpg_agent_conf" &> /dev/null; then
  44.   # Load required functions.
  45.   autoload -Uz add-zsh-hook
  46.  
  47.   # Override the ssh-agent environment file default path.
  48.   # FIXME not sure what this does, but this is the reference Zinit's pmodload does not catch
  49.   # _ssh_agent_env="$_gpg_agent_env"
  50.  
  51.   # Load the SSH module for additional processing.
  52.   # FIXME avoid loading Prezto's SSH module for now
  53.   # pmodload 'ssh'
  54.  
  55.   # Updates the GPG-Agent TTY before every command since SSH does not set it.
  56.   # FIXME is this required? some places suggest `updatestartuptty`, but hooking it before every command?
  57.   function _gpg-agent-update-tty {
  58.     gpg-connect-agent UPDATESTARTUPTTY /bye >/dev/null
  59.   }
  60.   add-zsh-hook preexec _gpg-agent-update-tty
  61.  
  62.   # FIXME is this required?
  63.   unset SSH_AGENT_PID
  64.   export SSH_AUTH_SOCK=$(gpgconf --list-dirs agent-ssh-socket)
  65. fi
  66.  
  67. # Clean up.
  68. unset _gpg_agent_{conf,env}
  69.  
  70. # Disable GUI prompts inside SSH.
  71. if [[ -n "$SSH_CONNECTION" ]]; then
  72.   export PINENTRY_USER_DATA='USE_CURSES=1'
  73. fi
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement