Convert bootscripts and udev tarballs to xz
[linux_from_scratch.git] / lfs-latest.php
blobb9b8f76305b345608b580be724144eba3bd318ba
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[ '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[ 'systemd' ] = "/^.*v([\d]+)$/";
20 //$regex[ 'sysvinit' ] = "/^.*sysvinit-([\d\.]+)dsf\.tar.*$/";
21 $regex[ 'tzdata' ] = "/^.*tzdata([\d]+[a-z]).*$/";
22 $regex[ 'xz' ] = "/^.*xz-([\d\.]*\d).*$/";
23 $regex[ 'zlib' ] = "/^.*zlib ([\d\.]*\d).*$/";
25 function find_max( $lines, $regex_match, $regex_replace )
27 $a = array();
28 if ( ! is_array( $lines ) ) return -1;
30 foreach ( $lines as $line )
32 if ( ! preg_match( $regex_match, $line ) ) continue;
34 // Isolate the version and put in an array
35 $slice = preg_replace( $regex_replace, "$1", $line );
36 if ( $slice == $line ) continue;
38 array_push( $a, $slice );
41 // SORT_NATURAL requires php-5.4.0 or later
42 rsort( $a, SORT_NATURAL ); // Max version is at the top
43 return ( isset( $a[0] ) ) ? $a[0] : -2;
46 function find_even_max( $lines, $regex_match, $regex_replace )
48 $a = array();
49 foreach ( $lines as $line )
51 if ( ! preg_match( $regex_match, $line ) ) continue;
53 // Isolate the version and put in an array
54 $slice = preg_replace( $regex_replace, "$1", $line );
56 if ( "x$slice" == "x$line" ) continue;
58 // Skip odd numbered minor versions and minors > 80
59 list( $major, $minor, $rest ) = explode( ".", $slice . ".0" );
60 if ( $minor % 2 == 1 ) continue;
61 if ( $minor > 80 ) continue;
62 array_push( $a, $slice );
65 rsort( $a, SORT_NATURAL ); // Max version is at the top
66 return ( isset( $a[0] ) ) ? $a[0] : -2;
69 function http_get_file( $url )
71 if ( ! preg_match( "/sourceforge/", $url ) )
73 exec( "curl --location --silent --max-time 30 $url", $dir );
75 $s = implode( "\n", $dir );
76 $dir = strip_tags( $s );
77 return explode( "\n", $dir );
79 else
81 exec( "links -dump $url 2>/dev/null", $lines );
82 return $lines;
86 function max_parent( $dirpath, $prefix )
88 // First, remove a directory
89 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
90 $position = strrpos( $dirpath, "/" );
91 $dirpath = substr ( $dirpath, 0, $position );
93 $lines = http_get_file( $dirpath );
95 $regex_match = "#${prefix}[\d\.]+/#";
96 $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#";
97 $max = find_max( $lines, $regex_match, $regex_replace );
99 return "$dirpath/$max";
102 function get_packages( $package, $dirpath )
104 global $exceptions;
105 global $regex;
107 //if ( $package != "vim" ) return 0; // Debug
109 if ( $package == "check" ) $dirpath = "https://github.com/libcheck/check/releases";
110 if ( $package == "e2fsprogs" ) $dirpath = "http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs";
111 if ( $package == "expat" ) $dirpath = "http://sourceforge.net/projects/expat/files";
112 if ( $package == "elfutils" ) $dirpath = "https://sourceware.org/ftp/elfutils";
113 if ( $package == "expect" ) $dirpath = "http://sourceforge.net/projects/expect/files";
114 if ( $package == "file" ) $dirpath = "https://github.com/file/file/releases";
115 if ( $package == "flex" ) $dirpath = "https://github.com/westes/flex/releases";
116 if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" );
117 if ( $package == "intltool" ) $dirpath = "https://launchpad.net/intltool/trunk";
118 if ( $package == "meson" ) $dirpath = "https://github.com/mesonbuild/meson/releases";
119 if ( $package == "mpc" ) $dirpath = "https://ftp.gnu.org/gnu/mpc";
120 if ( $package == "mpfr" ) $dirpath = "http://mpfr.loria.fr/mpfr-current";
121 if ( $package == "ninja" ) $dirpath = "https://github.com/ninja-build/ninja/releases";
122 if ( $package == "procps-ng" ) $dirpath = "http://sourceforge.net/projects/procps-ng/files";
123 if ( $package == "psmisc" ) $dirpath = "http://sourceforge.net/projects/$package/files";
124 if ( $package == "shadow" ) $dirpath = "https://github.com/shadow-maint/shadow/releases";
125 if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
126 if ( $package == "tcl" ) $dirpath = "http://sourceforge.net/projects/tcl/files";
127 if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
128 if ( $package == "vim" ) $dirpath = "https://github.com/vim/vim/releases";
129 //if ( $package == "vim" ) $dirpath = "ftp://ftp.vim.org/pub/vim/unix";
131 // Check for ftp
132 if ( preg_match( "/^ftp/", $dirpath ) )
134 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
135 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
136 $position = strpos( $dirpath, "/" ); // Divide at first slash
137 $server = substr( $dirpath, 0, $position );
138 $path = substr( $dirpath, $position );
140 $conn = ftp_connect( $server );
141 ftp_login( $conn, "anonymous", "" );
143 // See if we need special handling
144 if ( isset( $exceptions[ $package ] ) )
146 $specials = explode( ":", $exceptions[ $package ] );
148 foreach ( $specials as $i )
150 list( $op, $regexp ) = explode( "=", $i );
152 switch ($op)
154 case "UPDIR":
155 // Remove last dir from $path
156 $position = strrpos( $path, "/" );
157 $path = substr( $path, 0, $position );
159 // Get dir listing
160 $lines = ftp_rawlist ($conn, $path);
161 $max = find_max( $lines, $regexp, $regexp );
162 break;
164 case "DOWNDIR":
165 // Append found directory
166 $path .= "/$max";
167 break;
169 default:
170 echo "Error in specials array for $package\n";
171 return -5;
172 break;
177 $lines = ftp_rawlist ($conn, $path);
178 ftp_close( $conn );
180 else // http
182 // Customize http directories as needed
183 if ( $package == "tzdata" )
185 // Remove two directories
186 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
187 $position = strrpos( $dirpath, "/" );
188 $dirpath = substr ( $dirpath, 0, $position );
189 $position = strrpos( $dirpath, "/" );
190 $dirpath = substr ( $dirpath, 0, $position );
193 //if ( $package == "bzip2" )
195 // // Remove one directory
196 // $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
197 // $position = strrpos( $dirpath, "/" );
198 // $dirpath = substr ( $dirpath, 0, $position );
201 $lines = http_get_file( $dirpath );
202 if ( ! is_array( $lines ) ) return -6;
203 } // End fetch
204 //print_r($lines);
205 if ( isset( $regex[ $package ] ) )
207 // Custom search for latest package name
208 foreach ( $lines as $l )
210 $ver = preg_replace( $regex[ $package ], "$1", $l );
211 if ( $ver == $l ) continue;
212 return $ver; // Return first match of regex
215 return -7; // This is an error
218 if ( $package == "perl" ) // Custom for perl
220 $tmp = array();
222 foreach ( $lines as $l )
224 if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this
225 $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l );
226 if ( $ver == $l ) continue;
227 list( $s1, $s2, $rest ) = explode( ".", $ver );
228 if ( $s2 % 2 == 1 ) continue; // Remove odd minor versions
229 array_push( $tmp, $l );
232 $lines = $tmp;
235 if ( $package == "attr" ||
236 $package == "acl" )
238 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d).tar.*$/" );
241 if ( $package == "e2fsprogs" )
242 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
244 if ( $package == "expect" )
245 return find_max( $lines, "/expect/", "/^.*expect(\d[\d\.]+\d).tar.*$/" );
247 if ( $package == "elfutils" )
248 return find_max( $lines, "/^\d/", "/^(\d[\d\.]+\d)\/.*$/" );
250 if ( $package == "XML-Parser" )
252 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d).tar.*$/" );
253 # 2.44_01 is a developer release
254 if ( $max == "2.44_01" ) { return "2.44"; }
255 return $max;
258 if ( $package == "tcl" )
259 return find_max( $lines, "/tcl/", "/^.*tcl(\d[\d\.]*\d)-src.*$/" );
261 if ( $package == "ninja" )
262 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]*\d).*$/" );
264 if ( $package == "gmp" )
265 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
267 if ( $package == "dbus" )
268 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
270 if ( $package == "file" )
272 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
273 return str_replace( "_", ".", $max );
276 if ( $package == "grub" )
277 return find_max( $lines, "/grub/", "/^.*grub-(\d\..*).tar.xz.*$/" );
279 if ( $package == "openssl" )
280 return find_max( $lines, "/openssl/", "/^.*openssl-([\d\.p]*\d.?).tar.*$/" );
282 if ( $package == "vim" )
283 return find_max( $lines, "/v\d\./", "/^.*v([\d\.]+).*$/" );
285 // Most packages are in the form $package-n.n.n
286 // Occasionally there are dashes (e.g. 201-1)
287 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" );
290 function get_current()
292 global $dirs;
293 global $vers;
295 // Fetech from svn and get wget-list
296 $current = array();
297 $lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
299 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
300 $cdir = getcwd();
301 chdir( $tmpdir );
302 exec ( "svn --quiet export $lfssvn LFS" );
303 chdir( $cdir );
305 $PAGE = "$tmpdir/LFS/BOOK/chapter03/chapter03.xml";
306 $STYLESHEET = "$tmpdir/LFS/BOOK/stylesheets/wget-list.xsl";
308 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
309 exec( "rm -rf $tmpdir" );
311 foreach ( $current as $line )
313 $file = basename( $line ) . "\n";
314 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
316 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
318 $file = rtrim( $file );
319 $pkg_pattern = "/(\D*).*/";
320 //$pattern = "/\D*(\d.*\d)\D*/";
321 $pattern = "/\D*(\d.*\d)\D*/";
323 if ( preg_match( "/e2fsprogs/", $file ) )
325 $pattern = "/e2\D*(\d.*\d)\D*/";
326 $pkg_pattern = "/(e2\D*).*/";
329 else if ( preg_match( "/tzdata/", $file ) )
331 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
334 else if ( preg_match( "/openssl/", $file ) )
336 $pattern = "/\D*(\d.*\d.*).tar.*$/";
339 else if ( preg_match( "/gmp/", $file ) )
341 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
344 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
345 else if ( preg_match( "/python/" , $file ) ) continue;
347 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
348 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
350 // Touch up package names
351 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
352 $pkg_name = trim( $pkg_name, "-" );
354 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
355 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
356 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
358 $dirs[ $pkg_name ] = dirname( $line );
359 $vers[ $pkg_name ] = $version;
363 function mail_to_lfs()
365 global $date;
366 global $vers;
367 global $dirs;
369 //$to = "bruce.dubbs@gmail.com";
370 $to = "lfs-book@lists.linuxfromscratch.org";
371 $from = "bdubbs@linuxfromscratch.org";
372 $subject = "LFS Package Currency Check - $date GMT";
373 $headers = "From: bdubbs@anduin.linuxfromscratch.org";
375 $message = "Package LFS Upstream Flag\n\n";
377 foreach ( $dirs as $pkg => $dir )
379 //if ( $pkg != "gmp" ) continue; //debug
380 $v = get_packages( $pkg, $dir );
382 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
384 // Pad for output
385 $pad = " ";
386 $p = substr( $pkg . $pad, 0, 15 );
387 $l = substr( $vers[ $pkg ] . $pad, 0, 10 );
388 $c = substr( $v . $pad, 0, 10 );
390 $message .= "$p $l $c $flag\n";
393 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
394 //echo $message;
397 function html()
400 global $date;
401 global $vers;
402 global $dirs;
404 echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
405 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
406 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
407 <head>
408 <title>LFS Package Currency Check - $date</title>
409 <style type='text/css'>
410 h1, h2 {
411 text-align : center;
414 table {
415 border-width : 1px;
416 border-spacing : 0px;
417 border-style : outset;
418 border-color : gray;
419 border-collapse : separate;
420 background-color: white;
421 margin : 0px auto;
424 table th {
425 border-width : 1px;
426 padding : 2px;
427 border-style : inset;
428 border-color : gray;
429 background-color: white;
432 table td {
433 border-width : 1px;
434 padding : 2px;
435 border-style : inset;
436 border-color : gray;
437 background-color: white;
439 </style>
441 </head>
442 <body>
443 <h1>LFS Package Currency Check</h1>
444 <h2>As of $date GMT</h1>
446 <table>
447 <tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
449 // Get the latest version of each package
450 foreach ( $dirs as $pkg => $dir )
452 $v = get_packages( $pkg, $dir );
453 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
454 echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
457 echo "</table>
458 </body>
459 </html>\n";
463 get_current(); // Get what is in the book
464 mail_to_lfs();
465 //html(); // Write html output