refactor!: rename git-gpg-init => git-config-gpg
[webi-installers/.git] / git-config-gpg / git-config-gpg.sh
diff --git a/git-config-gpg/git-config-gpg.sh b/git-config-gpg/git-config-gpg.sh
new file mode 100644 (file)
index 0000000..3b38745
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/bash
+set -e
+set -u
+
+export PATH="$HOME/.local/opt/gnupg/bin:$PATH"
+export PATH="$HOME/.local/opt/gnupg/bin/pinentry-mac.app/Contents/MacOS:$PATH"
+
+# TODO check for public key without gpg-pubkey?
+if ! command -v gpg-pubkey; then
+    webi gpg-pubkey
+else
+    gpg-pubkey
+fi
+
+MY_KEY_ID="$(
+    gpg-pubkey-id
+)"
+
+echo -n "Enabling automatic git commit signing...
+    git config --global user.signingkey ${MY_KEY_ID}
+    git config --global commit.gpgsign true
+    git config --global log.showSignature true
+"
+
+git config --global user.signingkey "${MY_KEY_ID}"
+git config --global commit.gpgsign true
+git config --global log.showSignature true
+
+echo ""
+echo "Successfully updated ~/.gitconfig"
+echo ""
+echo "How to verify signed commits on GitHub:"
+echo ""
+echo "    1. Go to 'Add GPG Key': https://github.com/settings/gpg/new"
+echo "    2. Copy and paste the key above from the first ---- to the last ----"
+echo ""