1 |
commit: 39b69cb7d63d14f2816fd864eb60595680cfc94a |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 4 19:24:35 2019 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 4 19:24:35 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/qa-scripts.git/commit/?id=39b69cb7 |
7 |
|
8 |
keyrings: check for any change before renaming new dump |
9 |
|
10 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
11 |
|
12 |
keyrings.inc.bash | 24 +++++++++++++++++++----- |
13 |
1 file changed, 19 insertions(+), 5 deletions(-) |
14 |
|
15 |
diff --git a/keyrings.inc.bash b/keyrings.inc.bash |
16 |
index 54f0e8c..2b5ad9a 100644 |
17 |
--- a/keyrings.inc.bash |
18 |
+++ b/keyrings.inc.bash |
19 |
@@ -83,13 +83,27 @@ export_keys() { |
20 |
# 'gpg --export' returns zero if there was no error with the command itself |
21 |
# If there are no keys in the export set, then it ALSO does not write the destination file |
22 |
# and prints 'gpg: WARNING: nothing exported' to stderr |
23 |
- if gpg --output "$TMP" --export "${@}" && test -s "${TMP}"; then |
24 |
- chmod a+r "${TMP}" |
25 |
- mv "${TMP}" "${DST}" |
26 |
- else |
27 |
- echo "Unable to export keys to $DST" |
28 |
+ if ! gpg --output "$TMP" --export "${@}"; then |
29 |
+ echo "Unable to export keys to $DST: GPG returned non-zero" |
30 |
+ exit 1 |
31 |
+ fi |
32 |
+ if ! test -s "${TMP}"; then |
33 |
+ echo "Unable to export keys to $DST: GPG returned zero but generated empty file" |
34 |
exit 1 |
35 |
fi |
36 |
+ # We have a non-empty output now! |
37 |
+ # Capture it in a textual format that can be compared for changes, but make sure it exports correctly |
38 |
+ if ! gpg --list-packets "${TMP}" >"${TMP}.packets.txt"; then |
39 |
+ echo "Unable to export keys to $DST: GPG failed to list packets" |
40 |
+ exit 1 |
41 |
+ fi |
42 |
+ # Check if the textual format has changed at all, and emit the new version |
43 |
+ # if there are ANY changes at all. |
44 |
+ if ! cmp -s "${DST}.packets.txt" "${TMP}.packets.txt"; then |
45 |
+ chmod a+r "${TMP}" |
46 |
+ mv -f "${TMP}" "${DST}" |
47 |
+ mv -f "${TMP}.packets.txt" "${DST}.packets.txt" |
48 |
+ fi |
49 |
} |
50 |
|
51 |
# populate common variables |