source: lfs-latest-git.php

trunk
Last change on this file was c3a9569, checked in by Bruce Dubbs <bdubbs@…>, 6 weeks ago

Fix currency and cleanup
Fix currency for upstream changes for
Python
psmisc

Add currency for
lz

Remove a lot of old commented code.

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