[pacman-dev] List packages from a given repo

Dan McGee dpmcgee at gmail.com
Thu May 8 12:33:19 EDT 2008


On Thu, May 8, 2008 at 9:36 AM, Allan McRae <allan.mcrae at qimr.edu.au> wrote:
> Hi,
>
> I attach a script tentatively called "repopkg" that lists all packages
> installed from a given repo. I find this useful for monitoring what I have
> installed from [testing]. It is not entirely fool proof as it assumes you
> have installed packages using "pacman -S pkg" and not "pacman -S repo/pkg".
Handy little script.

> A couple of queries. Can someone come up with a better name which is not too
> long?  And any comments before I submit the for inclusion in the contrib
> directory (it is best to come as a git patch right?).
Yeah, that would be great, so you can add a bit of a description in
the commit message.

> Cheers,
> Allan
>
> #!/bin/bash
> # repopkg - List all packages installed from a given repo
> #
> # Copyright (C) 2008 Allan McRae <mcrae_allan at hotmail.com>
> #
> # This program 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.
> #
> # This program is distributed in the hope that it will be useful,
> # but WITHOUT ANY WARRANTY; without even the implied warranty of
> # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
> # GNU General Public License for more details.
> #
> # You should have received a copy of the GNU General Public License
> # along with this program.  If not, see <http://www.gnu.org/licenses/>.
>
> # TODO: Could match version numbers to catch packages
> #       install with pacman -S repo/pkg
Did you take a look at my pacsearch script? That does some sort of
intelligent matching of package versions.

>
>
> readonly progname="repopkg"
> readonly version="1.0"
>
> if [ -z "$1" -o "$1" = "--help" -o "$1" = "-h" ]; then
>        echo "Usage: $progname <repo>"
>        echo "Ex:    $progname testing"
Just spell out "Example"? We can afford a few more bytes. :)

>        exit 0
> fi
>
> if [ "$1" = "--version" -o "$1" = "-v" ]; then
>        echo "$progname version $version"
>        echo "Copyright (C) 2008 Allan McRae"
>        exit 0
> fi
>
> pkglist=$(mktemp)
> pacman -Sl > $pkglist
>
> for pkg in $(pacman -Qq); do
>  match=$(grep -m1 " $pkg " $pkglist | grep "^$1")
Not exactly cheap as you have to do two grep calls for every package
you list. Perhaps cmp or diff could be used?

And now for the real off-the-wall suggestion- doing this in perl would
give you the power of regular expressions and probably make this all
real easy. That is if you can figure out perl.

>  if [ -n "${match}" ]; then
>    echo $pkg
>  fi
> done
>
> rm $pkglist




More information about the pacman-dev mailing list