#!/bin/bash # Copyright 2010-2015 Gentoo Authors; Distributed under the GPL v2 # might be earlier copyright, no history available # Keep this variable in sync in both sign-autobuilds.sh & sync-autobuilds.sh _ARCHES="alpha amd64 arm64 arm hppa ia64 loong m68k mips ppc riscv s390 sh sparc x86" #alpha amd64 arm64 arm hppa ia64 loong m68k mips ppc riscv s390 sh sparc x86 ARCHES=${ARCHES:-${_ARCHES}} RELEASES=/var/tmp/gmirror-releases/releases/ [[ $HOSTNAME == TODO ]] && RELEASES=/var/tmp/gmirror/releases/ : "${DEBUG:=''}" : "${VERBOSE=''}" GPG=(gpg --homedir /home/gmirror/.gnupg-releng/ --batch --no-tty) # Do not change DEBUGP= VERBOSEP=false [ -n "$DEBUG" ] && DEBUGP='echo' [ -n "$VERBOSE" ] && VERBOSEP='' [ -n "$DEBUG" ] && RSYNC_OPTS="${RSYNC_OPTS} -n" [ -n "$VERBOSE" ] && RSYNC_OPTS="${RSYNC_OPTS} -v" # needs more debugging # set -e signone() { f="$1" $DEBUGP "${GPG[@]}" --armor --detach-sign "${f}" } signone_clearsign() { # only for text files! f="$1" d=".${1}.asc.tmp" rm -f "$d" # Clearsign aborts if the destfile exists $DEBUGP "${GPG[@]}" --armor --clearsign --output "$d" "${f}" $DEBUGP mv "${d}" "${f}" } cleanup() { # A sync mismatch means these seem like bad signatures due to different CDN # cache times. # [TXT] latest-install-alpha-minimal.txt 2023-10-09 03:00 116 # [TXT] latest-install-alpha-minimal.txt.asc 2023-10-09 00:21 488 # # Using a clearsign in a seperate file doesn't help here either, because it # can still be out of date compared to the underlying file. # It must be exactly 1 file, clearsigned. find autobuilds \ -type f \ -name 'latest*txt.asc' \ -exec grep -L -e '^-----BEGIN PGP SIGNED MESSAGE-----$' \{\} \+ \ | tr '\n' '\0' \ | xargs -0 --no-run-if-empty rm -f } gpgconf --kill all for a in $ARCHES ; do cd "$RELEASES/$a" >/dev/null || continue [[ -d autobuilds ]] || continue #echo "Release files:" # 2023/10/08: Unknown if the latest files are consumed by any machine-readable # process that would break if the changed into being clearsigned, so use a # detached signature for now. find_files_cmd=( find autobuilds -type f '(' -false -or -name '*.tar.xz' -or -name '*.tar.bz2' # old builds -or -name '*.tar.gz' # old builds -or -name '*.tar.zst' # future builds? -or -name '*.tar.zstd' # future builds? -or -name '*.iso' -or -name '*.tar.bz2' # hppa netboot -or -name '*.lif' # s390 netboot -or -name 'netboot*T[0-9][0-9][0-9][0-9][0-9][0-9]Z' ')' ) find_sigs_cmd=( find autobuilds -type f '(' -false -or -name '*.asc' ')' ) find_unsigned_helper_cmd=( find autobuilds -type f \( -false # Gentoo format digest files. -or -name '*.DIGESTS' # .sha256 files exist to support the OpenStack builder process -or -name '*.sha256' # marker files to declare latest builds. -or -name 'latest*txt' \) -exec grep -L -e '^-----BEGIN PGP SIGNED MESSAGE-----$' \{\} \+ ) files="$( "${find_files_cmd[@]}" )" sigs="$( "${find_sigs_cmd[@]}" )" unsigned="$(comm -23 <(echo "$files" |sort) <(echo "$sigs" | sed -e 's,.asc$,,g' |sort))" #$VERBOSEP echo "=== ARCH: $a" for src in ${unsigned} ; do dgst=${src}.asc if [[ -f "$src" ]] && [[ ! -f "${dgst}" ]]; then $VERBOSEP echo "Signing $src" signone "$src" fi done for dgst in ${sigs}; do src=${dgst%.asc} # If both the source & signature are files, not symlinks, and the source is # newer, then resign. Need to check both for being files, in case we are in # a symlink location. if [[ -f "${src}" ]] && [[ -f "${dgst}" ]] && [[ "${src}" -nt "${dgst}" ]]; then $VERBOSEP echo "Resigning $dgst" rm -f "${dgst}" signone "$src" fi done #echo "Text helper files:" unsigned="$( "${find_unsigned_helper_cmd[@]}" )" for src in $unsigned ; do $VERBOSEP echo "Signing (inline/cleartext) $src" signone_clearsign "$src" done cleanup done