diff options
author | Andrew Cady <d@jerkface.net> | 2020-09-16 17:59:37 -0400 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2020-09-16 17:59:37 -0400 |
commit | 4f1a27132876af5df548546acd0a57918cdba7a6 (patch) | |
tree | 2623cc036d10fa202fad6b506d1a7e85d1bf03af | |
parent | 7ad370ef42fcb67499eba8a068071b98bc1f5113 (diff) |
implement subcommand "cryptonomic gpg"
-rw-r--r-- | selfpublish.sh | 117 |
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 | |||
109 | File: /usr/share/doc/selfpublish-dot-sh/README.Debian 644 | 109 | File: /usr/share/doc/selfpublish-dot-sh/README.Debian 644 |
110 | This gets overwritten :( | 110 | This gets overwritten :( |
111 | EOF | 111 | EOF |
112 | control_file_file /usr/lib/cryptonomic/cryptonomic-gpg 755 <<'EOF' | ||
113 | #!/bin/sh | ||
114 | |||
115 | process_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 | |||
142 | is_secret_key() | ||
143 | { | ||
144 | case "$CURRENT_KEY" in | ||
145 | sec:*) true ;; | ||
146 | *) false ;; | ||
147 | esac | ||
148 | } | ||
149 | |||
150 | match_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 | |||
160 | match_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 | |||
172 | show_fpr() | ||
173 | { | ||
174 | echo ${CURRENT_FPR} | ||
175 | } | ||
176 | |||
177 | find_secret_key_with_domain() | ||
178 | { | ||
179 | process_colons match_domain "$1" show_fpr | ||
180 | } | ||
181 | |||
182 | force() { [ "$FORCE" ]; } | ||
183 | verbose() | ||
184 | { | ||
185 | if [ "$VERBOSE" ] | ||
186 | then | ||
187 | "$@" | ||
188 | fi | ||
189 | } | ||
190 | |||
191 | set -e | ||
192 | |||
193 | # 1. GET CRYPTONOMIC UID | ||
194 | cryptonomic_hostname=$(cryptonomic hostname) | ||
195 | [ "$cryptonomic_hostname" ] | ||
196 | username=$(id -un) | ||
197 | [ "$username" ] | ||
198 | uid=${username}@${cryptonomic_hostname} | ||
199 | |||
200 | # 2. CHECK IF EXISTING SECRET KEY | ||
201 | t=$(gpg -K --with-colons) | ||
202 | if [ "$t" ] | ||
203 | then | ||
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 | ||
216 | else | ||
217 | # 2.5 GENERATE NEW KEY | ||
218 | gpg --batch --passphrase '' --quick-generate-key "$uid" | ||
219 | verbose gpg -K "$uid" | ||
220 | exit 0 | ||
221 | fi | ||
222 | EOF | ||
112 | control_file_file /usr/bin/cryptonomic 755 <<'EOF' | 223 | control_file_file /usr/bin/cryptonomic 755 <<'EOF' |
113 | #!/bin/dash | 224 | #!/bin/dash |
114 | set -e | 225 | set -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 |
275 | elif [ -f /usr/lib/cryptonomic/cryptonomic-"$1" ] | ||
276 | then | ||
277 | exec /usr/lib/cryptonomic/cryptonomic-"$1" "$@" | ||
278 | |||
164 | else | 279 | else |
165 | echo "Usage: $0 [dyndns|hostname]" >&2 | 280 | echo "Usage: $0 [dyndns|hostname|gpg]" >&2 |
166 | exit 1 | 281 | exit 1 |
167 | fi | 282 | fi |
168 | EOF | 283 | EOF |