blob: 0379a4c53a7da6bbcab6c0452f1701e04a35e25e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
#!/usr/bin/perl
# paclist - List all packages installed from a given repo
#
# Copyright (C) 2008 Dan McGee <dpmcgee@gmail.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/>.
use strict;
use warnings;
my $progname = "paclist";
my $version = "1.0";
if ($#ARGV != 0 || $ARGV[0] eq "--help" || $ARGV[0] eq "-h") {
print "$progname - List all packages installed from a given repo\n";
print "Usage: $progname <repo>\n";
print "Example: $progname testing\n";
if ($#ARGV != 0) {
exit 1;
}
exit 0;
}
if ( $ARGV[0] eq "--version" || $ARGV[0] eq "-v") {
print "$progname version $version\n";
print "Copyright (C) 2008 Dan McGee\n";
exit 0;
}
# This hash table will be used to store pairs of ('name version', count) from
# the return of both pacman -Sl <repo> and pacman -Q output. We then check to
# see if a value was added twice (count = 2)- if so, we will print that package
# as it is both in the repo we queried and installed on our local system.
my %packages = ();
my $output;
$output = `pacman -Sl $ARGV[0]`;
if ($? != 0) {
exit 1;
}
my @sync = split(/\n/, $output);
# sample output from pacman -Sl:
# testing foobar 1.0-1
foreach $_ (@sync) {
my @info = split(/ /);
# we only want to store 'foobar 1.0-1' in our hash table
my $pkg = $info[1] . " " . $info[2];
$packages{$pkg}++;
}
$output = `pacman -Q`;
if ($? != 0) {
exit 1;
}
# sample output from pacman -Q:
# foobar 1.0-1
my @local = split(/\n/, $output);
foreach $_ (@local) {
# store 'foobar 1.0-1' in our hash table
$packages{$_}++;
}
# run comparison check- if value was added twice, it was in the intersection
my @intersection;
foreach $_ (keys %packages) {
if ($packages{$_} == 2) {
push @{ \@intersection }, $_;
}
}
# print our intersection, and bask in the glory and speed of perl
@intersection = sort @intersection;
foreach $_ (@intersection) {
print $_ . "\n";
}
#vim: set noet:
|