feature: add git-gpg-init
[webi-installers/.git] / git-gpg-init / git-gpg-init.sh
1 #!/bin/bash
2 set -e
3 set -u
4
5 export PATH="$HOME/.local/opt/gnupg/bin:$PATH"
6 export PATH="$HOME/.local/opt/gnupg/bin/pinentry-mac.app/Contents/MacOS:$PATH"
7
8 # TODO check for public key without gpg-pubkey?
9 if ! command -v gpg-pubkey; then
10     webi gpg-pubkey
11 else
12     gpg-pubkey
13 fi
14
15 MY_KEY_ID="$(
16     gpg-pubkey-id
17 )"
18
19 echo -n "Enabling automatic git commit signing...
20     git config --global user.signingkey ${MY_KEY_ID}
21     git config --global commit.gpgsign true
22     git config --global log.showSignature true
23 "
24
25 git config --global user.signingkey "${MY_KEY_ID}"
26 git config --global commit.gpgsign true
27 git config --global log.showSignature true
28
29 echo ""
30 echo "Successfully updated ~/.gitconfig"
31 echo ""
32 echo "How to verify signed commits on GitHub:"
33 echo ""
34 echo "    1. Go to 'Add GPG Key': https://github.com/settings/gpg/new"
35 echo "    2. Copy and paste the key above from the first ---- to the last ----"
36 echo ""