coreutils: Add -k for make check
[lfs.git] / lfs-latest-git.php
blob95abb7c28d5ec3a4abf24262272e54ba87a5f622
1 #! /usr/bin/php
2 <?php
3 $dirs = array();
4 $vers = array();
6 date_default_timezone_set( "GMT" );
7 $date = date( "Y-m-d H:i:s" );
9 // Special cases
10 $exceptions = array();
11 //$exceptions[ 'gmp' ] = "UPDIR=/.*(gmp-\d[\d\.-]*\d).*/:DOWNDIR=";
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).*$/";
24 function find_max( $lines, $regex_match, $regex_replace )
26 $a = array();
27 if ( ! is_array( $lines ) ) return -1;
29 foreach ( $lines as $line )
31 if ( ! preg_match( $regex_match, $line ) ) continue;
33 // Isolate the version and put in an array
34 $slice = preg_replace( $regex_replace, "$1", $line );
35 if ( strcmp( $slice, $line ) == 0 ) continue;
37 array_push( $a, $slice );
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;
45 function find_even_max( $lines, $regex_match, $regex_replace )
47 $a = array();
48 foreach ( $lines as $line )
50 if ( ! preg_match( $regex_match, $line ) ) continue;
52 // Isolate the version and put in an array
53 $slice = preg_replace( $regex_replace, "$1", $line );
55 if ( "x$slice" == "x$line" ) continue;
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 );
64 rsort( $a, SORT_NATURAL ); // Max version is at the top
65 return ( isset( $a[0] ) ) ? $a[0] : -2;
68 function http_get_file( $url )
70 if ( preg_match( "/mpfr/", $url ) )
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 );
79 if ( preg_match( "/sourceforge/", $url ) ||
80 preg_match( "/python/", $url ) ||
81 preg_match( "/psmisc/", $url ) )
83 exec( "lynx -dump $url 2>/dev/null", $lines );
84 return $lines;
87 exec( "curl --location --silent --max-time 30 $url", $dir );
89 $dir = implode( "\n", $dir );
90 if ( !preg_match( "/api.github.com/", $url) )
91 $dir = strip_tags( $dir );
92 return explode( "\n", $dir );
95 function max_parent( $dirpath, $prefix )
97 // First, remove a directory
98 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
99 $position = strrpos( $dirpath, "/" );
100 $dirpath = substr ( $dirpath, 0, $position );
102 $lines = http_get_file( $dirpath );
104 $regex_match = "#{$prefix}[\d\.]+/#";
105 $regex_replace = "#^.*({$prefix}[\d\.]+)/.*$#";
106 $max = find_max( $lines, $regex_match, $regex_replace );
108 return "$dirpath/$max";
111 function github( $path )
113 return "https://api.github.com/repos/$path/releases/latest";
116 function get_packages( $package, $dirpath )
118 global $exceptions;
119 global $regex;
121 //if ( $package != "psmisc" ) return 0; // debug
123 if ( $package == "bc" ) $dirpath = github("gavinhoward/bc");
124 if ( $package == "check" ) $dirpath = github("libcheck/check");
125 if ( $package == "e2fsprogs" ) $dirpath = "https://sourceforge.net/projects/e2fsprogs/files/e2fsprogs";
126 if ( $package == "expat" ) $dirpath = "https://sourceforge.net/projects/expat/files";
127 if ( $package == "elfutils" ) $dirpath = "https://sourceware.org/ftp/elfutils";
128 if ( $package == "expect" ) $dirpath = "https://sourceforge.net/projects/expect/files";
129 if ( $package == "file" ) $dirpath = "https://github.com/file/file/tags";
130 if ( $package == "flex" ) $dirpath = github("westes/flex");
131 if ( $package == "flit_core" ) $dirpath = "https://pypi.org/project/flit-core/";
132 if ( $package == "setuptools" ) $dirpath = "https://pypi.org/project/setuptools/";
133 if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" );
134 if ( $package == "iana-etc" ) $dirpath = github("Mic92/iana-etc");
135 if ( $package == "intltool" ) $dirpath = "https://launchpad.net/intltool/trunk";
136 if ( $package == "libffi" ) $dirpath = github("libffi/libffi");
137 if ( $package == "libxcrypt" ) $dirpath = github("besser82/libxcrypt");
138 if ( $package == "lz" ) $dirpath = github("lz4/lz4");
139 if ( $package == "meson" ) $dirpath = github("mesonbuild/meson");
140 if ( $package == "mpc" ) $dirpath = "https://ftp.gnu.org/gnu/mpc";
141 if ( $package == "mpfr" ) $dirpath = "https://mpfr.loria.fr/mpfr-current";
142 if ( $package == "ncurses" ) $dirpath = "https://invisible-mirror.net/archives/ncurses";
143 if ( $package == "ninja" ) $dirpath = github("ninja-build/ninja");
144 if ( $package == "procps-ng" ) $dirpath = "https://gitlab.com/procps-ng/procps/-/tags";
145 if ( $package == "psmisc" ) $dirpath = "https://gitlab.com/psmisc/psmisc/-/tags";
146 if ( $package == "Python" ) $dirpath = "https://www.python.org/downloads/source/";
147 if ( $package == "shadow" ) $dirpath = github("shadow-maint/shadow");
148 if ( $package == "sysvinit" ) $dirpath = github("slicer69/sysvinit");
149 if ( $package == "MarkupSafe" ) $dirpath = "https://pypi.python.org/pypi/MarkupSafe/";
150 if ( $package == "Jinja" ) $dirpath = "https://pypi.python.org/pypi/Jinja2/";
151 if ( $package == "systemd" ) $dirpath = github("systemd/systemd");
152 //if ( $package == "tcl" ) $dirpath = "https://sourceforge.net/projects/tcl/files";
153 if ( $package == "tcl" ) $dirpath = "https://www.tcl.tk/software/tcltk/download.html";
154 if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
155 if ( $package == "vim" ) $dirpath = "https://github.com/vim/vim/tags";
156 if ( $package == "wheel" ) $dirpath = "https://pypi.org/project/wheel/#files";
157 if ( $package == "xz" ) $dirpath = github("tukaani-project/xz");
158 if ( $package == "zlib" ) $dirpath = "https://www.zlib.net";
159 if ( $package == "zstd" ) $dirpath = github("facebook/zstd");
161 // Check for ftp
162 if ( preg_match( "/^ftp/", $dirpath ) )
164 echo "ftp should not occur\n";
166 else // http(s)
168 // Customize http directories as needed
169 if ( $package == "tzdata" )
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 );
179 $lines = http_get_file( $dirpath );
180 if ( ! is_array( $lines ) ) return -6;
181 } // End fetch
183 if ( isset( $regex[ $package ] ) )
185 // Custom search for latest package name
186 foreach ( $lines as $l )
188 $ver = preg_replace( $regex[ $package ], "$1", $l );
189 if ( $ver == $l ) continue;
190 return $ver; // Return first match of regex
193 return -7; // This is an error
196 if ( $package == "perl" ) // Custom for perl
198 $tmp = array();
200 foreach ( $lines as $l )
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 );
210 $lines = $tmp;
213 if ( $package == "attr" ||
214 $package == "acl" )
216 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d).tar.*$/" );
219 if ( $package == "e2fsprogs" )
220 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
222 if ( $package == "expect" )
223 return find_max( $lines, "/expect/", "/^.*expect(\d[\d\.]+\d).tar.*$/" );
225 if ( $package == "elfutils" )
226 return find_max( $lines, "/^\d/", "/^(\d[\d\.]+\d)\/.*$/" );
228 if ( $package == "XML-Parser" )
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;
236 if ( $package == "tcl" )
237 return find_max( $lines, "/tcl\d/", "/^.*tcl(\d\.[\d\.]*\d)-src.*$/" );
239 if ( $package == "gmp" )
240 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
242 if ( $package == "dbus" )
243 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
245 if ( $package == "file" )
247 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
248 return str_replace( "_", ".", $max );
251 if ( $package == "flit_core" )
252 return find_max( $lines, "/flit-core /", "/^.*flit-core ([\d\.]+)$/" );
254 if ( $package == "setuptools" )
255 return find_max( $lines, "/setuptools /", "/^.*setuptools ([\d\.]+)$/" );
257 if ( $package == "procps-ng" )
258 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+)$/" );
260 if ( $package == "psmisc" )
261 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+)$/" );
263 if ( $package == "grub" )
264 return find_max( $lines, "/grub/", "/^.*grub-([\d\.]+).tar.xz.*$/" );
266 if ( $package == "Jinja" )
267 return find_max( $lines, "/Jinja/", "/^.*Jinja2 ([\d\.]+).*$/" );
269 if ( $package == "lz" )
270 return find_max( $lines, "/name.:/", '/^.*LZ4 v([\d\.]+)".*$/' );
272 if ( $package == "openssl" )
273 return find_max( $lines, "/openssl/", "/^.*openssl-([\d\.p]*\d.?).tar.*$/" );
275 if ( $package == "Python" )
276 return find_max( $lines, "/Python 3/", "/^.*Python (3[\d\.]*\d) .*$/" );
278 if ( $package == "vim" )
279 return find_max( $lines, "/v\d\./", "/^.*v([\d\.]+).*$/" );
281 if ( preg_match( "/api.github.com/", $dirpath) )
282 return ltrim(json_decode(join("", $lines))->tag_name, "v");
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.*$/" );
289 function get_current()
291 global $dirs;
292 global $vers;
294 // Fetech from git and get wget-list
295 $current = array();
296 $lfsgit = "https://git.linuxfromscratch.org/lfs.git";
298 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
299 $cdir = getcwd();
300 chdir( $tmpdir );
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" );
306 # Make version.ent
307 chdir( "$tmpdir/LFS" );
308 exec ( "./git-version.sh systemd" );
310 chdir( $cdir );
312 $PAGE = "$tmpdir/LFS/chapter03/chapter03.xml";
313 $STYLESHEET = "$tmpdir/LFS/stylesheets/wget-list.xsl";
315 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
316 exec( "rm -rf $tmpdir" );
318 foreach ( $current as $line )
320 $file = basename( $line ) . "\n";
321 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
323 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
325 $file = rtrim( $file );
326 $pkg_pattern = "/(\D*).*/";
327 $pattern = "/\D*(\d.*\d)\D*/";
329 if ( preg_match( "/e2fsprogs/", $file ) )
331 $pattern = "/e2\D*(\d.*\d)\D*/";
332 $pkg_pattern = "/(e2\D*).*/";
335 else if ( preg_match( "/tzdata/", $file ) )
337 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
340 else if ( preg_match( "/openssl/", $file ) )
342 $pattern = "/\D*(\d.*\d.*).tar.*$/";
345 else if ( preg_match( "/gmp/", $file ) )
347 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
350 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
351 else if ( preg_match( "/python/" , $file ) ) continue;
353 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
354 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
356 // Touch up package names
357 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
358 $pkg_name = trim( $pkg_name, "-" );
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"; }
364 $dirs[ $pkg_name ] = dirname( $line );
365 $vers[ $pkg_name ] = $version;
369 function mail_to_lfs()
371 global $date;
372 global $vers;
373 global $dirs;
375 $to = "lfs-book@lists.linuxfromscratch.org";
376 $from = "bdubbs@linuxfromscratch.org";
377 $subject = "LFS Package Currency Check - $date GMT";
378 $headers = "From: bdubbs@linuxfromscratch.org";
380 $message = "Package LFS Upstream Flag\n\n";
382 foreach ( $dirs as $pkg => $dir )
384 //if ( $pkg != "gmp" ) continue; //debug
385 $v = get_packages( $pkg, $dir );
387 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
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 );
395 $message .= "$p $l $c $flag\n";
398 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
401 function html()
404 global $date;
405 global $vers;
406 global $dirs;
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'>
414 h1, h2 {
415 text-align : center;
418 table {
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;
428 table th {
429 border-width : 1px;
430 padding : 2px;
431 border-style : inset;
432 border-color : gray;
433 background-color: white;
436 table td {
437 border-width : 1px;
438 padding : 2px;
439 border-style : inset;
440 border-color : gray;
441 background-color: white;
443 </style>
445 </head>
446 <body>
447 <h1>LFS Package Currency Check</h1>
448 <h2>As of $date GMT</h1>
450 <table>
451 <tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
453 // Get the latest version of each package
454 foreach ( $dirs as $pkg => $dir )
456 $v = get_packages( $pkg, $dir );
457 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
458 echo "<tr><td>$pkg</td> <td>{$vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
461 echo "</table>
462 </body>
463 </html>\n";
467 function write_to_stdout()
470 global $date;
471 global $vers;
472 global $dirs;
474 echo "
475 LFS Package Currency Check
476 As of $date GMT
478 LFS Package LFS Version Latest Flag\n";
480 // Get the latest version of each package
481 foreach ( $dirs as $pkg => $dir )
483 $p_name = sprintf( "%-15s", $pkg ); // package name formatted
485 $b_version = $vers[ $pkg ]; // book version
486 $b_string = sprintf( "%-11s", $b_version ); // book version formatted
488 $latest = get_packages( $pkg, $dir ); // latest version
489 $l_string = sprintf( "%-6s", $latest ); // latest version formatted
491 $flag = ( $b_version != $latest ) ? "*" : "";
492 echo "$p_name $b_string $l_string $flag\n";
496 get_current(); // Get what is in the book
497 mail_to_lfs();
498 //html(); // Write html output
499 //write_to_stdout(); // For debugging