Add mock configuration for building against the local dnf repository
[utils/utils.git] / dnf-repoquery-by-srpm
... / ...
CommitLineData
1#!/bin/bash
2# dnf-repoquery-by-srpm [dnf-options...] srpm-name...
3#
4# List every package built from one of the given source RPMs
5# (given by full name as in the SOURCERPM tag, e.g., glibc-2.31-4.fc32.src.rpm).
6#
7# This script's option parser is crude and assumes that every argument that
8# doesn't begin with a dash is a source RPM name, so you must use the
9# "--opt=val" form of dnf options, not "--opt val". Also, if you customize
10# the query format, it must not contain an embedded newline or \x01.
11#
12# Ideally "dnf repoquery" would support arbitrary query tags like rpm
13# (i.e., "rpm -qa SOURCERPM=...") and we wouldn't need this script.
14#
15# ~ Matt 2020-09-02
16
17set -e
18set -o pipefail
19
20dnf_options=()
21orig_queryformat="%{name}-%{evr}.%{arch}"
22grep_options=()
23for arg in "$@"; do
24 case "$arg" in
25 (--qf=*)
26 orig_queryformat="${arg#--qf=}";;
27 (--queryformat=*)
28 orig_queryformat="${arg#--queryformat=}";;
29 (-*)
30 dnf_options+=("$arg");;
31 (*)
32 # Hope . is the only character special in a basic regular expression that
33 # occurs in package filenames.
34 grep_options+=(-e $'\x01'"${arg//./\.}\$");;
35 esac
36done
37
38real_queryformat="$orig_queryformat"$'\x01'"%{sourcerpm}"
39
40dnf repoquery --queryformat="$real_queryformat" "${dnf_options[@]}" \
41 | { grep "${grep_options[@]}" || true; } \
42 | sed -e $'s,\x01.*$,,'