/[smeserver]/builds_bin/update_rpms_dir
ViewVC logotype

Contents of /builds_bin/update_rpms_dir

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.2 - (show annotations) (download)
Fri Oct 14 00:14:28 2005 UTC (19 years, 1 month ago) by gordonr
Branch: MAIN
Changes since 1.1: +2 -2 lines
Make output c&p friendly, and use cp -p

1 #!/usr/bin/perl -w
2 #
3 # Copyright (c) 2005 Gormand Pty Ltd. All rights reserved. This program
4 # is free software; you can redistribute it and/or modify it under the
5 # same terms as Perl itself.
6 #
7 # $Id: update_rpms_dir,v 1.1.1.1 2005/09/15 23:55:09 gordonr Exp $
8 #
9 # Update RPMS directory with the latest from a given list of directories
10
11 use RPM2;
12 use Getopt::Long;
13
14 my $rpm_flags = RPM2->vsf_nodsa; # Deal with missing DSA keys
15
16 GetOptions(\%opt, "verbose");
17
18 # XXX - FIXME - These will be command line options
19
20 my $rpms_dir = "/builds/RPMS";
21
22 my @repositories = qw(
23 /builds/rpms/RPMS/i386/
24 /builds/rpms/RPMS/noarch/
25 /mirrors/mitel/devel/repo/RPMS/
26 /mirrors/centos/4.1/updates/i386/RPMS/
27 /mirrors/centos/4.1/os/i386/CentOS/RPMS/
28 );
29
30 chdir $rpms_dir or die "Couldn't chdir $rpms_dir";
31
32 opendir RPMS, '.' or die "Couldn't opendir $rpms_dir";
33
34 for my $file ( sort grep { /.rpm$/ } readdir RPMS )
35 {
36 warn "Checking $file:\n" if $opt{verbose};
37
38 my $rpm = RPM2->open_package($file, $rpm_flags);
39
40 for my $dir ( @repositories )
41 {
42 my $newest = find_newest($rpm, $dir);
43
44 if ($newest)
45 {
46 # XXX - FIXME - Should we try other repos, or stop here?
47 warn "cd $rpms_dir; rm $file; cp -p $dir/$newest .\n"
48 }
49 }
50 }
51
52 sub find_newest
53 {
54 my ($rpm, $dir) = @_;
55
56 # XXX - FIXME - Need to cater for multiple architectures
57
58 my $name = $rpm->name;
59 $name =~ s/\+/\\+/g; # libstdc++ and friends
60
61 opendir DIR, $dir or die "Couldn't opendir $dir";
62 my @rpms = grep { /^${name}-.*.rpm$/ } readdir DIR;
63 closedir DIR;
64
65 my $newest_file = undef;
66 my $newest_hdr = undef;
67
68 for my $file (@rpms)
69 {
70 my $candidate = RPM2->open_package("$dir/$file", $rpm_flags);
71
72 if ($candidate->name ne $name)
73 {
74 warn "Ignoring $file - name doesn't match\n" if $opt{verbose};
75 next;
76 }
77
78 if ( ($candidate cmp $rpm) <= 0)
79 {
80 warn "Ignoring $file - older or same version\n" if $opt{verbose};
81 next;
82 }
83
84 if (not defined $newest_hdr or ($candidate cmp $newest_hdr) < 0)
85 {
86 warn "Newest is $file\n" if $opt{verbose};
87 $newest_file = $file;
88 $newest_hdr = $candidate;
89 }
90 }
91
92 return $newest_file;
93 }

admin@koozali.org
ViewVC Help
Powered by ViewVC 1.2.1 RSS 2.0 feed