summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@parabola.nu>2018-10-03 15:19:27 -0400
committerLuke Shumaker <lukeshu@parabola.nu>2018-10-03 22:51:04 -0400
commit35094992a3804204b97d77dd74749d59b9f69280 (patch)
tree7b530a13c2db9019d385db58b2a9f1660b04a9dd
parent28ab9fc5754134437c6eb627ca103bf5e7efddc6 (diff)
db-import-any: Rewrite to use db-updatelukeshu/any2
-rw-r--r--config.local.import-ourarches2
-rwxr-xr-xdb-import-any97
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 <file.db> <expac_args>
+#
+# 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 "$@"