Skip to content

Instantly share code, notes, and snippets.

@soywiz
Created January 19, 2019 03:20
Show Gist options
  • Save soywiz/b486669bb473bcc7993d896d76f97117 to your computer and use it in GitHub Desktop.
Save soywiz/b486669bb473bcc7993d896d76f97117 to your computer and use it in GitHub Desktop.
export gpgconf_path=`which gpgconf`
echo "gpgconf_path: $gpgconf_path"
if [ "$gpgconf_path" = "" ]; then
echo Non gpg2 in path
exit 1
fi
read -r -d '' homebrew_gpg_gpg_agent_plist << \
_______________________________________________________________________________
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<!-- Sets a name for a task -->
<key>Label</key>
<string>homebrew.gpg.gpg-agent</string>
<!-- Sets a command to run and its options -->
<key>ProgramArguments</key>
<array>
<string>$gpgconf_path</string>
<string>--launch</string>
<string>gpg-agent</string>
</array>
<!-- Tells it to run the task once the XML is loaded -->
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
_______________________________________________________________________________
read -r -d '' link_ssh_auth_sock_plist << \
_______________________________________________________________________________
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>link-ssh-auth-sock</string>
<key>ProgramArguments</key>
<array>
<string>/bin/sh</string>
<string>-c</string>
<string>/bin/ln -sf \$HOME/.gnupg/S.gpg-agent.ssh \$SSH_AUTH_SOCK</string>
</array>
<key>RunAtLoad</key>
<true/>
</dict>
</plist>
_______________________________________________________________________________
echo "$homebrew_gpg_gpg_agent_plist" > ~/Library/LaunchAgents/homebrew.gpg.gpg-agent.plist
launchctl load -F ~/Library/LaunchAgents/homebrew.gpg.gpg-agent.plist
echo "$link_ssh_auth_sock_plist" > ~/Library/LaunchAgents/link-ssh-auth-sock.plist
launchctl load -F ~/Library/LaunchAgents/link-ssh-auth-sock.plist
@soywiz
Copy link
Author

soywiz commented Jun 30, 2019

which gpg 2> /dev/null > /dev/null

if [ $? -eq 0 ]
then
  echo "gpg already installed" >&2
else
  brew cask install gpg-suite
  source ~/.zshrc
fi

export SSH_AGENT_PATH=`which ssh-agent`
echo $SSH_AGENT_PATH

cat >/System/Library/LaunchAgents/com.openssh.ssh-agent.plist <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>Label</key>
    <string>com.openssh.ssh-agent</string>
    <key>ProgramArguments</key>
    <array>
        <string>${SSH_AGENT_PATH}</string>
        <string>-l</string>
    </array>
    <key>Sockets</key>
    <dict>
        <key>Listeners</key>
        <dict>
            <key>SecureSocketWithKey</key>
            <string>SSH_AUTH_SOCK</string>
        </dict>
    </dict>
    <key>EnableTransactions</key>
    <true/>
</dict>
</plist>
EOL

export GPGCONF_PATH=`which gpgconf`
echo $GPGCONF_PATH

cat >~/Library/LaunchAgents/homebrew.gpg.gpg-agent.plist <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <!-- Sets a name for a task -->
  <key>Label</key>
  <string>homebrew.gpg.gpg-agent</string>
  <!-- Sets a command to run and its options -->
  <key>ProgramArguments</key>
  <array>
    <string>${GPGCONF_PATH}</string>
    <string>--launch</string>
    <string>gpg-agent</string>
  </array>
  <!-- Tells it to run the task once the XML is loaded -->
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>
EOL

launchctl load -F ~/Library/LaunchAgents/homebrew.gpg.gpg-agent.plist
launchctl list | grep gpg-agent
pgrep -fl gpg-agent

cat >~/Library/LaunchAgents/link-ssh-auth-sock.plist <<EOL
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
  <key>Label</key>
  <string>link-ssh-auth-sock</string>
  <key>ProgramArguments</key>
  <array>
    <string>/bin/sh</string>
    <string>-c</string>
    <string>/bin/ln -sf \$HOME/.gnupg/S.gpg-agent.ssh \$SSH_AUTH_SOCK</string>
  </array>
  <key>RunAtLoad</key>
  <true/>
</dict>
</plist>
EOL

launchctl load -F ~/Library/LaunchAngents/link-ssh-auth-sock.plist
launchctl list | grep link-ssh-auth-sock
ls -lah $SSH_AUTH_SOCK
ssh-add -L

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment