diff options
author | Andrew Cady <d@jerkface.net> | 2020-09-21 12:27:21 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-09-21 12:27:21 -0400 |
commit | 2b879f461f83c1938e1787f0f1cbdd1233fac41e (patch) | |
tree | 5f7aa4195d498984570ae8a9f4e028a219486fb5 | |
parent | c561d85cdbf2b94b1e45f2d58d1f341442038621 (diff) |
change gpg/sudo interaction
-rw-r--r-- | selfpublish.sh | 37 |
1 files changed, 24 insertions, 13 deletions
diff --git a/selfpublish.sh b/selfpublish.sh index 6ebf36b..ac5ad09 100644 --- a/selfpublish.sh +++ b/selfpublish.sh | |||
@@ -192,41 +192,52 @@ get_home() | |||
192 | [ "$1" ] && getent passwd "$1" | (IFS=: read _ _ _ _ _ h _; echo $h) | 192 | [ "$1" ] && getent passwd "$1" | (IFS=: read _ _ _ _ _ h _; echo $h) |
193 | } | 193 | } |
194 | 194 | ||
195 | GPG() | ||
196 | { | ||
197 | set -- gpg "$@" | ||
198 | if [ "$SUDO_USER" ] | ||
199 | then | ||
200 | su "$SUDO_USER" -c "$(bash -c 'printf "%q " "$@"' bash "$@")" | ||
201 | else | ||
202 | "$@" | ||
203 | fi | ||
204 | } | ||
195 | 205 | ||
196 | set -e | 206 | set -e |
197 | 207 | ||
198 | # 1. GET CRYPTONOMIC UID | 208 | # 1. GET CRYPTONOMIC UID |
199 | cryptonomic_hostname=$(cryptonomic hostname) | 209 | cryptonomic_hostname=$(cryptonomic hostname) |
200 | [ "$cryptonomic_hostname" ] | 210 | [ "$cryptonomic_hostname" ] |
201 | username=$(id -un) | 211 | |
212 | if [ "$SUDO_USER" ] | ||
213 | then | ||
214 | username=$SUDO_USER | ||
215 | else | ||
216 | username=$(id -un) | ||
217 | fi | ||
202 | [ "$username" ] | 218 | [ "$username" ] |
203 | uid=${username}@${cryptonomic_hostname} | 219 | uid=${username}@${cryptonomic_hostname} |
204 | 220 | ||
205 | # 2. CHECK IF EXISTING SECRET KEY | 221 | # 2. CHECK IF EXISTING SECRET KEY |
206 | if [ "$SUDO_USER" -a ! "$GNUPGHOME" ] | 222 | t=$(GPG -K --with-colons) |
207 | then | ||
208 | GNUPGHOME=$(get_home "$SUDO_USER")/.gnupg | ||
209 | export GNUPGHOME | ||
210 | fi | ||
211 | t=$(gpg -K --with-colons) | ||
212 | if [ "$t" ] | 223 | if [ "$t" ] |
213 | then | 224 | then |
214 | # 3. CHECK IF EXISTING KEY HAS UID | 225 | # 3. CHECK IF EXISTING KEY HAS UID |
215 | if gpg -K --with-colons | find_secret_key_with_domain "${cryptonomic_hostname#*.}" | grep -q . && ! force | 226 | if GPG -K --with-colons | find_secret_key_with_domain "${cryptonomic_hostname#*.}" | grep -q . && ! force |
216 | then | 227 | then |
217 | exit | 228 | exit |
218 | fi | 229 | fi |
219 | 230 | ||
220 | # 4. ADD UID TO EXISTING KEY | 231 | # 4. ADD UID TO EXISTING KEY |
221 | gpg_default_key=$(gpg -K --with-colons | process_colons match_first_secret_key show_fpr) | 232 | gpg_default_key=$(GPG -K --with-colons | process_colons match_first_secret_key show_fpr) |
222 | [ "$gpg_default_key" ] | 233 | [ "$gpg_default_key" ] |
223 | gpg --quick-add-uid "$gpg_default_key" "$uid" || force | 234 | GPG --quick-add-uid "$gpg_default_key" "$uid" || force |
224 | verbose gpg -K "$gpg_default_key" | 235 | verbose GPG -K "$gpg_default_key" |
225 | exit 0 | 236 | exit 0 |
226 | else | 237 | else |
227 | # 2.5 GENERATE NEW KEY | 238 | # 2.5 GENERATE NEW KEY |
228 | gpg --batch --passphrase '' --quick-generate-key "$uid" | 239 | GPG --batch --passphrase '' --quick-generate-key "$uid" |
229 | verbose gpg -K "$uid" | 240 | verbose GPG -K "$uid" |
230 | exit 0 | 241 | exit 0 |
231 | fi | 242 | fi |
232 | EOF | 243 | EOF |