1 | #! /bin/env perl |
---|
2 | |
---|
3 | use strict; |
---|
4 | use warnings; |
---|
5 | use Sophie::Client; |
---|
6 | use Getopt::Long; |
---|
7 | use Pod::Usage; |
---|
8 | use Config::General; |
---|
9 | use File::Temp; |
---|
10 | |
---|
11 | =head1 NAME |
---|
12 | |
---|
13 | sophie-rpm - Tools to check rpms over Sophie Website |
---|
14 | |
---|
15 | =cut |
---|
16 | |
---|
17 | =head1 SYNOPSYS |
---|
18 | |
---|
19 | sophie-rpm [-c configfile] [--proxy proxy] RPM1 [RPM2 [...]] |
---|
20 | |
---|
21 | =cut |
---|
22 | |
---|
23 | my $distrib = {}; |
---|
24 | my $searchsp = {}; |
---|
25 | |
---|
26 | =head1 OPTIONS |
---|
27 | |
---|
28 | =over4 |
---|
29 | |
---|
30 | =item -c configfile |
---|
31 | |
---|
32 | Use this config instead default one (C<~/.sophie.conf>) |
---|
33 | |
---|
34 | =item --proxy proxy |
---|
35 | |
---|
36 | Use this proxy to connect sophie's web site. The proxy must given as an url |
---|
37 | like C<http://proxy:8080/> |
---|
38 | |
---|
39 | =item -v |
---|
40 | |
---|
41 | Being verbose, show each required packages |
---|
42 | |
---|
43 | =item -s |
---|
44 | |
---|
45 | Search in database package matching unresolved dependencies |
---|
46 | |
---|
47 | =back |
---|
48 | |
---|
49 | =cut |
---|
50 | |
---|
51 | =item HEAD1 config file |
---|
52 | |
---|
53 | The configuration must look like something like this |
---|
54 | |
---|
55 | # url http://sophie.zarb.org/rpc |
---|
56 | # proxy http://nanardon.zarb.org:3128/ |
---|
57 | <distrib> |
---|
58 | distribution Mandriva |
---|
59 | release 2010.0 |
---|
60 | arch x86_64 |
---|
61 | </distrib> |
---|
62 | <distrib> |
---|
63 | distribution Mandriva |
---|
64 | release cooker |
---|
65 | arch x86_64 |
---|
66 | </distrib> |
---|
67 | |
---|
68 | =over 4 |
---|
69 | |
---|
70 | =item proxy URL |
---|
71 | |
---|
72 | Optionnal proxy to use to connect to sophie website |
---|
73 | |
---|
74 | =item url URL |
---|
75 | |
---|
76 | The url of C<RPC> top method, default is C<http://sophie.zarb.org/rpc>. |
---|
77 | |
---|
78 | =item distrib |
---|
79 | |
---|
80 | The distribution for which rpms must be checked |
---|
81 | |
---|
82 | =over 4 |
---|
83 | |
---|
84 | =item distribution |
---|
85 | |
---|
86 | The distribution name |
---|
87 | |
---|
88 | =item release |
---|
89 | |
---|
90 | The release provided by this distribution |
---|
91 | |
---|
92 | =item arch |
---|
93 | |
---|
94 | The architecture for this distribution/release |
---|
95 | |
---|
96 | =back |
---|
97 | |
---|
98 | =item search |
---|
99 | |
---|
100 | Works like distrib but is used to find not found dependencies when C<-s> is |
---|
101 | used. |
---|
102 | |
---|
103 | =back |
---|
104 | |
---|
105 | =cut |
---|
106 | |
---|
107 | GetOptions( |
---|
108 | 'c=s' => \my $configfile, |
---|
109 | 'u=s' => \my $url, |
---|
110 | 'l=s' => \my $login, |
---|
111 | 'p=s' => \my $pass, |
---|
112 | 'v' => \my $verbose, |
---|
113 | 's' => \my $search, |
---|
114 | 'proxy' => \my $proxy, |
---|
115 | ) or pod2usage; |
---|
116 | |
---|
117 | $configfile ||= "$ENV{HOME}/.sophie.conf"; |
---|
118 | |
---|
119 | if (-f $configfile && (my $conf = Config::General->new($configfile))) { |
---|
120 | my %config = $conf->getall; |
---|
121 | $url ||= $config{url}; |
---|
122 | $login ||= $config{login}; |
---|
123 | $pass ||= $config{pass}; |
---|
124 | $proxy ||= $config{proxy}; |
---|
125 | $distrib = $config{distrib}; |
---|
126 | $searchsp = $config{search}; |
---|
127 | } |
---|
128 | |
---|
129 | my $sc = Sophie::Client->new( |
---|
130 | server => $url, |
---|
131 | login => $login, |
---|
132 | password => $pass, |
---|
133 | proxy => $proxy, |
---|
134 | ); |
---|
135 | |
---|
136 | $sc->login; |
---|
137 | |
---|
138 | my $ts = $sc->ts($distrib); |
---|
139 | |
---|
140 | foreach my $rpm (@ARGV) { |
---|
141 | $ts->add_rpm($rpm) or die "Cannot add $rpm"; |
---|
142 | } |
---|
143 | |
---|
144 | my $res = $ts->run( |
---|
145 | verbose => $verbose, |
---|
146 | ); |
---|
147 | $ts->summary if (@ARGV > 1); |
---|
148 | print "\nThis transaction would failed\n" if(!$res); |
---|
149 | if ($search) { |
---|
150 | print "\nSearching depedencies in sophie\n"; |
---|
151 | foreach my $dep (@{ $ts->{unresolved}} ) { |
---|
152 | my $res = $sc->send_request( |
---|
153 | 'search.rpm.bydep', $searchsp, 'P', split(' ', $dep) |
---|
154 | ); |
---|
155 | if (ref $res && !$res->is_fault) { |
---|
156 | print "$dep: " . $res->value->{total_entries} . " results\n"; |
---|
157 | foreach (@{ $res->value->{results} }) { |
---|
158 | print " " . $sc->send_request('rpms.basicinfo', $_)->value->{filename}; |
---|
159 | print "\n"; |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | } |
---|
164 | exit($res ? 0 : 1); |
---|
165 | |
---|
166 | =head1 AUTHOR |
---|
167 | |
---|
168 | Olivier Thauvin C<nanardon@nanardon.zarb.org> |
---|
169 | |
---|
170 | =head1 SEE ALSO |
---|
171 | |
---|
172 | L<http://sophie.zarb.org> |
---|
173 | |
---|
174 | =head1 COPYRIGHT AND LICENSE |
---|
175 | |
---|
176 | Copyright (C) 2010 by Olivier Thauvin |
---|
177 | |
---|
178 | This library is free software; you can redistribute it and/or modify |
---|
179 | it under the same terms as Perl itself, either Perl version 5.12.2 or, |
---|
180 | at your option, any later version of Perl 5 you may have available. |
---|
181 | |
---|
182 | =cut |
---|