refactor: finish moving ssh-* scripts to own installers
[webi-installers/.git] / gpg / install.sh
index 0a19fa4eeabe5ef9d97590716637aa28b97b9dc7..8058709c22584655f77349b3883bc7e309ed2e5c 100644 (file)
@@ -11,7 +11,7 @@ function _install_gpg() {
     fi
 
     # Download the latest LTS
-    #curl -fsSL -o ~/Downloads/GnuPG-2.2.32.dmg 'https://sourceforge.net/projects/gpgosx/files/GnuPG-2.2.32.dmg/download'
+    #curl -fsSL -o ~/Downloads/webi/GnuPG-2.2.32.dmg 'https://sourceforge.net/projects/gpgosx/files/GnuPG-2.2.32.dmg/download'
     webi_download
     chmod a-w "${WEBI_PKG_DOWNLOAD}"
 
@@ -19,15 +19,15 @@ function _install_gpg() {
     hdiutil detach -quiet /Volumes/GnuPG* 2> /dev/null || true
     hdiutil attach -quiet -readonly "${WEBI_PKG_DOWNLOAD}"
 
-    # Extract (completely) to ~/Downloads/GnuGP-VERSION.d
+    # Extract (completely) to ~/Downloads/webi/GnuGP-VERSION.d
     # (and detach the DMG)
-    rm -rf ~/Downloads/GnuPG-"${WEBI_VERSION}".d
-    pkgutil --expand-full /Volumes/GnuPG*/*.pkg ~/Downloads/GnuPG-"${WEBI_VERSION}".d
+    rm -rf ~/Downloads/webi/GnuPG-"${WEBI_VERSION}".d
+    pkgutil --expand-full /Volumes/GnuPG*/*.pkg ~/Downloads/webi/GnuPG-"${WEBI_VERSION}".d
     hdiutil detach -quiet /Volumes/GnuPG*
 
     # Move to ~/.local/opt/gnugp (where it belongs!)
     if [[ ! -e ~/.local/opt/gnupg-"${WEBI_VERSION}" ]]; then
-        mv ~/Downloads/GnuPG-"${WEBI_VERSION}".d/GnuPG.pkg/Payload/ ~/.local/opt/gnupg-"${WEBI_VERSION}"
+        mv ~/Downloads/webi/GnuPG-"${WEBI_VERSION}".d/GnuPG.pkg/Payload/ ~/.local/opt/gnupg-"${WEBI_VERSION}"
     fi
 
     # Update symlink to latest
@@ -35,7 +35,8 @@ function _install_gpg() {
     ln -s gnupg-"${WEBI_VERSION}" ~/.local/opt/gnupg
 
     pathman add ~/.local/opt/gnupg/bin
-    export PATH="$HOME/.local/opt/gnupg/bin/:$PATH"
+    export PATH="$HOME/.local/opt/gnupg/bin:$PATH"
+    export PATH="$HOME/.local/opt/gnupg/bin/pinentry-mac.app/Contents/MacOS:$PATH"
 
     # Prep for first use
     mkdir -p ~/.gnupg/
@@ -56,7 +57,7 @@ function _install_gpg() {
        <string>gpg-agent</string>
        <key>ProgramArguments</key>
        <array>
-               <string>'"${HOME}"'/.local/opt/gpg/bin/gpg-connect-agent</string>
+               <string>'"${HOME}"'/.local/opt/gnupg/bin/gpg-connect-agent</string>
                <string>--agent-program</string>
                <string>'"${HOME}"'/.local/opt/gnupg/bin/gpg-agent</string>
                <string>--homedir</string>
@@ -78,6 +79,10 @@ function _install_gpg() {
 </plist>' > ~/Library/LaunchAgents/gpg-agent.plist
     launchctl load -w ~/Library/LaunchAgents/gpg-agent.plist
     sleep 3
+    ~/.local/opt/gnupg/bin/gpg-connect-agent \
+        --agent-program ~/.local/opt/gnupg/bin/gpg-agent \
+        --homedir ~/.gnupg/ \
+        /bye
 
     # (maybe) Create first key
     if ! gpg --list-secret-keys | grep -q sec; then
@@ -90,21 +95,14 @@ function _create_gpg_key() {
         return 0
     fi
 
-    MY_NAME="$(
-        grep 'name\s*=' ~/.gitconfig |
-            head -n 1 |
-            cut -d'=' -f2 |
-            sed -e 's/^[\t ]*//'
-    )"
+    #grep 'name\s*=' ~/.gitconfig | head -n 1 | cut -d'=' -f2 | sed -e 's/^[\t ]*//'
+    MY_NAME="$(git config --global user.name)"
     if [[ -z ${MY_NAME} ]]; then
         return 0
     fi
 
-    MY_EMAIL="$(
-        grep 'email\s*=.*@' ~/.gitconfig |
-            tr -d '\t ' | head -n 1 |
-            cut -d'=' -f2
-    )"
+    # grep 'email\s*=.*@' ~/.gitconfig | tr -d '\t ' | head -n 1 | cut -d'=' -f2
+    MY_EMAIL="$(git config --global user.email)"
     if [[ -z ${MY_EMAIL} ]]; then
         return 0
     fi