Add (1) readme and (2) copy of GPLv2 for stow.
[utils/utils.git] / dnf-repoquery-by-srpm
... / ...
CommitLineData
1#!/bin/bash
2# dnf-repoquery-by-srpm [dnf-options...] srpm-name...
3#
4# List the NEVRA of 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 -x
19set -o pipefail
20
21dnf_options=()
22orig_queryformat="%{name}-%{evr}.%{arch}"
23grep_options=()
24for arg in "$@"; do
25 case "$arg" in
26 (--qf=*)
27 orig_queryformat="${arg#--qf=}";;
28 (--queryformat=*)
29 orig_queryformat="${arg#--queryformat=}";;
30 (-*)
31 dnf_options+=("$arg");;
32 (*)
33 # Hope . is the only character special in a basic regular expression that
34 # occurs in package filenames.
35 grep_options+=(-e $'\x01'"${arg//./\.}\$");;
36 esac
37done
38
39real_queryformat="$orig_queryformat"$'\x01'"%{sourcerpm}"
40
41dnf repoquery --queryformat="$real_queryformat" "${dnf_options[@]}" \
42 | { grep "${grep_options[@]}" || true; } \
43 | sed -e $'s,\x01.*$,,'