/[svn.andrew.net.au]/scripts/rh_update
ViewVC logotype

Annotation of /scripts/rh_update

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1 - (hide annotations)
Sun Jun 25 17:33:52 2006 UTC (18 years, 3 months ago) by apollock
File size: 6304 byte(s)
Initial experiment with svn
1 apollock 1 #!/usr/bin/perl -w
2    
3     use strict;
4     use URI;
5     use File::Basename;
6    
7     #########
8     #
9     # Partially completed Red Hat updates parser.
10     # Compares updated RPMs on a mirror against installed versions
11     #
12     #########
13    
14     my $UPDATES_i386_URL="http://public.ftp.planetmirror.com/pub/redhat/updates/7.3/en/os/i386/";
15     my $UPDATES_i686_URL="http://public.ftp.planetmirror.com/pub/redhat/updates/7.3/en/os/i686/";
16     my $UPDATES_NOARCH_URL="http://public.ftp.planetmirror.com/pub/redhat/updates/7.3/en/os/noarch/";
17    
18     my $DEBUG = 1;
19    
20     sub parse_rpm($) {
21     my $file = $_[0];
22     my %p;
23    
24     if (substr($file, -4) ne ".rpm") {
25     return 0;
26     }
27    
28     my @parts = split("-", substr($file, 0, length($file) - 4));
29     my @temp = split(/\./, pop(@parts));
30     $p{'a'} = pop(@temp);
31     $p{'r'} = join(".", @temp);
32     $p{'v'} = pop(@parts);
33     $p{'n'} = join("-", @parts);
34    
35     return \%p;
36     }
37    
38     sub parse_package($) {
39     my $package = $_[0];
40     my %p;
41    
42     my @parts = split("-", $package);
43     my @temp = split(/\./, pop(@parts));
44     $p{'r'} = join(".", @temp);
45     $p{'v'} = pop(@parts);
46     $p{'n'} = join("-", @parts);
47    
48     return \%p;
49     }
50    
51    
52     my %UPDATES_i386;
53     my %UPDATES_i686;
54     my %UPDATES_NOARCH;
55     my %INSTALLED_PACKAGES;
56    
57     open(LYNX, "lynx -dump $UPDATES_i386_URL |");
58     while(<LYNX>) {
59     chomp;
60     if (/^\s+\d+\.(.*)/) {
61     my $URL = $1;
62     if ($URL =~ /\.rpm$/) {
63     $URL = URI->new($URL);
64     my $package = basename($URL->path());
65     print "Populating hash for $package\n" if ($DEBUG);
66     my $rpm_package = parse_rpm($package);
67     print "\tWorking with $rpm_package->{'n'}\n" if ($DEBUG);
68     print "\tWorking with $rpm_package->{'v'}\n" if ($DEBUG);
69     print "\tWorking with $rpm_package->{'r'}\n" if ($DEBUG);
70     print "\tWorking with $rpm_package->{'a'}\n" if ($DEBUG);
71     $rpm_package->{'URL'} = $URL->as_string();
72     $UPDATES_i386{$rpm_package->{'n'}} = $rpm_package;
73     }
74     }
75     }
76     close(LYNX);
77    
78     open(LYNX, "lynx -dump $UPDATES_NOARCH_URL |");
79     while(<LYNX>) {
80     chomp;
81     if (/^\s+\d+\.(.*)/) {
82     my $URL = $1;
83     if ($URL =~ /\.rpm$/) {
84     $URL = URI->new($URL);
85     my $package = basename($URL->path());
86     print "Populating hash for $package\n" if ($DEBUG);
87     my $rpm_package = parse_rpm($package);
88     print "\tWorking with $rpm_package->{'n'}\n" if ($DEBUG);
89     print "\tWorking with $rpm_package->{'v'}\n" if ($DEBUG);
90     print "\tWorking with $rpm_package->{'r'}\n" if ($DEBUG);
91     print "\tWorking with $rpm_package->{'a'}\n" if ($DEBUG);
92     $rpm_package->{'URL'} = $URL->as_string();
93     $UPDATES_NOARCH{$rpm_package->{'n'}} = $rpm_package;
94     }
95     }
96     }
97     close(LYNX);
98    
99     open(LYNX, "lynx -dump $UPDATES_i686_URL |");
100     while(<LYNX>) {
101     chomp;
102     if (/^\s+\d+\.(.*)/) {
103     my $URL = $1;
104     if ($URL =~ /\.rpm$/) {
105     $URL = URI->new($URL);
106     my $package = basename($URL->path());
107     print "Populating hash for $package\n" if ($DEBUG);
108     my $rpm_package = parse_rpm($package);
109     print "\tWorking with $rpm_package->{'n'}\n" if ($DEBUG);
110     print "\tWorking with $rpm_package->{'v'}\n" if ($DEBUG);
111     print "\tWorking with $rpm_package->{'r'}\n" if ($DEBUG);
112     print "\tWorking with $rpm_package->{'a'}\n" if ($DEBUG);
113     $rpm_package->{'URL'} = $URL->as_string();
114     $UPDATES_i686{$rpm_package->{'n'}} = $rpm_package;
115     }
116     }
117     }
118     close(LYNX);
119    
120     open(RPM, "rpm -qa --queryformat '%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm\n' |");
121     while(<RPM>) {
122     chomp;
123     my $package = parse_rpm($_);
124     $INSTALLED_PACKAGES{$package->{'n'}} = $package;
125     }
126     close(RPM);
127    
128     print "Loaded information about ", scalar keys(%INSTALLED_PACKAGES), " installed packages\n" if ($DEBUG);
129     print "Loaded information about ", scalar keys(%UPDATES_i386), " update packages\n" if ($DEBUG);
130    
131     my ($pkg, $pkg_info);
132    
133     print "Processing i386 updates\n";
134     while (($pkg, $pkg_info) = each %UPDATES_i386) {
135     print "Examining $pkg\n" if ($DEBUG);
136     if (exists $INSTALLED_PACKAGES{$pkg}) {
137     print "\tWe have it installed\n" if ($DEBUG);
138     if ("$INSTALLED_PACKAGES{$pkg}->{'v'}-$INSTALLED_PACKAGES{$pkg}->{'r'}" ne "$UPDATES_i386{$pkg}->{'v'}-$UPDATES_i386{$pkg}->{'r'}") {
139     print "Examining $pkg\n" if (!$DEBUG);
140     print "\tOur version is $INSTALLED_PACKAGES{$pkg}->{'v'}\n" if ($DEBUG);
141     print "\tUpdated version is $UPDATES_i386{$pkg}->{'v'}\n" if ($DEBUG);
142     print "\tOutstanding update for $pkg ($UPDATES_i386{$pkg}->{'v'}-$UPDATES_i386{$pkg}->{'r'} != $INSTALLED_PACKAGES{$pkg}->{'v'}-$INSTALLED_PACKAGES{$pkg}->{'r'})\n" if (!$DEBUG);
143     print "\t$UPDATES_i386{$pkg}->{'URL'}\n";
144     } else {
145     print "\t$pkg is up to date with latest available update\n" if ($DEBUG);
146     }
147     }
148     }
149    
150     print "Processing i686 updates\n";
151     while (($pkg, $pkg_info) = each %UPDATES_i686) {
152     print "Examining $pkg\n" if ($DEBUG);
153     if (exists $INSTALLED_PACKAGES{$pkg}) {
154     print "\tWe have it installed\n" if ($DEBUG);
155     if ("$INSTALLED_PACKAGES{$pkg}->{'v'}-$INSTALLED_PACKAGES{$pkg}->{'r'}" ne "$UPDATES_i686{$pkg}->{'v'}-$UPDATES_i686{$pkg}->{'r'}") {
156     print "Examining $pkg\n" if (!$DEBUG);
157     print "\tOur version is $INSTALLED_PACKAGES{$pkg}->{'v'}\n" if ($DEBUG);
158     print "\tUpdated version is $UPDATES_i686{$pkg}->{'v'}\n" if ($DEBUG);
159     print "\tOutstanding update for $pkg ($UPDATES_i686{$pkg}->{'v'}-$UPDATES_i686{$pkg}->{'r'} != $INSTALLED_PACKAGES{$pkg}->{'v'}-$INSTALLED_PACKAGES{$pkg}->{'r'})\n" if (!$DEBUG);
160     print "\t$UPDATES_i686{$pkg}->{'URL'}\n";
161     } else {
162     print "\t$pkg is up to date with latest available update\n" if ($DEBUG);
163     }
164     }
165     }
166    
167     print "Processing noarch updates\n";
168     while (($pkg, $pkg_info) = each %UPDATES_NOARCH) {
169     print "Examining $pkg\n" if ($DEBUG);
170     if (exists $INSTALLED_PACKAGES{$pkg}) {
171     print "\tWe have it installed\n" if ($DEBUG);
172     if ("$INSTALLED_PACKAGES{$pkg}->{'v'}-$INSTALLED_PACKAGES{$pkg}->{'r'}" ne "$UPDATES_NOARCH{$pkg}->{'v'}-$UPDATES_NOARCH{$pkg}->{'r'}") {
173     print "Examining $pkg\n" if (!$DEBUG);
174     print "\tOur version is $INSTALLED_PACKAGES{$pkg}->{'v'}\n" if ($DEBUG);
175     print "\tUpdated version is $UPDATES_NOARCH{$pkg}->{'v'}\n" if ($DEBUG);
176     print "\tOutstanding update for $pkg ($UPDATES_NOARCH{$pkg}->{'v'}-$UPDATES_NOARCH{$pkg}->{'r'} != $INSTALLED_PACKAGES{$pkg}->{'v'}-$INSTALLED_PACKAGES{$pkg}->{'r'})\n" if (!$DEBUG);
177     print "\t$UPDATES_NOARCH{$pkg}->{'URL'}\n";
178     } else {
179     print "\t$pkg is up to date with latest available update\n" if ($DEBUG);
180     }
181     }
182     }

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.22