#!/bin/bash # dnf-repoquery-by-srpm [dnf-options...] srpm-name... # # List the NEVRA of every package built from one of the given source RPMs # (given by full name as in the SOURCERPM tag, e.g., glibc-2.31-4.fc32.src.rpm). # # This script's option parser is crude and assumes that every argument that # doesn't begin with a dash is a source RPM name, so you must use the # "--opt=val" form of dnf options, not "--opt val". Also, if you customize # the query format, it must not contain an embedded newline or \x01. # # Ideally "dnf repoquery" would support arbitrary query tags like rpm # (i.e., "rpm -qa SOURCERPM=...") and we wouldn't need this script. # # ~ Matt 2020-09-02 set -e set -x set -o pipefail dnf_options=() orig_queryformat="%{name}-%{evr}.%{arch}" grep_options=() for arg in "$@"; do case "$arg" in (--qf=*) orig_queryformat="${arg#--qf=}";; (--queryformat=*) orig_queryformat="${arg#--queryformat=}";; (-*) dnf_options+=("$arg");; (*) # Hope . is the only character special in a basic regular expression that # occurs in package filenames. grep_options+=(-e $'\x01'"${arg//./\.}\$");; esac done real_queryformat="$orig_queryformat"$'\x01'"%{sourcerpm}" dnf repoquery --queryformat="$real_queryformat" "${dnf_options[@]}" \ | { grep "${grep_options[@]}" || true; } \ | sed -e $'s,\x01.*$,,'