commit:     d1dda423e1285e94fade299209e58f4434db35ee
Author:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
AuthorDate: Fri Jun 30 05:33:01 2023 +0000
Commit:     Robin H. Johnson <robbat2 <AT> gentoo <DOT> org>
CommitDate: Fri Jun 30 05:33:01 2023 +0000
URL:        https://gitweb.gentoo.org/proj/qa-scripts.git/commit/?id=d1dda423

keyrings.inc.bash: ensure digests/packets present

Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org>

 keyrings-export.bash |  4 +++-
 keyrings.inc.bash    | 17 +++++++++--------
 2 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/keyrings-export.bash b/keyrings-export.bash
index 92c0228..56e4e51 100755
--- a/keyrings-export.bash
+++ b/keyrings-export.bash
@@ -6,6 +6,8 @@
 # - requires keeping state to detect changes in keys, there is no usable mtime 
data in a key itself
 
 OUTPUT_DIR=${1:-.}
+# Ensure output is absolute
+OUTPUT_DIR=$(readlink -f "${OUTPUT_DIR}")
 BASEDIR="$(dirname "$0")"
 # shellcheck source=./keyrings.inc.bash
 source "${BASEDIR}"/keyrings.inc.bash
@@ -57,7 +59,7 @@ export_keys "${OUTPUT_DIR}"/keys/all-devs.gpg \
 for key in "${KEYRINGS[@]}" ; do
        if [[ ! -L "${OUTPUT_DIR}"/${key}.gpg ]] ; then
                # Compatibility symlink
-               ln -s "${OUTPUT_DIR}"/keys/${key}.gpg "${OUTPUT_DIR}"/${key}.gpg
+               ln -sf "${OUTPUT_DIR}"/keys/${key}.gpg 
"${OUTPUT_DIR}"/${key}.gpg
        fi
 
        if [[ $(date -u +%A) == Monday ]] ; then

diff --git a/keyrings.inc.bash b/keyrings.inc.bash
index 32fc03f..d2668e0 100644
--- a/keyrings.inc.bash
+++ b/keyrings.inc.bash
@@ -123,14 +123,15 @@ export_keys() {
 
        # Check if the textual format has changed at all, and emit the new 
version
        # if there are ANY changes at all.
-       if ! cmp -s "${DST}.packets.txt" "${TMP}.packets.txt"; then
-               chmod a+r "${TMP}"
-               mv -f "${TMP}" "${DST}"
-               mv -f "${TMP}.packets.txt" "${DST}.packets.txt"
-               mv -f "${TMP}.DIGESTS" "${DST}.DIGESTS"
-       fi
-       # Cleanup anyway
-       rm -f "${TMP}.packets.txt" "${TMP}"
+       cmp -s "${DST}.packets.txt" "${TMP}.packets.txt"
+       cmp_rc=$?
+       chmod a+r "${TMP}" "${TMP}.packets.txt" "${TMP}.DIGESTS"
+       for suffix in '' '.packets.txt' '.DIGESTS'; do
+               # If these file do not exist, or the cmp was different, move 
them.
+               [ ! -f "${DST}${suffix}" -o $cmp_rc -ne 0 ] && mv -f 
"${TMP}${suffix}" "${DST}${suffix}"
+               # Cleanup anyway
+               rm -f "${TMP}${suffix}"
+       done
 }
 
 # populate common variables

Reply via email to