6 date_default_timezone_set( "GMT" );
7 $date = date( "Y-m-d H:i:s" );
10 $exceptions = array();
11 //$exceptions[ 'gmp' ] = "UPDIR=/.*(gmp-\d[\d\.-]*\d).*/:DOWNDIR=";
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).*$/";
26 function find_max( $lines, $regex_match, $regex_replace )
29 if ( ! is_array( $lines ) ) return -1;
31 foreach ( $lines as $line )
33 if ( ! preg_match( $regex_match, $line ) ) continue;
35 // Isolate the version and put in an array
36 $slice = preg_replace( $regex_replace, "$1", $line );
37 if ( $slice == $line ) continue;
39 array_push( $a, $slice );
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;
47 function find_even_max( $lines, $regex_match, $regex_replace )
50 foreach ( $lines as $line )
52 if ( ! preg_match( $regex_match, $line ) ) continue;
54 // Isolate the version and put in an array
55 $slice = preg_replace( $regex_replace, "$1", $line );
57 if ( "x$slice" == "x$line" ) continue;
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 );
66 rsort( $a, SORT_NATURAL
); // Max version is at the top
67 return ( isset( $a[0] ) ) ?
$a[0] : -2;
70 function http_get_file( $url )
72 if ( ! preg_match( "/sourceforge/", $url ) )
74 exec( "curl --location --silent --max-time 30 $url", $dir );
76 $s = implode( "\n", $dir );
77 $dir = strip_tags( $s );
78 return explode( "\n", $dir );
82 exec( "links -dump $url 2>/dev/null", $lines );
87 function max_parent( $dirpath, $prefix )
89 // First, remove a directory
90 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
91 $position = strrpos( $dirpath, "/" );
92 $dirpath = substr ( $dirpath, 0, $position );
94 $lines = http_get_file( $dirpath );
96 $regex_match = "#${prefix}[\d\.]+/#";
97 $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#";
98 $max = find_max( $lines, $regex_match, $regex_replace );
100 return "$dirpath/$max";
103 function get_packages( $package, $dirpath )
108 //if ( $package != "zstd" ) return 0; // Debug
110 if ( $package == "bc" ) $dirpath = "https://github.com/gavinhoward/bc/releases";
111 if ( $package == "check" ) $dirpath = "https://github.com/libcheck/check/releases";
112 if ( $package == "e2fsprogs" ) $dirpath = "http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs";
113 if ( $package == "expat" ) $dirpath = "http://sourceforge.net/projects/expat/files";
114 if ( $package == "elfutils" ) $dirpath = "https://sourceware.org/ftp/elfutils";
115 if ( $package == "expect" ) $dirpath = "http://sourceforge.net/projects/expect/files";
116 if ( $package == "file" ) $dirpath = "https://github.com/file/file/releases";
117 if ( $package == "flex" ) $dirpath = "https://github.com/westes/flex/releases";
118 if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" );
119 if ( $package == "iana-etc" ) $dirpath = "https://github.com/Mic92/iana-etc/releases";
120 if ( $package == "intltool" ) $dirpath = "https://launchpad.net/intltool/trunk";
121 if ( $package == "meson" ) $dirpath = "https://github.com/mesonbuild/meson/releases";
122 if ( $package == "mpc" ) $dirpath = "https://ftp.gnu.org/gnu/mpc";
123 if ( $package == "mpfr" ) $dirpath = "http://mpfr.loria.fr/mpfr-current";
124 if ( $package == "ninja" ) $dirpath = "https://github.com/ninja-build/ninja/releases";
125 //if ( $package == "procps-ng" ) $dirpath = "http://sourceforge.net/projects/procps-ng/files";
126 if ( $package == "procps-ng" ) $dirpath = "https://gitlab.com/procps-ng/procps/-/tags";
127 //if ( $package == "psmisc" ) $dirpath = "http://sourceforge.net/projects/$package/files";
128 if ( $package == "psmisc" ) $dirpath = "https://gitlab.com/psmisc/psmisc/-/tags";
129 if ( $package == "Python" ) $dirpath = "https://www.python.org/downloads/source/";
130 if ( $package == "shadow" ) $dirpath = "https://github.com/shadow-maint/shadow/releases";
131 if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
132 if ( $package == "tcl" ) $dirpath = "http://sourceforge.net/projects/tcl/files";
133 if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
134 if ( $package == "vim" ) $dirpath = "https://github.com/vim/vim/releases";
135 if ( $package == "zstd" ) $dirpath = "https://github.com/facebook/zstd/releases";
136 //if ( $package == "vim" ) $dirpath = "ftp://ftp.vim.org/pub/vim/unix";
139 if ( preg_match( "/^ftp/", $dirpath ) )
141 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
142 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
143 $position = strpos( $dirpath, "/" ); // Divide at first slash
144 $server = substr( $dirpath, 0, $position );
145 $path = substr( $dirpath, $position );
147 $conn = ftp_connect( $server );
148 ftp_login( $conn, "anonymous", "" );
150 // See if we need special handling
151 if ( isset( $exceptions[ $package ] ) )
153 $specials = explode( ":", $exceptions[ $package ] );
155 foreach ( $specials as $i )
157 list( $op, $regexp ) = explode( "=", $i );
162 // Remove last dir from $path
163 $position = strrpos( $path, "/" );
164 $path = substr( $path, 0, $position );
167 $lines = ftp_rawlist ($conn, $path);
168 $max = find_max( $lines, $regexp, $regexp );
172 // Append found directory
177 echo "Error in specials array for $package\n";
184 $lines = ftp_rawlist ($conn, $path);
189 // Customize http directories as needed
190 if ( $package == "tzdata" )
192 // Remove two directories
193 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
194 $position = strrpos( $dirpath, "/" );
195 $dirpath = substr ( $dirpath, 0, $position );
196 $position = strrpos( $dirpath, "/" );
197 $dirpath = substr ( $dirpath, 0, $position );
200 //if ( $package == "bzip2" )
202 // // Remove one directory
203 // $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
204 // $position = strrpos( $dirpath, "/" );
205 // $dirpath = substr ( $dirpath, 0, $position );
208 $lines = http_get_file( $dirpath );
209 if ( ! is_array( $lines ) ) return -6;
212 if ( isset( $regex[ $package ] ) )
214 // Custom search for latest package name
215 foreach ( $lines as $l )
217 $ver = preg_replace( $regex[ $package ], "$1", $l );
218 if ( $ver == $l ) continue;
219 return $ver; // Return first match of regex
222 return -7; // This is an error
225 if ( $package == "perl" ) // Custom for perl
229 foreach ( $lines as $l )
231 if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this
232 $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l );
233 if ( $ver == $l ) continue;
234 list( $s1, $s2, $rest ) = explode( ".", $ver );
235 if ( $s2 %
2 == 1 ) continue; // Remove odd minor versions
236 array_push( $tmp, $l );
242 if ( $package == "attr" ||
245 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d).tar.*$/" );
248 if ( $package == "e2fsprogs" )
249 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
251 if ( $package == "expect" )
252 return find_max( $lines, "/expect/", "/^.*expect(\d[\d\.]+\d).tar.*$/" );
254 if ( $package == "elfutils" )
255 return find_max( $lines, "/^\d/", "/^(\d[\d\.]+\d)\/.*$/" );
257 if ( $package == "XML-Parser" )
259 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d).tar.*$/" );
260 # 2.44_01 is a developer release
261 if ( $max == "2.44_01" ) { return "2.44"; }
265 if ( $package == "tcl" )
266 return find_max( $lines, "/tcl/", "/^.*tcl(\d[\d\.]*\d)-src.*$/" );
268 if ( $package == "ninja" )
269 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]*\d).*$/" );
271 if ( $package == "gmp" )
272 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
274 if ( $package == "dbus" )
275 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
277 if ( $package == "file" )
279 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
280 return str_replace( "_", ".", $max );
283 if ( $package == "procps-ng" )
284 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+).*$/" );
286 if ( $package == "psmisc" )
287 return find_max( $lines, "/^v/", "/^v([\d\.]+).*$/" );
289 if ( $package == "grub" )
290 return find_max( $lines, "/grub/", "/^.*grub-(\d\..*).tar.xz.*$/" );
292 if ( $package == "openssl" )
293 return find_max( $lines, "/openssl/", "/^.*openssl-([\d\.p]*\d.?).tar.*$/" );
295 if ( $package == "vim" )
296 return find_max( $lines, "/v\d\./", "/^.*v([\d\.]+).*$/" );
298 if ( $package == "zstd" )
299 return find_max( $lines, "/Zstandard v/", "/^.*v([\d\.]+).*$/" );
301 // Most packages are in the form $package-n.n.n
302 // Occasionally there are dashes (e.g. 201-1)
303 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" );
306 function get_current()
311 // Fetech from svn and get wget-list
313 $lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
315 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
318 exec ( "svn --quiet export $lfssvn LFS" );
321 $PAGE = "$tmpdir/LFS/BOOK/chapter03/chapter03.xml";
322 $STYLESHEET = "$tmpdir/LFS/BOOK/stylesheets/wget-list.xsl";
324 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
325 exec( "rm -rf $tmpdir" );
327 foreach ( $current as $line )
329 $file = basename( $line ) . "\n";
330 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
332 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
334 $file = rtrim( $file );
335 $pkg_pattern = "/(\D*).*/";
336 //$pattern = "/\D*(\d.*\d)\D*/";
337 $pattern = "/\D*(\d.*\d)\D*/";
339 if ( preg_match( "/e2fsprogs/", $file ) )
341 $pattern = "/e2\D*(\d.*\d)\D*/";
342 $pkg_pattern = "/(e2\D*).*/";
345 else if ( preg_match( "/tzdata/", $file ) )
347 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
350 else if ( preg_match( "/openssl/", $file ) )
352 $pattern = "/\D*(\d.*\d.*).tar.*$/";
355 else if ( preg_match( "/gmp/", $file ) )
357 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
360 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
361 else if ( preg_match( "/python/" , $file ) ) continue;
363 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
364 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
366 // Touch up package names
367 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
368 $pkg_name = trim( $pkg_name, "-" );
370 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
371 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
372 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
374 $dirs[ $pkg_name ] = dirname( $line );
375 $vers[ $pkg_name ] = $version;
379 function mail_to_lfs()
385 //$to = "bruce.dubbs@gmail.com";
386 $to = "lfs-book@lists.linuxfromscratch.org";
387 $from = "bdubbs@linuxfromscratch.org";
388 $subject = "LFS Package Currency Check - $date GMT";
389 $headers = "From: bdubbs@anduin.linuxfromscratch.org";
391 $message = "Package LFS Upstream Flag\n\n";
393 foreach ( $dirs as $pkg => $dir )
395 //if ( $pkg != "gmp" ) continue; //debug
396 $v = get_packages( $pkg, $dir );
398 $flag = ( $vers[ $pkg ] != $v ) ?
"*" : "";
402 $p = substr( $pkg . $pad, 0, 15 );
403 $l = substr( $vers[ $pkg ] . $pad, 0, 10 );
404 $c = substr( $v . $pad, 0, 10 );
406 $message .= "$p $l $c $flag\n";
409 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
420 echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
421 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
422 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
424 <title>LFS Package Currency Check - $date</title>
425 <style type='text/css'>
432 border-spacing : 0px;
433 border-style : outset;
435 border-collapse : separate;
436 background-color: white;
443 border-style : inset;
445 background-color: white;
451 border-style : inset;
453 background-color: white;
459 <h1>LFS Package Currency Check</h1>
460 <h2>As of $date GMT</h1>
463 <tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
465 // Get the latest version of each package
466 foreach ( $dirs as $pkg => $dir )
468 $v = get_packages( $pkg, $dir );
469 $flag = ( $vers[ $pkg ] != $v ) ?
"*" : "";
470 echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
479 get_current(); // Get what is in the book
481 //html(); // Write html output