]>
pere.pagekite.me Git - homepage.git/blob - linux/ftp-upgrade
3 # ftp-upgrade - fetch redhat package manager updates from the network
5 # usage: ftp-upgrade [-n] [-u uname]
7 # -u - specify a username to use - will be prompted for a password
8 # -n - identify packages that are "new" (e.g. not yet installed)
10 # ftp-upgrade queries the set of installed packages on the local machine. It
11 # then connects to the redhat repository of your choice via ftp, examines
12 # the list of available updates there, and informs you of any packages that
13 # have had their patch level increased or version number changed. You can
14 # then choose to have all of the indicated packages downloaded, or
15 # individually select which packages to download. The transferred RPMs are
16 # placed in the current working directory. They can then be installed on
17 # your system by using the command rpm -u <file>, where <file> is one of
18 # the downloaded RPMs.
20 # Note that if there is an update to RPM or GLINT, these should be updated
23 # $Header: /storage/cvsroot/user/www/homepage/linux/ftp-upgrade,v 1.1 2003/06/02 13:01:37 pere Exp $
25 # $Log: ftp-upgrade,v $
26 # Revision 1.1 2003/06/02 13:01:37 pere
27 # Add all my patches to CVS.
29 # Revision 1.10-pr 1998/05/28 10:00:00 pere
30 # Lost of changes. Added handling of many directories, etc.
32 # Revision 1.10 1995/11/27 11:01:33 ahby
33 # Changed default path to be for the 2.1 RPMS directory.
35 # Revision 1.9 1995/11/22 09:38:21 ahby
36 # Removed some debugging code.
38 # Revision 1.8 1995/11/20 19:27:58 ahby
39 # Added ability to get packages that are not yet installed.
41 # Revision 1.7 1995/11/14 21:53:41 ahby
42 # Fixed an erroneously anchored string.
43 # Improved package recognition.
44 # Fixed a stupid array reference (I really am a better programmer
47 # Revision 1.6 1995/11/14 19:09:35 ahby
48 # Added list of mirror sites and username option.
49 # Changed handling on connection error.
51 # Revision 1.5 1995/11/14 15:59:07 ahby
52 # Changed it so if there are no changes it just terminates.
54 # Revision 1.4 1995/11/14 15:51:16 ahby
55 # Cleaned up some comments.
57 # Revision 1.3 1995/11/09 23:15:46 ahby
58 # CHanged revision tracking strategy to be smarter and use associative
59 # array instead of a flat array and a search.
61 # Revision 1.2 1995/11/09 17:27:01 ahby
65 sub get_redhat_version
{
66 my($tmp) = `rpm -q redhat-release`;
67 my($ver) = $tmp =~ m/^.+-([\d\.]+)-\d+/;
71 print "Unable to determine RedHat version. Exiting.\n";
76 sub get_redhat_architecture
{
77 my($tmp) = `uname -m`;
80 if ($tmp =~ m/i?86/) {
88 $version = get_redhat_version
();
89 $arch = get_redhat_architecture
();
90 @rpm_dirs = ("redhat-$version/$arch/RedHat/RPMS",
91 "updates/$version/$arch",
92 "powertools-$version/$arch");
94 # Popular RedHat mirrors sites
95 #$host = "ftp.nvg.unit.no";
96 #$path = "/pub/linux/redhat";
97 $host = "sunsite.uio.no";
98 $path = "/pub/unix/linux/redhat";
99 #$host = "ftp.caldera.com";
100 #$path = "/pub/mirrors/redhat";
101 #$host = "ftp.cc.gatech.edu";
102 #$path = "/pub/linux/distributions/redhat";
103 #$host = "ftp.pht.com";
104 #$path = "/pub/linux/redhat";
105 #$host = "ftp.cms.uncwil.edu";
106 #$path = "/linux/redhat";
107 #$host = "ftp.wilmington.net";
108 #$path = "/linux/redhat";
109 #$host = "ftp.caldera.com";
110 #$path = "/pub/mirrors/redhat";
111 #$host = "ftp.lasermoon.co.uk";
112 #$path = "/pub/distributions/RedHat";
113 #$host = "sunsite.unc.edu";
114 #$path = "/pub/Linux/distributions/redhat";
115 #$host = "sunsite.doc.ic.ac.uk";
116 #$path = "/packages/linux/sunsite.unc-mirror/distributions/redhat";
117 #$host = "ftp.cc.gatech.edu";
118 #$path = "/pub/linux/distributions/redhat";
119 #$host = "uiarchive.cso.uiuc.edu";
120 #$path = "/pub/systems/linux/distributions/redhat";
121 #$host = "ftp.ibp.fr";
122 #$path = "/pub/linux/distributions/redhat";
123 #$host = "ftp.gwdg.de";
124 #$path = "/pub/linux/install/redhat";
125 #$host = "ftp.uoknor.edu";
126 #$path = "/linux/redhat";
127 #$host = "ftp.msu.ru";
128 #$path = "/pub/Linux/RedHat";
129 #$host = "linux.ucs.indiana.edu";
130 #$path = "/pub/linux/redhat";
131 #$host = "ftp.cvut.cz";
132 #$path = "/pub/linux/redhat";
133 #$host = "ftp.ton.tut.fi";
134 #$path = "/pub/Linux/RedHat";
135 #$host = "ftp.funet.fi";
136 #$path = "/pub/Linux/images/RedHat";
139 # Find Net::FTP if it is in an nonstandard place
140 push(@INC, "/store/lib/perl5", "/store/lib/perl5/site_perl" );
142 # Workaround for a bug in early RedHat 5 perl distributions.
143 eval 'require "ftp.pl"; import ftp;';
144 return unless ( $@ );
146 # Make backup include files
147 mkdir "/tmp/perl-fix", 0777;
148 mkdir "/tmp/perl-fix/gnu", 0777;
149 my($tmp) = `echo '1;' > /tmp/perl-fix/gnu/stubs.ph`;
150 $tmp = `echo '1;' > /tmp/perl-fix/stddef.ph`;
151 push(@INC, "/tmp/perl-fix");
154 # compare versions - needs more work
155 # 1.9.1 is newer then 1.9 and 3.19 is newer then 3.2
156 # Return true if v2 is newer then v1
160 ($v1,$r1) = $v1 =~ m/^(.+)-(\d+).+rpm/;
161 ($v2,$r2) = $v2 =~ m/^(.+)-(\d+).+rpm/;
165 my @v1 = split(/\./, $v1);
166 my @v2 = split(/\./, $v2);
167 if ($v1[0] < $v2[0] ||
168 ($v1[0] == $v2[0] && $v1[1] < $v2[1]) ||
169 ($v1[0] == $v2[0] && $v1[1] == $v2[1] && $v1[2] lt $v2[2])) {
170 # print "Comparing $v1 and $v2 - true\n";
173 # print "Comparing $v1 and $v2 - false\n";
184 $uname = "anonymous";
185 $pword = "upgrade-user@";
193 chop($pword = <STDIN
>);
198 # subroutine to get y/n answer
206 print "$prompt (y/n)? ";
208 $a = substr($answer, 0, 1);
209 } while (($a ne "Y") && ($a ne "y") && ($a ne "N") && ($a ne "n"));
210 return (($a eq "Y") || ($a eq "y"));
214 # get the local list of installed packages
216 print "Getting list of installed packages\n";
221 # now connect to the remote host
223 print ("Getting the list of updated packages from $host.\n");
225 # make the connection and fetch the directory
227 print "Opening connection to $host\n";
229 # XXX $ftp = Net::FTP->new($host, Timeout => '30');
230 ftp
::set_timeout
(30);
231 $ftp = ftp
::open($host,21,0,10);
234 die("open of $host failed");
236 print "Logging in to $host as $uname\n";
238 # XXX $ftp->login($uname,$pword) || die("login failed");
239 ftp
::login
($uname,$pword) || die("login failed");
241 for $dir (@rpm_dirs) {
242 fetch_subdir_list
($dir);
246 # Exports: @templist, %rlist
247 sub fetch_subdir_list
{
249 my($curpath) = $path . "/" . $dir;
251 print "Changing to directory $curpath on $host\n";
253 # XXX $ftp->cwd($curpath);
254 if ( ! ftp
::cwd
($curpath) ) {
258 print "Fetching directory list\n";
260 # XXX my(@longlist) = $ftp->ls();
262 @longlist = <ftp
::NS
>;
265 push(@templist, grep(/\.rpm/, @longlist));
273 @temp = m/([^ ]*)-([^- ]*-[0-9]*[^ ]*rpm).*/;
274 ($file) = m/(\S+rpm)/;
275 # Only add newer package
276 if ( (! $rlist{$temp[0]} ) ||
277 ($rlist{$temp[0]} && version_newer
($rlist{$temp[0]},$temp[1])) ) {
278 $rlist{$temp[0]} = $temp[1];
279 $directory{$file} = $curpath;
284 # XXX $ftp->type("I");
287 # XXX $ftp->debug(1);
290 if ($opt_n) { # if we are looking for new packages
293 @temp = m/([^ ]*)-([^-]*-[0-9]*)/;
294 $ilist{$temp[0]} = $temp[1];
297 $uindex = 0; #initialize index for uninstalled package array
301 $fname =~ s/.*\s([^ ]*rpm).*/$1/;
302 @pname = ($fname =~ m/^(.*)-([^-]*)-([0-9]*)/);
303 if (! $ilist{$pname[0]}) { # if this not package already installed
304 @ulist[$uindex] = $fname;
308 @ulist = sort(@ulist);
310 print "Uninstalled packages:\n";
314 $all = getyn
("Fetch all?");
318 if (!getyn
("Fetch $_")) { next };
323 print ("No new packages are available on $host\n");
326 } else { # check for updated packages
328 $nindex = 0; #initialize index for new version array
329 $cindex = 0; #initialize index for changed patch array
332 @lname = m/^(.*)-([^-]*)-([0-9]*$)/;
333 if ($rlist{$lname[0]}) { # if this package has an update
334 @temp = ($rlist{$lname[0]} =~ m/([^-]*)-([0-9]*).*rpm/);
335 if ($lname[1] eq $temp[0]) { # if versions equal
336 if ($lname[2] < $temp[1]) { # if patch level has increased
337 @clist[$cindex] = $lname[0] . '-' . $rlist{$lname[0]};
340 } else { # if different version
341 if (version_newer
($lname[1], $temp[0])) {
342 @nlist[$nindex] = $lname[0] . '-' . $rlist{$lname[0]};
348 if (@clist || @nlist) {
349 @clist = sort(@clist);
350 @nlist = sort(@nlist);
351 print "New patches:\n\n";
355 print "\nDifferent versions:\n\n";
360 $all = getyn
("Fetch all?");
364 if (!getyn
("Fetch $_")) { next };
370 if (!getyn
("Fetch $_")) { next };
374 print "\nTo upgrade, run 'rpm -Uvh *.rpm' as root.\n"
376 print ("No new updates are available on $host\n");
386 my($ftphandle, $filename) = @_;
387 my($dir) = $directory{$filename};
388 print "Fetching $dir/$filename\n";
389 # XXX $ftphandle->cwd($dir);
392 # XXX $ftphandle->get($filename);