#!/bin/sh
## #!/bin/sh -ef
export LC_ALL=C

repocop_cachedir=
while getopts c:h opt; do
	case "$opt" in
		c) repocop_cachedir="${OPTARG:?}"  ;;
		h) pod2usage --exit=0 "$0"; exit 0 ;;
		*) pod2usage --exit=2 "$0"; exit 2 ;;
	esac
done
shift "$((OPTIND-1))"

if [ -z "$repocop_cachedir" ]; then
	repocop_cachedir="$(readlink -ev "$HOME")/.repocop"
fi

rpmdb="$repocop_cachedir/db/rpm.db";
if ! [ -e $rpmdb ]; then
    echo "db/rpm.db not found at $repocop_cachedir"
    exit 1;
fi

sqlite3 $rpmdb "select distinct name from rpm as a, rpm_files as b where a.pkgid=b.pkgid and b.filename glob '/etc/rpm/macros.d/*' and a.name not glob '*compat*' and a.name not glob '*experimental*' and b.filename <> '/etc/rpm/macros.d/pam';"
exit 0;

: <<'__EOF__'

=head1	NAME

repocop-tools-ls-rpmbuild-bs-environment - lists packages that has rpm macros

=head1	SYNOPSIS

B<repocop-tools-ls-rpmbuild-bs-environment>
[B<-h>] 
[B<-c> I<repocopdir>]

=head1	DESCRIPTION

B<repocop-tools-ls-rpmbuild-bs-environment> 
lists packages that has rpm macros according to repocop database.

=head1	OPTIONS

=over

=item	B<-c> I<workdir>

Use I<workdir> working directory.
Default working directory is C<S<$HOME/.repocop>>.

=item	B<-h>

Display this help and exit.

=back

=head1	AUTHOR

Written by Igor Vlasenko <viy@altlinux.org>.

=head1	ACKNOWLEGEMENTS

To Alexey Torbin <at@altlinux.org>, whose qa-robot package
had a strong influence on repocop. 

=head1	COPYING

Copyright (c) 2008 Igor Vlasenko, ALT Linux Team.

This is free software; you can redistribute it and/or modify it under the terms
of the GNU General Public License as published by the Free Software Foundation;
either version 2 of the License, or (at your option) any later version.

=cut

__EOF__
