From 35094992a3804204b97d77dd74749d59b9f69280 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Wed, 3 Oct 2018 15:19:27 -0400 Subject: db-import-any: Rewrite to use db-update --- config.local.import-ourarches | 2 + db-import-any | 97 ++++++++++++++++++++++--------------------- 2 files changed, 52 insertions(+), 47 deletions(-) diff --git a/config.local.import-ourarches b/config.local.import-ourarches index c1b101f..0361328 100644 --- a/config.local.import-ourarches +++ b/config.local.import-ourarches @@ -10,6 +10,8 @@ PKGREPOS=( # ARCHES should list arches that ./config.local.parabola has but # there's no Arch Linux upstream for. ARCHES=(ppc64le) +PKGPOOL='pool/import-ourarches' +SRCPOOL='sources/import-ourarches' # For db-import-any. # Which architecture to import arch=(any) packages from. diff --git a/db-import-any b/db-import-any index 9c6b478..455b802 100755 --- a/db-import-any +++ b/db-import-any @@ -1,56 +1,59 @@ #!/bin/bash # Releases 'any' packages from Arch arches to our arches +set -eu -o pipefail source "$(dirname "$(readlink -e "$0")")/config" source "$(librelib messages)" setup_traps -# Traverse all Arch repos -for _repo in "${PKGREPOS[@]}"; do - msg "Processing %s..." "${_repo}" - - # Find 'any' packages - # This is hardcoded but it could release other arches... - PKGS=($(find "${FTP_BASE}/${_repo}/os/${ARCHARCH}/" \ - -iname '*-any.pkg.tar.?z' \ - -printf "%f ")) - - if [ ${#PKGS[@]} -eq 0 ]; then - msg2 "No '%s' packages here" any - continue - fi - - for _arch in "${ARCHES[@]}"; do - msg2 "Syncing %s..." "${_arch}" - - # Sync 'any' only and extract the synced packages - SYNCED=($( - rsync -av \ - --include='*-any.pkg.tar.?z' \ - --include='*-any.pkg.tar.?z.sig' \ - --exclude='*' \ - "${FTP_BASE}/${_repo}/os/${ARCHARCH}/" \ - "${FTP_BASE}/${_repo}/os/${_arch}/" 2>&1 | \ - grep 'any\.pkg\.tar\..z$' | \ - cut -d ' ' -f 1 )) - - if [ ${#SYNCED[@]} -eq 0 ]; then - msg2 "Already synced (or error happened)" - continue - fi - - msg2 "Synced %d packages: %s" "${#SYNCED[@]}" "${SYNCED[*]}" - - msg2 "Adding to db..." - - pushd "${FTP_BASE}/${_repo}/os/${_arch}/" >/dev/null - - # Add the packages to the db - repo-add "${_repo}${DBEXT}" "${SYNCED[@]}" +# usage: expac_file +# +# Uses the ${WORKDIR} global +expac_file() { + local dbfile=$1 + local args=("${@:2}") + + local reponame=${dbfile##*/} + reponame=${reponame%%.*} + + mkdir -p -- "${WORKDIR}/expac/root" + cat >"${WORKDIR}/expac/pacman.conf" <<-EOT + [options] + RootDir = ${WORKDIR}/expac/root + DBPath = ${WORKDIR}/expac/root + + [${reponame}] + Server = file://$(realpath --no-symlinks -- "${dbfile%/*}") + EOT + + fakeroot pacman --config="${WORKDIR}/expac/pacman.conf" -Syy >/dev/null + # expac exits with non-zero on emtpy databases, so ignore errors + expac --config="${WORKDIR}/expac/pacman.conf" --sync "${args[@]}" || true +} + +main() { + WORKDIR=$(mktemp -dt "${0##*/}.XXXXXXXXXX") + readonly WORKDIR + trap "rm -rf -- ${WORKDIR@Q}" EXIT + + local repo + for repo in "${PKGREPOS[@]}"; do + msg "Processing %s..." "${repo}" + # Look for arch=(any) packages that exist in + # ${ARCHARCH} for this repo but not in any of + # ${ARCHES[@]}. + # + # Assume that all ${ARCHES[@]} agree on arch=(any) + # packages, and only inspect ${ARCHES[0]}. + comm -23 \ + <(expac_file "${FTP_BASE}/${repo}/os/${ARCHARCH}/${repo}.db" '%a %f' | awk '$1 == "any" { print $2 }') \ + <(expac_file "${FTP_BASE}/${repo}/os/${ARCHES[0]}/${repo}.db" '%a %f' | awk '$1 == "any" { print $2 }') \ + | xargs -d '\n' -r -n1 -- printf '%s/%s\n' "${FTP_BASE}/${repo}/os/${ARCHARCH}" \ + | xargs -d '\n' -r -- ln -srv -t "${WORKDIR}/staging/${repo}" -- + done - popd >/dev/null + msg "Running db-update..." + STAGING=${WORKDIR}/staging db-update +} - # Avoid mixups - unset SYNCED PKGS - done -done +main "$@" -- cgit v1.2.2