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[ 'expect' ] = "/^.*Download expect([\d\.]+)\.tar.*$/";
17 $regex[ 'expat' ] = "/^.*Download expat-([\d\.]+)\.tar.*$/";
18 $regex[ 'intltool' ] = "/^.*Latest version is (\d[\d\.]+\d).*$/";
19 $regex[ 'less' ] = "/^.*current released version is less-(\d+).*$/";
20 $regex[ 'mpc' ] = "/^(\d\.\d\.\d).*$/";
21 $regex[ 'mpfr' ] = "/^mpfr-([\d\.]+)\.tar.*$/";
22 $regex[ 'systemd' ] = "/^.*v([\d]+).*$/";
23 $regex[ 'sysvinit' ] = "/^.*sysvinit-([\d\.]+)dsf\.tar.*$/";
24 $regex[ 'tcl-core' ] = "/^.*Download tcl([\d\.]+)-src.*$/";
25 $regex[ 'tzdata' ] = "/^.*tzdata([\d]+[a-z]).*$/";
26 $regex[ 'xz' ] = "/^.*xz-([\d\.]*\d).*$/";
27 $regex[ 'zlib' ] = "/^.*zlib ([\d\.]*\d).*$/";
29 function find_max( $lines, $regex_match, $regex_replace )
32 if ( ! is_array( $lines ) ) return -1;
34 foreach ( $lines as $line )
36 if ( ! preg_match( $regex_match, $line ) ) continue;
38 // Isolate the version and put in an array
39 $slice = preg_replace( $regex_replace, "$1", $line );
40 if ( $slice == $line ) continue;
42 array_push( $a, $slice );
45 // SORT_NATURAL requires php-5.4.0 or later
46 rsort( $a, SORT_NATURAL
); // Max version is at the top
47 return ( isset( $a[0] ) ) ?
$a[0] : -2;
50 function find_even_max( $lines, $regex_match, $regex_replace )
53 foreach ( $lines as $line )
55 if ( ! preg_match( $regex_match, $line ) ) continue;
57 // Isolate the version and put in an array
58 $slice = preg_replace( $regex_replace, "$1", $line );
60 if ( "x$slice" == "x$line" ) continue;
62 // Skip odd numbered minor versions and minors > 80
63 list( $major, $minor, $rest ) = explode( ".", $slice . ".0" );
64 if ( $minor %
2 == 1 ) continue;
65 if ( $minor > 80 ) continue;
66 array_push( $a, $slice );
69 rsort( $a, SORT_NATURAL
); // Max version is at the top
70 return ( isset( $a[0] ) ) ?
$a[0] : -2;
73 function http_get_file( $url )
75 if ( ! preg_match( "/sourceforge/", $url ) )
77 exec( "curl --location --silent --max-time 30 $url", $dir );
79 $s = implode( "\n", $dir );
80 $dir = strip_tags( $s );
81 return explode( "\n", $dir );
85 exec( "elinks -dump $url 2>/dev/null", $lines );
90 function max_parent( $dirpath, $prefix )
92 // First, remove a directory
93 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
94 $position = strrpos( $dirpath, "/" );
95 $dirpath = substr ( $dirpath, 0, $position );
97 $lines = http_get_file( $dirpath );
99 $regex_match = "#${prefix}[\d\.]+/#";
100 $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#";
101 $max = find_max( $lines, $regex_match, $regex_replace );
103 return "$dirpath/$max";
106 function get_packages( $package, $dirpath )
111 //if ( $package != "check" ) return 0; // Debug
113 if ( $package == "check" ) $dirpath = "https://github.com/libcheck/check/releases";
114 if ( $package == "e2fsprogs" ) $dirpath = "http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs";
115 if ( $package == "expat" ) $dirpath = "http://sourceforge.net/projects/expat/files";
116 if ( $package == "expect" ) $dirpath = "http://sourceforge.net/projects/$package/files";
117 if ( $package == "file" ) $dirpath = "https://github.com/file/file/releases";
118 if ( $package == "flex" ) $dirpath = "https://github.com/westes/flex/releases";
119 if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" );
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 = "http://www.multiprecision.org/index.php?prog=mpc&page=download";
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 == "psmisc" ) $dirpath = "http://sourceforge.net/projects/$package/files";
127 if ( $package == "shadow" ) $dirpath = "https://github.com/shadow-maint/shadow/releases";
128 if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
129 if ( $package == "tcl-core" ) $dirpath = "http://sourceforge.net/projects/tcl/files";
130 if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
131 if ( $package == "vim" ) $dirpath = "ftp://ftp.vim.org/pub/vim/unix";
134 if ( preg_match( "/^ftp/", $dirpath ) )
136 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
137 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
138 $position = strpos( $dirpath, "/" ); // Divide at first slash
139 $server = substr( $dirpath, 0, $position );
140 $path = substr( $dirpath, $position );
142 $conn = ftp_connect( $server );
143 ftp_login( $conn, "anonymous", "" );
145 // See if we need special handling
146 if ( isset( $exceptions[ $package ] ) )
148 $specials = explode( ":", $exceptions[ $package ] );
150 foreach ( $specials as $i )
152 list( $op, $regexp ) = explode( "=", $i );
157 // Remove last dir from $path
158 $position = strrpos( $path, "/" );
159 $path = substr( $path, 0, $position );
162 $lines = ftp_rawlist ($conn, $path);
163 $max = find_max( $lines, $regexp, $regexp );
167 // Append found directory
172 echo "Error in specials array for $package\n";
179 $lines = ftp_rawlist ($conn, $path);
184 // Customize http directories as needed
185 if ( $package == "tzdata" )
187 // Remove two directories
188 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
189 $position = strrpos( $dirpath, "/" );
190 $dirpath = substr ( $dirpath, 0, $position );
191 $position = strrpos( $dirpath, "/" );
192 $dirpath = substr ( $dirpath, 0, $position );
195 if ( $package == "bzip2" )
197 // Remove one directory
198 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
199 $position = strrpos( $dirpath, "/" );
200 $dirpath = substr ( $dirpath, 0, $position );
204 $lines = http_get_file( $dirpath );
205 if ( ! is_array( $lines ) ) return -6;
208 if ( isset( $regex[ $package ] ) )
210 // Custom search for latest package name
211 foreach ( $lines as $l )
213 $ver = preg_replace( $regex[ $package ], "$1", $l );
214 if ( $ver == $l ) continue;
215 return $ver; // Return first match of regex
218 return -7; // This is an error
221 if ( $package == "perl" ) // Custom for perl
225 foreach ( $lines as $l )
227 if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this
228 $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l );
229 if ( $ver == $l ) continue;
230 list( $s1, $s2, $rest ) = explode( ".", $ver );
231 if ( $s2 %
2 == 1 ) continue; // Remove odd minor versions
232 array_push( $tmp, $l );
238 if ( $package == "attr" ||
241 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.src.*$/" );
244 if ( $package == "e2fsprogs" )
245 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
247 if ( $package == "XML-Parser" )
249 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d).tar.*$/" );
250 # 2.44_01 is a developer release
251 if ( $max == "2.44_01" ) { return "2.44"; }
255 if ( $package == "ninja" )
256 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]*\d).*$/" );
258 if ( $package == "gmp" )
259 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
261 if ( $package == "dbus" )
262 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
264 if ( $package == "file" )
266 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
267 return str_replace( "_", ".", $max );
270 if ( $package == "grub" )
271 return find_max( $lines, "/grub/", "/^.*grub-(\d\..*).tar.xz.*$/" );
273 // Most packages are in the form $package-n.n.n
274 // Occasionally there are dashes (e.g. 201-1)
275 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" );
278 function get_current()
283 // Fetech from svn and get wget-list
285 $lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
287 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
290 exec ( "svn --quiet export $lfssvn LFS" );
293 $PAGE = "$tmpdir/LFS/BOOK/chapter03/chapter03.xml";
294 $STYLESHEET = "$tmpdir/LFS/BOOK/stylesheets/wget-list.xsl";
296 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
297 exec( "rm -rf $tmpdir" );
299 foreach ( $current as $line )
301 $file = basename( $line ) . "\n";
302 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
304 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
306 $file = rtrim( $file );
307 $pkg_pattern = "/(\D*).*/";
308 //$pattern = "/\D*(\d.*\d)\D*/";
309 $pattern = "/\D*(\d.*\d)\D*/";
311 if ( preg_match( "/e2fsprogs/", $file ) )
313 $pattern = "/e2\D*(\d.*\d)\D*/";
314 $pkg_pattern = "/(e2\D*).*/";
317 else if ( preg_match( "/tzdata/", $file ) )
319 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
322 else if ( preg_match( "/gmp/", $file ) )
324 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
327 else if ( preg_match( "/eudev.*manpages/", $file ) ) continue;
328 //else if ( preg_match( "/python/" , $file ) ) continue;
329 else if ( preg_match( "/systemd-man/" , $file ) ) continue;
331 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
332 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
334 // Touch up package names
335 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
336 $pkg_name = trim( $pkg_name, "-" );
338 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
339 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
340 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
342 $dirs[ $pkg_name ] = dirname( $line );
343 $vers[ $pkg_name ] = $version;
347 function mail_to_lfs()
353 //$to = "bruce.dubbs@gmail.com";
354 $to = "lfs-book@lists.linuxfromscratch.org";
355 $from = "bdubbs@linuxfromscratch.org";
356 $subject = "LFS Package Currency Check - $date GMT";
357 $headers = "From: bdubbs@anduin.linuxfromscratch.org";
359 $message = "Package LFS Upstream Flag\n\n";
361 foreach ( $dirs as $pkg => $dir )
363 //if ( $pkg != "gmp" ) continue; //debug
364 $v = get_packages( $pkg, $dir );
366 $flag = ( $vers[ $pkg ] != $v ) ?
"*" : "";
370 $p = substr( $pkg . $pad, 0, 15 );
371 $l = substr( $vers[ $pkg ] . $pad, 0, 10 );
372 $c = substr( $v . $pad, 0, 10 );
374 $message .= "$p $l $c $flag\n";
377 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
388 echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
389 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
390 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
392 <title>LFS Package Currency Check - $date</title>
393 <style type='text/css'>
400 border-spacing : 0px;
401 border-style : outset;
403 border-collapse : separate;
404 background-color: white;
411 border-style : inset;
413 background-color: white;
419 border-style : inset;
421 background-color: white;
427 <h1>LFS Package Currency Check</h1>
428 <h2>As of $date GMT</h1>
431 <tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
433 // Get the latest version of each package
434 foreach ( $dirs as $pkg => $dir )
436 $v = get_packages( $pkg, $dir );
437 $flag = ( $vers[ $pkg ] != $v ) ?
"*" : "";
438 echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
447 get_current(); // Get what is in the book
449 //html(); // Write html output