summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2020-09-16 17:59:37 -0400
committerAndrew Cady <d@jerkface.net>2020-09-16 17:59:37 -0400
commit4f1a27132876af5df548546acd0a57918cdba7a6 (patch)
tree2623cc036d10fa202fad6b506d1a7e85d1bf03af
parent7ad370ef42fcb67499eba8a068071b98bc1f5113 (diff)
implement subcommand "cryptonomic gpg"
-rw-r--r--selfpublish.sh117
1 files changed, 116 insertions, 1 deletions
diff --git a/selfpublish.sh b/selfpublish.sh
index da906c9..f1c8af7 100644
--- a/selfpublish.sh
+++ b/selfpublish.sh
@@ -109,6 +109,117 @@ EOF
109File: /usr/share/doc/selfpublish-dot-sh/README.Debian 644 109File: /usr/share/doc/selfpublish-dot-sh/README.Debian 644
110 This gets overwritten :( 110 This gets overwritten :(
111EOF 111EOF
112 control_file_file /usr/lib/cryptonomic/cryptonomic-gpg 755 <<'EOF'
113#!/bin/sh
114
115process_colons()
116{
117 local callback="$*" IFS process_colons_break=
118 set --
119 while read LINE
120 do
121 IFS=:
122 set -- $LINE
123 unset IFS
124
125 case "$1" in
126 sec|pub) CURRENT_KEY=$LINE ;;
127 fpr) CURRENT_FPR=${10} ;;
128 esac
129
130 if [ "$CURRENT_KEY" -a "$CURRENT_FPR" ]
131 then
132 $callback "$@"
133 fi
134
135 if [ "$process_colons_break" ]
136 then
137 break
138 fi
139 done
140}
141
142is_secret_key()
143{
144 case "$CURRENT_KEY" in
145 sec:*) true ;;
146 *) false ;;
147 esac
148}
149
150match_domain()
151{
152 domain=$1
153 action=$2
154 shift 2
155 case "$1:$2:${10%>}" in
156 uid:u:*.${domain}) $action "$@";;
157 esac
158}
159
160match_first_secret_key()
161{
162 action=$1
163 shift
164 is_secret_key || return
165 case "$1:$2" in
166 fpr:*) $action "$@"
167 process_colons_break=y
168 ;;
169 esac
170}
171
172show_fpr()
173{
174 echo ${CURRENT_FPR}
175}
176
177find_secret_key_with_domain()
178{
179 process_colons match_domain "$1" show_fpr
180}
181
182force() { [ "$FORCE" ]; }
183verbose()
184{
185 if [ "$VERBOSE" ]
186 then
187 "$@"
188 fi
189}
190
191set -e
192
193# 1. GET CRYPTONOMIC UID
194cryptonomic_hostname=$(cryptonomic hostname)
195[ "$cryptonomic_hostname" ]
196username=$(id -un)
197[ "$username" ]
198uid=${username}@${cryptonomic_hostname}
199
200# 2. CHECK IF EXISTING SECRET KEY
201t=$(gpg -K --with-colons)
202if [ "$t" ]
203then
204 # 3. CHECK IF EXISTING KEY HAS UID
205 if gpg -K --with-colons | find_secret_key_with_domain "${cryptonomic_hostname#*.}" | grep -q . && ! force
206 then
207 exit
208 fi
209
210 # 4. ADD UID TO EXISTING KEY
211 gpg_default_key=$(gpg -K --with-colons | process_colons match_first_secret_key show_fpr)
212 [ "$gpg_default_key" ]
213 gpg --quick-add-uid "$gpg_default_key" "$uid" || force
214 verbose gpg -K "$gpg_default_key"
215 exit 0
216else
217 # 2.5 GENERATE NEW KEY
218 gpg --batch --passphrase '' --quick-generate-key "$uid"
219 verbose gpg -K "$uid"
220 exit 0
221fi
222EOF
112 control_file_file /usr/bin/cryptonomic 755 <<'EOF' 223 control_file_file /usr/bin/cryptonomic 755 <<'EOF'
113#!/bin/dash 224#!/bin/dash
114set -e 225set -e
@@ -161,8 +272,12 @@ then
161 su -c "$(bash -c 'printf "%q " "$@"' bash "$@")" 272 su -c "$(bash -c 'printf "%q " "$@"' bash "$@")"
162 273
163 fi 274 fi
275elif [ -f /usr/lib/cryptonomic/cryptonomic-"$1" ]
276then
277 exec /usr/lib/cryptonomic/cryptonomic-"$1" "$@"
278
164else 279else
165 echo "Usage: $0 [dyndns|hostname]" >&2 280 echo "Usage: $0 [dyndns|hostname|gpg]" >&2
166 exit 1 281 exit 1
167fi 282fi
168EOF 283EOF