source: lfs-latest-git.php@ acaeb102

multilib trunk xry111/loongarch
Last change on this file since acaeb102 was e31b6c5, checked in by Bruce Dubbs <bdubbs@…>, 6 weeks ago

Fix Python currency

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