source: lfs-latest-git.php@ 0739fa7

11.0 11.0-rc1 11.0-rc2 11.0-rc3 ml-11.0 multilib trunk xry111/glibc-2.34 xry111/tester-nohack xry111/usr-move
Last change on this file since 0739fa7 was 0739fa7, checked in by Bruce Dubbs <bdubbs@…>, 8 months ago

Update lfs-latest to work with git and send to new server mailing list.

  • Property mode set to 100644
File size: 15.3 KB
Line 
1#! /usr/bin/php
2<?php
3$dirs = array();
4$vers = array();
5
6date_default_timezone_set( "GMT" );
7$date = date( "Y-m-d H:i:s" );
8
9// Special cases
10$exceptions = array();
11//$exceptions[ 'gmp' ] = "UPDIR=/.*(gmp-\d[\d\.-]*\d).*/:DOWNDIR=";
12
13$regex = array();
14//$regex[ 'bzip2' ] = "/^.*current version is ([\d\.]+).*$/";
15$regex[ 'check' ] = "/^.*Check (\d[\d\.]+\d).*$/";
16$regex[ 'intltool' ] = "/^.*Latest version is (\d[\d\.]+\d).*$/";
17$regex[ 'less' ] = "/^.*current released version is less-(\d+).*$/";
18$regex[ 'mpfr' ] = "/^mpfr-([\d\.]+)\.tar.*$/";
19$regex[ 'Python' ] = "/^.*Latest Python 3.*Python (3[\d\.]+\d).*$/";
20$regex[ 'systemd' ] = "/^.*v([\d]+)$/";
21//$regex[ 'sysvinit' ] = "/^.*sysvinit-([\d\.]+)dsf\.tar.*$/";
22$regex[ 'tzdata' ] = "/^.*tzdata([\d]+[a-z]).*$/";
23$regex[ 'xz' ] = "/^.*xz-([\d\.]*\d).*$/";
24$regex[ 'zlib' ] = "/^.*zlib ([\d\.]*\d).*$/";
25
26function find_max( $lines, $regex_match, $regex_replace )
27{
28 $a = array();
29 if ( ! is_array( $lines ) ) return -1;
30
31 foreach ( $lines as $line )
32 {
33 if ( ! preg_match( $regex_match, $line ) ) continue;
34
35 // Isolate the version and put in an array
36 $slice = preg_replace( $regex_replace, "$1", $line );
37 if ( $slice == $line ) continue;
38
39 array_push( $a, $slice );
40 }
41
42 // SORT_NATURAL requires php-5.4.0 or later
43 rsort( $a, SORT_NATURAL ); // Max version is at the top
44 return ( isset( $a[0] ) ) ? $a[0] : -2;
45}
46
47function find_even_max( $lines, $regex_match, $regex_replace )
48{
49 $a = array();
50 foreach ( $lines as $line )
51 {
52 if ( ! preg_match( $regex_match, $line ) ) continue;
53
54 // Isolate the version and put in an array
55 $slice = preg_replace( $regex_replace, "$1", $line );
56
57 if ( "x$slice" == "x$line" ) continue;
58
59 // Skip odd numbered minor versions and minors > 80
60 list( $major, $minor, $rest ) = explode( ".", $slice . ".0" );
61 if ( $minor % 2 == 1 ) continue;
62 if ( $minor > 80 ) continue;
63 array_push( $a, $slice );
64 }
65
66 rsort( $a, SORT_NATURAL ); // Max version is at the top
67 return ( isset( $a[0] ) ) ? $a[0] : -2;
68}
69
70function http_get_file( $url )
71{
72 if ( ! preg_match( "/sourceforge/", $url ) &&
73 ! preg_match( "/psmisc/", $url ) )
74 {
75 exec( "curl --location --silent --max-time 30 $url", $dir );
76
77 $s = implode( "\n", $dir );
78 $dir = strip_tags( $s );
79 return explode( "\n", $dir );
80 }
81 else
82 {
83 exec( "lynx -dump $url 2>/dev/null", $lines );
84 return $lines;
85 }
86}
87
88function max_parent( $dirpath, $prefix )
89{
90 // First, remove a directory
91 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
92 $position = strrpos( $dirpath, "/" );
93 $dirpath = substr ( $dirpath, 0, $position );
94
95 $lines = http_get_file( $dirpath );
96
97 $regex_match = "#${prefix}[\d\.]+/#";
98 $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#";
99 $max = find_max( $lines, $regex_match, $regex_replace );
100
101 return "$dirpath/$max";
102}
103
104function get_packages( $package, $dirpath )
105{
106 global $exceptions;
107 global $regex;
108
109//if ( $package != "psmisc" ) return 0; // debug
110
111if ( $package == "bc" ) $dirpath = "https://github.com/gavinhoward/bc/releases";
112if ( $package == "check" ) $dirpath = "https://github.com/libcheck/check/releases";
113if ( $package == "e2fsprogs" ) $dirpath = "https://sourceforge.net/projects/e2fsprogs/files/e2fsprogs/";
114if ( $package == "expat" ) $dirpath = "http://sourceforge.net/projects/expat/files";
115if ( $package == "elfutils" ) $dirpath = "https://sourceware.org/ftp/elfutils";
116if ( $package == "expect" ) $dirpath = "http://sourceforge.net/projects/expect/files";
117if ( $package == "file" ) $dirpath = "https://github.com/file/file/releases";
118if ( $package == "flex" ) $dirpath = "https://github.com/westes/flex/releases";
119if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" );
120if ( $package == "iana-etc" ) $dirpath = "https://github.com/Mic92/iana-etc/releases";
121if ( $package == "intltool" ) $dirpath = "https://launchpad.net/intltool/trunk";
122if ( $package == "meson" ) $dirpath = "https://github.com/mesonbuild/meson/releases";
123if ( $package == "mpc" ) $dirpath = "https://ftp.gnu.org/gnu/mpc";
124if ( $package == "mpfr" ) $dirpath = "http://mpfr.loria.fr/mpfr-current";
125if ( $package == "ninja" ) $dirpath = "https://github.com/ninja-build/ninja/releases";
126if ( $package == "procps-ng" ) $dirpath = "https://gitlab.com/procps-ng/procps/-/tags";
127if ( $package == "psmisc" ) $dirpath = "https://gitlab.com/psmisc/psmisc/-/tags";
128if ( $package == "Python" ) $dirpath = "https://www.python.org/downloads/source/";
129if ( $package == "shadow" ) $dirpath = "https://github.com/shadow-maint/shadow/releases";
130if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
131if ( $package == "tcl" ) $dirpath = "http://sourceforge.net/projects/tcl/files";
132if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
133if ( $package == "vim" ) $dirpath = "https://github.com/vim/vim/releases";
134if ( $package == "zstd" ) $dirpath = "https://github.com/facebook/zstd/releases";
135//if ( $package == "vim" ) $dirpath = "ftp://ftp.vim.org/pub/vim/unix";
136
137 // Check for ftp
138 if ( preg_match( "/^ftp/", $dirpath ) )
139 {
140 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
141 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
142 $position = strpos( $dirpath, "/" ); // Divide at first slash
143 $server = substr( $dirpath, 0, $position );
144 $path = substr( $dirpath, $position );
145
146 $conn = ftp_connect( $server );
147 ftp_login( $conn, "anonymous", "" );
148
149 // See if we need special handling
150 if ( isset( $exceptions[ $package ] ) )
151 {
152 $specials = explode( ":", $exceptions[ $package ] );
153
154 foreach ( $specials as $i )
155 {
156 list( $op, $regexp ) = explode( "=", $i );
157
158 switch ($op)
159 {
160 case "UPDIR":
161 // Remove last dir from $path
162 $position = strrpos( $path, "/" );
163 $path = substr( $path, 0, $position );
164
165 // Get dir listing
166 $lines = ftp_rawlist ($conn, $path);
167 $max = find_max( $lines, $regexp, $regexp );
168 break;
169
170 case "DOWNDIR":
171 // Append found directory
172 $path .= "/$max";
173 break;
174
175 default:
176 echo "Error in specials array for $package\n";
177 return -5;
178 break;
179 }
180 }
181 }
182
183 $lines = ftp_rawlist ($conn, $path);
184 ftp_close( $conn );
185 }
186 else // http(s)
187 {
188 // Customize http directories as needed
189 if ( $package == "tzdata" )
190 {
191 // Remove two directories
192 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
193 $position = strrpos( $dirpath, "/" );
194 $dirpath = substr ( $dirpath, 0, $position );
195 $position = strrpos( $dirpath, "/" );
196 $dirpath = substr ( $dirpath, 0, $position );
197 }
198
199 $lines = http_get_file( $dirpath );
200 if ( ! is_array( $lines ) ) return -6;
201 } // End fetch
202
203 if ( isset( $regex[ $package ] ) )
204 {
205 // Custom search for latest package name
206 foreach ( $lines as $l )
207 {
208 $ver = preg_replace( $regex[ $package ], "$1", $l );
209 if ( $ver == $l ) continue;
210 return $ver; // Return first match of regex
211 }
212
213 return -7; // This is an error
214 }
215
216 if ( $package == "perl" ) // Custom for perl
217 {
218 $tmp = array();
219
220 foreach ( $lines as $l )
221 {
222 if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this
223 $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l );
224 if ( $ver == $l ) continue;
225 list( $s1, $s2, $rest ) = explode( ".", $ver );
226 if ( $s2 % 2 == 1 ) continue; // Remove odd minor versions
227 array_push( $tmp, $l );
228 }
229
230 $lines = $tmp;
231 }
232
233 if ( $package == "attr" ||
234 $package == "acl" )
235 {
236 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d).tar.*$/" );
237 }
238
239 if ( $package == "e2fsprogs" )
240 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
241
242 if ( $package == "expect" )
243 return find_max( $lines, "/expect/", "/^.*expect(\d[\d\.]+\d).tar.*$/" );
244
245 if ( $package == "elfutils" )
246 return find_max( $lines, "/^\d/", "/^(\d[\d\.]+\d)\/.*$/" );
247
248 if ( $package == "XML-Parser" )
249 {
250 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d).tar.*$/" );
251 # 2.44_01 is a developer release
252 if ( $max == "2.44_01" ) { return "2.44"; }
253 return $max;
254 }
255
256 if ( $package == "tcl" )
257 return find_max( $lines, "/tcl/", "/^.*tcl(\d[\d\.]*\d)-src.*$/" );
258
259 if ( $package == "ninja" )
260 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]*\d).*$/" );
261
262 if ( $package == "gmp" )
263 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
264
265 if ( $package == "dbus" )
266 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
267
268 if ( $package == "file" )
269 {
270 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
271 return str_replace( "_", ".", $max );
272 }
273
274 if ( $package == "procps-ng" )
275 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+)$/" );
276
277 if ( $package == "psmisc" )
278 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+) .*$/" );
279
280 if ( $package == "grub" )
281 return find_max( $lines, "/grub/", "/^.*grub-(\d\..*).tar.xz.*$/" );
282
283 if ( $package == "openssl" )
284 return find_max( $lines, "/openssl/", "/^.*openssl-([\d\.p]*\d.?).tar.*$/" );
285
286 if ( $package == "vim" )
287 return find_max( $lines, "/v\d\./", "/^.*v([\d\.]+).*$/" );
288
289 if ( $package == "zstd" )
290 return find_max( $lines, "/Zstandard v/", "/^.*v([\d\.]+).*$/" );
291
292 // Most packages are in the form $package-n.n.n
293 // Occasionally there are dashes (e.g. 201-1)
294 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" );
295}
296
297function get_current()
298{
299 global $dirs;
300 global $vers;
301
302 // Fetech from git and get wget-list
303 $current = array();
304 #$lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
305 $lfsgit = "git://git.linuxfromscratch.org/lfs.git";
306
307 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
308 $cdir = getcwd();
309 chdir( $tmpdir );
310 #exec ( "svn --quiet export $lfssvn LFS" );
311 exec ( "git clone $lfsgit LFS" );
312
313 # Make version.ent
314 chdir( "$tmpdir/LFS" );
315 exec ( "./git-version.sh" );
316
317 chdir( $cdir );
318
319 $PAGE = "$tmpdir/LFS/chapter03/chapter03.xml";
320 $STYLESHEET = "$tmpdir/LFS/stylesheets/wget-list.xsl";
321
322 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
323 exec( "rm -rf $tmpdir" );
324
325 foreach ( $current as $line )
326 {
327 $file = basename( $line ) . "\n";
328 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
329
330 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
331
332 $file = rtrim( $file );
333 $pkg_pattern = "/(\D*).*/";
334 //$pattern = "/\D*(\d.*\d)\D*/";
335 $pattern = "/\D*(\d.*\d)\D*/";
336
337 if ( preg_match( "/e2fsprogs/", $file ) )
338 {
339 $pattern = "/e2\D*(\d.*\d)\D*/";
340 $pkg_pattern = "/(e2\D*).*/";
341 }
342
343 else if ( preg_match( "/tzdata/", $file ) )
344 {
345 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
346 }
347
348 else if ( preg_match( "/openssl/", $file ) )
349 {
350 $pattern = "/\D*(\d.*\d.*).tar.*$/";
351 }
352
353 else if ( preg_match( "/gmp/", $file ) )
354 {
355 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
356 }
357
358 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
359 else if ( preg_match( "/python/" , $file ) ) continue;
360
361 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
362 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
363
364 // Touch up package names
365 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
366 $pkg_name = trim( $pkg_name, "-" );
367
368 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
369 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
370 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
371
372 $dirs[ $pkg_name ] = dirname( $line );
373 $vers[ $pkg_name ] = $version;
374 }
375}
376
377function mail_to_lfs()
378{
379 global $date;
380 global $vers;
381 global $dirs;
382
383 $to = "lfs-book@lists4.linuxfromscratch.org";
384 $from = "bdubbs@rivendell.linuxfromscratch.org";
385 $subject = "LFS Package Currency Check - $date GMT";
386 $headers = "From: bdubbs@rivendell.linuxfromscratch.org";
387
388 $message = "Package LFS Upstream Flag\n\n";
389
390 foreach ( $dirs as $pkg => $dir )
391 {
392 //if ( $pkg != "gmp" ) continue; //debug
393 $v = get_packages( $pkg, $dir );
394
395 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
396
397 // Pad for output
398 $pad = " ";
399 $p = substr( $pkg . $pad, 0, 15 );
400 $l = substr( $vers[ $pkg ] . $pad, 0, 10 );
401 $c = substr( $v . $pad, 0, 10 );
402
403 $message .= "$p $l $c $flag\n";
404 }
405
406 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
407 //echo $message;
408}
409
410function html()
411{
412
413 global $date;
414 global $vers;
415 global $dirs;
416
417 echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
418 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
419<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
420<head>
421<title>LFS Package Currency Check - $date</title>
422<style type='text/css'>
423h1, h2 {
424 text-align : center;
425}
426
427table {
428 border-width : 1px;
429 border-spacing : 0px;
430 border-style : outset;
431 border-color : gray;
432 border-collapse : separate;
433 background-color: white;
434 margin : 0px auto;
435}
436
437table th {
438 border-width : 1px;
439 padding : 2px;
440 border-style : inset;
441 border-color : gray;
442 background-color: white;
443}
444
445table td {
446 border-width : 1px;
447 padding : 2px;
448 border-style : inset;
449 border-color : gray;
450 background-color: white;
451}
452</style>
453
454</head>
455<body>
456<h1>LFS Package Currency Check</h1>
457<h2>As of $date GMT</h1>
458
459<table>
460<tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
461
462 // Get the latest version of each package
463 foreach ( $dirs as $pkg => $dir )
464 {
465 $v = get_packages( $pkg, $dir );
466 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
467 echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
468 }
469
470 echo "</table>
471</body>
472</html>\n";
473
474}
475
476function write_to_stdout()
477{
478
479 global $date;
480 global $vers;
481 global $dirs;
482
483 echo "
484LFS Package Currency Check
485As of $date GMT
486
487LFS Package LFS Version Latest Flag\n";
488
489 // Get the latest version of each package
490 foreach ( $dirs as $pkg => $dir )
491 {
492 $p_name = sprintf( "%-15s", $pkg ); // package name formatted
493
494 $b_version = $vers[ $pkg ]; // book version
495 $b_string = sprintf( "%-11s", $b_version ); // book version formatted
496
497 $latest = get_packages( $pkg, $dir ); // latest version
498 $l_string = sprintf( "%-6s", $latest ); // latest version formatted
499
500 $flag = ( $b_version != $latest ) ? "*" : "";
501 echo "$p_name $b_string $l_string $flag\n";
502 }
503}
504
505get_current(); // Get what is in the book
506mail_to_lfs();
507//html(); // Write html output
508//write_to_stdout(); // For debugging
509?>
Note: See TracBrowser for help on using the repository browser.