5 spectool - tool to work with rpm spec files
9 spectool [options] specfiles...
17 display help as manpage
19 =item B<--dist>=I<STRING>
21 set distribution, e.g. "11.1-i586" or path to config
23 =item B<--archpath>=I<STRING>
25 compatible architecture separated by colon, e.g. C<i586:i486:i386>.
26 Autotected if missing.
28 =item B<--configdir>=I<STRING>
30 path to config files if B<--dist> didn't specify a full path
32 =item B<--define>=I<STRING>
34 =item B<--with>=I<STRING>
36 =item B<--without>=I<STRING>
38 same meaning as in rpmbuild
40 =item B<--tag>=I<STRING>
42 print tag from spec file, e.g. C<version>. Regexp is also possible,
47 print package source files. If a file C<sources> or
48 C<I<packagename>.sources> is present verify the checksums against
59 download missing sources
67 The B<--sources> option allows to manage a sources file in a way
68 similar to Fedora. The sources file lists the check sums and file
69 names of the binary files specified in the spec file.
71 B<--sources> without further options compares the check sums of all
72 files and prints a report consisting of a character that describes
73 the status of the file and the file name. Meaning of the characters
78 =item B<.> check sum matches
80 =item B<!> check sum broken
82 =item B<d> file is missing, checksum known. Can be verified after download
84 =item B<-> file is missing and checksum unknown
86 =item B<_> file is present but checksum unknown
88 =item B<t> text file, will be skipped for check sums
90 =item B<?> check sum known but not referenced from spec file
94 Additionally specifying B<--update> recomputes all check sums and
95 updates the sources file.
97 With B<--download> all missing files are downloaded if the spec file
98 has an http or ftp url.
100 =head2 FORMAT OF THE SOURCES FILE
103 <checksum> <whitespace> <filename>
105 =head2 NAME OF THE SOURCES FILE
107 A file named C<sources> is preferred if present for compatibility
108 with Fedora. It only contains md5 sums. If that file is not present
109 the C<.spec> suffix of the spec file is replaced with C<.sources>
110 and the this name used as sources file (e.g. C<foo.spec> ->
111 C<foo.sources>). In this file sha1 is preferred. Also, the name of
112 the algorithm is prepended with colon to the check sum.
119 $builddir = ($::ENV{'BUILD_DIR'} || '/usr/lib/build');
120 unshift @INC, $builddir;
128 Getopt::Long::Configure("no_ignore_case");
130 my (@opt_showtag, $opt_sources, $opt_update, $opt_download);
134 my ($dist, $rpmdeps, $archs, $configdir, $useusedforbuild);
139 "help" => sub { pod2usage(-exitstatus => 0, -verbose => 2) },
142 "archpath=s" => \$archs,
143 "configdir=s" => \$configdir,
144 "define=s" => sub { Build::define($_[1]) },
145 "with=s" => sub { Build::define("_with_".$_[1]." --with-".$_[1]) },
146 "without=s" => sub { Build::define("_without_".$_[1]." --without-".$_[1]) },
148 "tag=s" => \@opt_showtag,
149 "sources" => \$opt_sources,
150 "update" => \$opt_update,
151 "download" => \$opt_download,
153 "download-recompress=s",
155 "download-compare=s",
156 "download-delete-identical",
159 pod2usage(1) unless @ARGV;
165 die "--download must be used together with --sources\n" if ($opt_download && !$opt_sources);
166 die "--update must be used together with --sources\n" if ($opt_update && !$opt_sources);
168 $options{'download-recompress'} ||= 'auto';
169 $options{'download-outdir'}.='/' if ($options{'download-outdir'} && $options{'download-outdir'} !~ /\/$/);
170 $options{'download-outdir'} ||= '';
171 $options{'download-compare'}.='/' if ($options{'download-compare'} && $options{'download-compare'} !~ /\/$/);
172 $options{'download-compare'} ||= '';
175 if (!defined $archs) {
177 my %archmap = qw/x86_64 i686 i686 i586 i586 i486 i486 i386/;
180 while(exists $archmap{$archs[-1]}) {
181 push @archs, $archmap{$archs[-1]};
184 @archs = split(':', $archs);
186 push @archs, 'noarch' unless grep {$_ eq 'noarch'} @archs;
190 # $dist = `rpm -q --qf '%{DISTRIBUTION}' rpm 2>/dev/null`;
191 # $dist = Build::dist_canon($dist||'', $archs[0]);
194 if($dist !~ /\// && !defined $configdir) {
196 use File::Basename qw/dirname/;
197 $configdir = dirname($0).'/configs';
198 undef $configdir unless -e $configdir.'/sl11.3.conf';
200 $configdir = $builddir.'/configs';
201 undef $configdir unless -e $configdir.'/sl11.3.conf';
203 if(!defined $configdir) {
204 print STDERR "please specify config dir\n";
208 #######################################################################
210 # param: array to fill, spec file
212 sub read_sources_digests($$)
216 my $srcfile = 'sources';
219 $srcfile =~ s/spec$/sources/;
221 if (open (F, '<', $srcfile)) {
224 my ($sum, $file) = split(/ +/, $_, 2);
225 $files->{$file} = $sum;
232 # param: file, oldsum
233 # return: newsum or undef if match
237 my $oldsum = shift || 'sha1:';
240 if($oldsum =~ /^(\S+:)/) {
243 $oldsum = $type.$oldsum;
245 if ($type eq 'md5:') {
246 $sum = $type.`md5sum $file` || die "md5sum failed\n";
247 } elsif ($type eq 'sha1:') {
248 $sum = $type.`sha1sum $file` || die "sha1sum failed\n";
250 die "unsupported digest type '$type'\n";
253 if($sum ne $oldsum) {
261 my ($url, $dest) = @_;
264 my $res = $ua->mirror($url, $dest);
265 last if $res->is_success;
266 # if it's a redirect we probably got a bad mirror and should just retry
267 return 0 unless $retry && $res->previous;
268 warn "retrying $url\n";
273 #######################################################################
276 for my $spec (@specs) {
277 my $cf = Build::read_config_dist($dist, $archs[0], $configdir);
278 my $parsed = Build::parse($cf, $spec);
280 if (!defined $parsed) {
281 die "can't parse $spec\n";
284 for my $tag (@opt_showtag) {
285 if($tag =~ /^\/(.+)\/$/) {
287 for my $t (keys %$parsed) {
289 push @opt_showtag, $t;
293 if(exists $parsed->{lc $tag}) {
295 my $v = $parsed->{lc $tag};
296 $v = join(' ', @$v) if (ref $v eq 'ARRAY');
299 print STDERR "$tag does not exist\n";
306 my $srcfile = read_sources_digests($files, $spec);
310 $ua = LWP::UserAgent->new(
311 agent => "openSUSE build service",
316 for my $t (keys %$parsed) {
317 next unless ($t =~ /^(?:source|patch)\d*/);
318 my $url = $parsed->{$t};
319 next unless $url =~ /^(?:https?|ftp):\/\//;
322 my $src = $options{'download-compare'}.$file;
323 next if -e $src && !($options{'download-force'} || $options{'download-delete-identical'});
324 print "Downloading $file...\n";
325 my $dest = $options{'download-outdir'}.$file;
326 print "$url -> $dest\n";
328 if(!download($url, $dest) && $options{'download-recompress'} ne 'no') {
330 # let's see if the file was recompressed
331 if($url =~ s/\.bz2$/.gz/ && $file =~ s/\.bz2$/.gz/
332 && !download($url, $dest)) {
333 if(system('bznew', $dest) == 0) {
334 print STDERR "Used $file and recompressed to bz2 instead\n";
339 print STDERR "Downloading $file failed\n";
342 if ($options{'download-delete-identical'} && $options{'download-outdir'}
343 && system('cmp', '-s', $dest, $src) == 0) {
350 for my $t (keys %$parsed) {
351 next unless ($t =~ /^(?:source|patch)\d*/);
352 my $file = $parsed->{$t};
354 next unless -B $file;
355 my $sum = check_sum($file, ($files->{$file} || ($srcfile eq 'sources'?'md5:':'sha1:')));
357 print STDERR "update $file\n";
358 $files->{$file} = $sum;
363 if(open(F, '>', $srcfile)) {
364 for my $file (keys %$files) {
365 $files->{$file} =~ s/^md5:// if $srcfile eq 'sources';
366 print F $files->{$file}, ' ', $file, "\n";
372 for my $t (keys %$parsed) {
373 next unless ($t =~ /^(?:source|patch)\d*/);
374 my $file = $parsed->{$t};
376 if (!exists $files->{$file}) {
384 } elsif (! -e $file) {
386 delete $files->{$file};
388 my $sum = check_sum($file, $files->{$file});
395 delete $files->{$file};
397 print $parsed->{$t}, "\n";
399 for my $file (keys %$files) {