source: lfs-latest-git.php@ 7c8e399

11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since 7c8e399 was 7c8e399, checked in by Bruce Dubbs <bdubbs@…>, 2 years ago

Fix 'file' currency

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