5 function __get_git_email() {
6 grep 'email\s*=.*@' ~/.gitconfig |
7 tr -d '\t ' | head -n 1 |
11 function __get_pubkey_id() {
12 gpg --list-secret-keys --keyid-format LONG |
18 function _create_gpg_key() {
19 if [[ ! -e ~/.gitconfig ]]; then
24 grep 'name\s*=' ~/.gitconfig |
29 if [[ -z ${MY_NAME} ]]; then
36 if [[ -z ${MY_EMAIL} ]]; then
43 #gpg --batch --generate-key --pinentry=loopback --passphrase=''
45 # With passphrase via macOS Keychain
47 %echo Generating RSA 3072 key...
48 %echo Warning: It may take several minutes to gather enough entropy,
49 %echo especially on a linux VPS if haveged isn't installed.
50 %echo (try moving the mouse, downloading large files, etc)
56 Name-Comment: ${MY_HOST}
57 Name-Email: ${MY_EMAIL}
61 if ! echo "$gpg_opts" | gpg --batch --generate-key 2> /dev/null; then
65 echo >&2 "== STOP! CHOOSE A PASSPHRASE =="
67 echo >&2 "Choose a passphrase for this GPG Key."
68 echo >&2 "(the passphrase will not be shown as you type)"
70 echo >&2 -n "Passphrase: "
74 %echo Generating RSA 3072 key...
75 %echo Warning: It may take several minutes to gather enough entropy,
76 %echo especially on a linux VPS if haveged isn't installed.
77 %echo (try moving the mouse, downloading large files, etc)
83 Name-Comment: ${MY_HOST}
84 Name-Email: ${MY_EMAIL}
88 " --batch --generate-key > gpg
93 # (maybe) Create first key
94 if ! gpg --list-secret-keys | grep -q sec; then
95 if ! _create_gpg_key; then
97 echo >&2 "Please set your name and email, and then try again:"
99 echo >&2 " git config --global user.name 'John Doe'"
100 echo >&2 " git config --global user.email johndoe@example.com"
101 echo >&2 " gpg-pubkey"
103 echo >&2 "(or manually create a private key first)"
117 #gpg --send-keys "${MY_KEY_ID}"
119 MY_ASC_RELPATH="Downloads/${MY_EMAIL}.${MY_KEY_ID}.gpg.asc"
120 mkdir -p ~/Downloads/
121 rm -f ~/"${MY_ASC_RELPATH}"
122 gpg --armor --export "${MY_KEY_ID}" > ~/"${MY_ASC_RELPATH}"
125 echo >&2 "GnuPG Public Key ID: ${MY_KEY_ID}"
127 #shellcheck disable=SC2088
128 echo >&2 "~/${MY_ASC_RELPATH}":
130 cat ~/"${MY_ASC_RELPATH}"