From 9aa21ffdd18f0b92aeaa2ba505c01a2ae38437e3 Mon Sep 17 00:00:00 2001 From: Dridi Boukelmoune Date: Jan 06 2019 11:10:18 +0000 Subject: Add rpm -a support to rpmls And grow a more robust handling of options and arguments. Using the -p option should be based on whether the argument refers to a file instead of a heuristic based on a glob expression `*.[sr]pm` that somehow will accept `.spm` as a valid RPM extension. It becomes possible to compose commands like this: rpmls -la varnish\* | awk '/^d/ {print $NF}' | sort --- diff --git a/rpmls b/rpmls index cb6ca71..6c9552e 100755 --- a/rpmls +++ b/rpmls @@ -16,15 +16,49 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +set -u + +all= owner= -if [ "$1" = "-l" ] ; then - owner='%-8{fileusername} %-8{filegroupname} ' - shift -fi + +usage() { + cat <<-EOF + rpmls -- List contents of rpm packages + + Usage: rpmls [-a] [-l] PKG... + rpmls -? + + Options: + -a list all packages matching a PKG + -l use a long listing format + -? print this help and exit + + The PKG arguments may either be package + name expressions or file names. + EOF + exit +} + +while getopts 'al?' opt +do + case $opt in + a) all=a ;; + l) owner='%-8{fileusername} %-8{filegroupname} ' ;; + ?) usage ;; + esac +done + +shift $((OPTIND - 1)) + qf="[%-11{filemodes:perms} $owner%{filenames}\\n]" for arg in "$@" ; do - p= - case "$arg" in *.[rs]pm) p=p ;; esac - rpm -q$p --qf="$qf" --nodigest --nosignature "$arg" + a=$all + p= + if [ -f "$arg" ] + then + a= + p=p + fi + rpm -q$a$p --qf="$qf" --nodigest --nosignature "$arg" done