summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-09-21 12:27:21 -0400
committerAndrew Cady <d@jerkface.net>2020-09-21 12:27:21 -0400
commit2b879f461f83c1938e1787f0f1cbdd1233fac41e (patch)
tree5f7aa4195d498984570ae8a9f4e028a219486fb5
parentc561d85cdbf2b94b1e45f2d58d1f341442038621 (diff)
change gpg/sudo interaction
-rw-r--r--selfpublish.sh37
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
195GPG()
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
196set -e 206set -e
197 207
198# 1. GET CRYPTONOMIC UID 208# 1. GET CRYPTONOMIC UID
199cryptonomic_hostname=$(cryptonomic hostname) 209cryptonomic_hostname=$(cryptonomic hostname)
200[ "$cryptonomic_hostname" ] 210[ "$cryptonomic_hostname" ]
201username=$(id -un) 211
212if [ "$SUDO_USER" ]
213then
214 username=$SUDO_USER
215else
216 username=$(id -un)
217fi
202[ "$username" ] 218[ "$username" ]
203uid=${username}@${cryptonomic_hostname} 219uid=${username}@${cryptonomic_hostname}
204 220
205# 2. CHECK IF EXISTING SECRET KEY 221# 2. CHECK IF EXISTING SECRET KEY
206if [ "$SUDO_USER" -a ! "$GNUPGHOME" ] 222t=$(GPG -K --with-colons)
207then
208 GNUPGHOME=$(get_home "$SUDO_USER")/.gnupg
209 export GNUPGHOME
210fi
211t=$(gpg -K --with-colons)
212if [ "$t" ] 223if [ "$t" ]
213then 224then
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
226else 237else
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
231fi 242fi
232EOF 243EOF