doc/PKGBUILD: document libdeps
[pacman-ng.git] / contrib / paclist.in
blob0379a4c53a7da6bbcab6c0452f1701e04a35e25e
1 #!/usr/bin/perl
2 # paclist - List all packages installed from a given repo
4 # Copyright (C) 2008 Dan McGee <dpmcgee@gmail.com>
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 use strict;
20 use warnings;
22 my $progname = "paclist";
23 my $version = "1.0";
25 if ($#ARGV != 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
26 print "$progname - List all packages installed from a given repo\n";
27 print "Usage: $progname <repo>\n";
28 print "Example: $progname testing\n";
29 if ($#ARGV != 0) {
30 exit 1;
32 exit 0;
35 if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
36 print "$progname version $version\n";
37 print "Copyright (C) 2008 Dan McGee\n";
38 exit 0;
41 # This hash table will be used to store pairs of ('name version', count) from
42 # the return of both pacman -Sl <repo> and pacman -Q output. We then check to
43 # see if a value was added twice (count = 2)- if so, we will print that package
44 # as it is both in the repo we queried and installed on our local system.
45 my %packages = ();
46 my $output;
48 $output = `pacman -Sl $ARGV[0]`;
49 if ($? != 0) {
50 exit 1;
52 my @sync = split(/\n/, $output);
53 # sample output from pacman -Sl:
54 # testing foobar 1.0-1
55 foreach $_ (@sync) {
56 my @info = split(/ /);
57 # we only want to store 'foobar 1.0-1' in our hash table
58 my $pkg = $info[1] . " " . $info[2];
59 $packages{$pkg}++;
62 $output = `pacman -Q`;
63 if ($? != 0) {
64 exit 1;
66 # sample output from pacman -Q:
67 # foobar 1.0-1
68 my @local = split(/\n/, $output);
69 foreach $_ (@local) {
70 # store 'foobar 1.0-1' in our hash table
71 $packages{$_}++;
74 # run comparison check- if value was added twice, it was in the intersection
75 my @intersection;
76 foreach $_ (keys %packages) {
77 if ($packages{$_} == 2) {
78 push @{ \@intersection }, $_;
82 # print our intersection, and bask in the glory and speed of perl
83 @intersection = sort @intersection;
84 foreach $_ (@intersection) {
85 print $_ . "\n";
88 #vim: set noet: