#!/bin/sh
# this script builds comparative chart of available kernel modules
# by flavour; it should be run in $ARCH/RPMS directory of the repo
# (c) 2010 Michael Shigorin <mike@altlinux.org>

KEY=
VALUE=

usage()
{
	echo "Usage: $0 -f|-m"
	echo "Builds comparative chart of available kernel modules"
	echo "when run in directory containing binary packages"
	echo
	echo "  -f: sort by kernel flavour"
	echo "  -m: sort by module name"
}

case "$1" in
	-m) ORDER='\1 \2';;
	-f) ORDER='\2 \1';;
	h|--help) usage; exit 0;;
	*) usage >&2; exit 1;;
esac

rpm -qp --qf='%{NAME}\n' kernel-modules-* \
| sed 's/^kernel-modules-\(.*\)-\([^-]\+-[^-]\+\)$/'"$ORDER"'/' \
| LC_COLLATE=C sort -u \
| while read k v; do
	[ "$k" == "$KEY" ] && {
		VALUE="$VALUE $v"
	} || {
		[ -n "$KEY" ] && echo "$KEY: $VALUE"
		KEY="$k"
		VALUE="$v"
	}
done
