source: lfs-latest.php@ b2e3c22

Last change on this file since b2e3c22 was c5eaf41, checked in by Bruce Dubbs <bdubbs@…>, 6 years ago

Fix for new bzip2 location

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@11448 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

  • Property mode set to 100644
File size: 13.7 KB
Line 
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[ '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).*$/";
24
25function find_max( $lines, $regex_match, $regex_replace )
26{
27 $a = array();
28 if ( ! is_array( $lines ) ) return -1;
29
30 foreach ( $lines as $line )
31 {
32 if ( ! preg_match( $regex_match, $line ) ) continue;
33
34 // Isolate the version and put in an array
35 $slice = preg_replace( $regex_replace, "$1", $line );
36 if ( $slice == $line ) continue;
37
38 array_push( $a, $slice );
39 }
40
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;
44}
45
46function find_even_max( $lines, $regex_match, $regex_replace )
47{
48 $a = array();
49 foreach ( $lines as $line )
50 {
51 if ( ! preg_match( $regex_match, $line ) ) continue;
52
53 // Isolate the version and put in an array
54 $slice = preg_replace( $regex_replace, "$1", $line );
55
56 if ( "x$slice" == "x$line" ) continue;
57
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 );
63 }
64
65 rsort( $a, SORT_NATURAL ); // Max version is at the top
66 return ( isset( $a[0] ) ) ? $a[0] : -2;
67}
68
69function http_get_file( $url )
70{
71 if ( ! preg_match( "/sourceforge/", $url ) )
72 {
73 exec( "curl --location --silent --max-time 30 $url", $dir );
74
75 $s = implode( "\n", $dir );
76 $dir = strip_tags( $s );
77 return explode( "\n", $dir );
78 }
79 else
80 {
81 exec( "links -dump $url 2>/dev/null", $lines );
82 return $lines;
83 }
84}
85
86function max_parent( $dirpath, $prefix )
87{
88 // First, remove a directory
89 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
90 $position = strrpos( $dirpath, "/" );
91 $dirpath = substr ( $dirpath, 0, $position );
92
93 $lines = http_get_file( $dirpath );
94
95 $regex_match = "#${prefix}[\d\.]+/#";
96 $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#";
97 $max = find_max( $lines, $regex_match, $regex_replace );
98
99 return "$dirpath/$max";
100}
101
102function get_packages( $package, $dirpath )
103{
104 global $exceptions;
105 global $regex;
106
107//if ( $package != "expat" ) return 0; // Debug
108
109if ( $package == "check" ) $dirpath = "https://github.com/libcheck/check/releases";
110if ( $package == "e2fsprogs" ) $dirpath = "http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs";
111if ( $package == "expat" ) $dirpath = "http://sourceforge.net/projects/expat/files";
112if ( $package == "elfutils" ) $dirpath = "https://sourceware.org/ftp/elfutils";
113if ( $package == "expect" ) $dirpath = "http://sourceforge.net/projects/expect/files";
114if ( $package == "file" ) $dirpath = "https://github.com/file/file/releases";
115if ( $package == "flex" ) $dirpath = "https://github.com/westes/flex/releases";
116if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" );
117if ( $package == "intltool" ) $dirpath = "https://launchpad.net/intltool/trunk";
118if ( $package == "meson" ) $dirpath = "https://github.com/mesonbuild/meson/releases";
119if ( $package == "mpc" ) $dirpath = "https://ftp.gnu.org/gnu/mpc";
120if ( $package == "mpfr" ) $dirpath = "http://mpfr.loria.fr/mpfr-current";
121if ( $package == "ninja" ) $dirpath = "https://github.com/ninja-build/ninja/releases";
122if ( $package == "procps-ng" ) $dirpath = "http://sourceforge.net/projects/procps-ng/files";
123if ( $package == "psmisc" ) $dirpath = "http://sourceforge.net/projects/$package/files";
124if ( $package == "shadow" ) $dirpath = "https://github.com/shadow-maint/shadow/releases";
125if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
126if ( $package == "tcl" ) $dirpath = "http://sourceforge.net/projects/tcl/files";
127if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
128if ( $package == "vim" ) $dirpath = "ftp://ftp.vim.org/pub/vim/unix";
129
130 // Check for ftp
131 if ( preg_match( "/^ftp/", $dirpath ) )
132 {
133 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
134 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
135 $position = strpos( $dirpath, "/" ); // Divide at first slash
136 $server = substr( $dirpath, 0, $position );
137 $path = substr( $dirpath, $position );
138
139 $conn = ftp_connect( $server );
140 ftp_login( $conn, "anonymous", "" );
141
142 // See if we need special handling
143 if ( isset( $exceptions[ $package ] ) )
144 {
145 $specials = explode( ":", $exceptions[ $package ] );
146
147 foreach ( $specials as $i )
148 {
149 list( $op, $regexp ) = explode( "=", $i );
150
151 switch ($op)
152 {
153 case "UPDIR":
154 // Remove last dir from $path
155 $position = strrpos( $path, "/" );
156 $path = substr( $path, 0, $position );
157
158 // Get dir listing
159 $lines = ftp_rawlist ($conn, $path);
160 $max = find_max( $lines, $regexp, $regexp );
161 break;
162
163 case "DOWNDIR":
164 // Append found directory
165 $path .= "/$max";
166 break;
167
168 default:
169 echo "Error in specials array for $package\n";
170 return -5;
171 break;
172 }
173 }
174 }
175
176 $lines = ftp_rawlist ($conn, $path);
177 ftp_close( $conn );
178 }
179 else // http
180 {
181 // Customize http directories as needed
182 if ( $package == "tzdata" )
183 {
184 // Remove two directories
185 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
186 $position = strrpos( $dirpath, "/" );
187 $dirpath = substr ( $dirpath, 0, $position );
188 $position = strrpos( $dirpath, "/" );
189 $dirpath = substr ( $dirpath, 0, $position );
190 }
191
192 //if ( $package == "bzip2" )
193 //{
194 // // Remove one directory
195 // $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
196 // $position = strrpos( $dirpath, "/" );
197 // $dirpath = substr ( $dirpath, 0, $position );
198 //}
199
200 $lines = http_get_file( $dirpath );
201 if ( ! is_array( $lines ) ) return -6;
202 } // End fetch
203//print_r($lines);
204 if ( isset( $regex[ $package ] ) )
205 {
206 // Custom search for latest package name
207 foreach ( $lines as $l )
208 {
209 $ver = preg_replace( $regex[ $package ], "$1", $l );
210 if ( $ver == $l ) continue;
211 return $ver; // Return first match of regex
212 }
213
214 return -7; // This is an error
215 }
216
217 if ( $package == "perl" ) // Custom for perl
218 {
219 $tmp = array();
220
221 foreach ( $lines as $l )
222 {
223 if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this
224 $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l );
225 if ( $ver == $l ) continue;
226 list( $s1, $s2, $rest ) = explode( ".", $ver );
227 if ( $s2 % 2 == 1 ) continue; // Remove odd minor versions
228 array_push( $tmp, $l );
229 }
230
231 $lines = $tmp;
232 }
233
234 if ( $package == "attr" ||
235 $package == "acl" )
236 {
237 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d).tar.*$/" );
238 }
239
240 if ( $package == "e2fsprogs" )
241 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
242
243 if ( $package == "expect" )
244 return find_max( $lines, "/expect/", "/^.*expect(\d[\d\.]+\d).tar.*$/" );
245
246 if ( $package == "elfutils" )
247 return find_max( $lines, "/^\d/", "/^(\d[\d\.]+\d)\/.*$/" );
248
249 if ( $package == "XML-Parser" )
250 {
251 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d).tar.*$/" );
252 # 2.44_01 is a developer release
253 if ( $max == "2.44_01" ) { return "2.44"; }
254 return $max;
255 }
256
257 if ( $package == "tcl" )
258 return find_max( $lines, "/tcl/", "/^.*tcl(\d[\d\.]*\d)-src.*$/" );
259
260 if ( $package == "ninja" )
261 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]*\d).*$/" );
262
263 if ( $package == "gmp" )
264 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
265
266 if ( $package == "dbus" )
267 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
268
269 if ( $package == "file" )
270 {
271 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
272 return str_replace( "_", ".", $max );
273 }
274
275 if ( $package == "grub" )
276 return find_max( $lines, "/grub/", "/^.*grub-(\d\..*).tar.xz.*$/" );
277
278 if ( $package == "openssl" )
279 return find_max( $lines, "/openssl/", "/^.*openssl-([\d\.p]*\d.?).tar.*$/" );
280
281 // Most packages are in the form $package-n.n.n
282 // Occasionally there are dashes (e.g. 201-1)
283 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" );
284}
285
286function get_current()
287{
288 global $dirs;
289 global $vers;
290
291 // Fetech from svn and get wget-list
292 $current = array();
293 $lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
294
295 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
296 $cdir = getcwd();
297 chdir( $tmpdir );
298 exec ( "svn --quiet export $lfssvn LFS" );
299 chdir( $cdir );
300
301 $PAGE = "$tmpdir/LFS/BOOK/chapter03/chapter03.xml";
302 $STYLESHEET = "$tmpdir/LFS/BOOK/stylesheets/wget-list.xsl";
303
304 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
305 exec( "rm -rf $tmpdir" );
306
307 foreach ( $current as $line )
308 {
309 $file = basename( $line ) . "\n";
310 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
311
312 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
313
314 $file = rtrim( $file );
315 $pkg_pattern = "/(\D*).*/";
316 //$pattern = "/\D*(\d.*\d)\D*/";
317 $pattern = "/\D*(\d.*\d)\D*/";
318
319 if ( preg_match( "/e2fsprogs/", $file ) )
320 {
321 $pattern = "/e2\D*(\d.*\d)\D*/";
322 $pkg_pattern = "/(e2\D*).*/";
323 }
324
325 else if ( preg_match( "/tzdata/", $file ) )
326 {
327 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
328 }
329
330 else if ( preg_match( "/openssl/", $file ) )
331 {
332 $pattern = "/\D*(\d.*\d.*).tar.*$/";
333 }
334
335 else if ( preg_match( "/gmp/", $file ) )
336 {
337 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
338 }
339
340 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
341 else if ( preg_match( "/python/" , $file ) ) continue;
342
343 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
344 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
345
346 // Touch up package names
347 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
348 $pkg_name = trim( $pkg_name, "-" );
349
350 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
351 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
352 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
353
354 $dirs[ $pkg_name ] = dirname( $line );
355 $vers[ $pkg_name ] = $version;
356 }
357}
358
359function mail_to_lfs()
360{
361 global $date;
362 global $vers;
363 global $dirs;
364
365 //$to = "bruce.dubbs@gmail.com";
366 $to = "lfs-book@lists.linuxfromscratch.org";
367 $from = "bdubbs@linuxfromscratch.org";
368 $subject = "LFS Package Currency Check - $date GMT";
369 $headers = "From: bdubbs@anduin.linuxfromscratch.org";
370
371 $message = "Package LFS Upstream Flag\n\n";
372
373 foreach ( $dirs as $pkg => $dir )
374 {
375 //if ( $pkg != "gmp" ) continue; //debug
376 $v = get_packages( $pkg, $dir );
377
378 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
379
380 // Pad for output
381 $pad = " ";
382 $p = substr( $pkg . $pad, 0, 15 );
383 $l = substr( $vers[ $pkg ] . $pad, 0, 10 );
384 $c = substr( $v . $pad, 0, 10 );
385
386 $message .= "$p $l $c $flag\n";
387 }
388
389 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
390 //echo $message;
391}
392
393function html()
394{
395
396 global $date;
397 global $vers;
398 global $dirs;
399
400 echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
401 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
402<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
403<head>
404<title>LFS Package Currency Check - $date</title>
405<style type='text/css'>
406h1, h2 {
407 text-align : center;
408}
409
410table {
411 border-width : 1px;
412 border-spacing : 0px;
413 border-style : outset;
414 border-color : gray;
415 border-collapse : separate;
416 background-color: white;
417 margin : 0px auto;
418}
419
420table th {
421 border-width : 1px;
422 padding : 2px;
423 border-style : inset;
424 border-color : gray;
425 background-color: white;
426}
427
428table td {
429 border-width : 1px;
430 padding : 2px;
431 border-style : inset;
432 border-color : gray;
433 background-color: white;
434}
435</style>
436
437</head>
438<body>
439<h1>LFS Package Currency Check</h1>
440<h2>As of $date GMT</h1>
441
442<table>
443<tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
444
445 // Get the latest version of each package
446 foreach ( $dirs as $pkg => $dir )
447 {
448 $v = get_packages( $pkg, $dir );
449 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
450 echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
451 }
452
453 echo "</table>
454</body>
455</html>\n";
456
457}
458
459get_current(); // Get what is in the book
460mail_to_lfs();
461//html(); // Write html output
462?>
Note: See TracBrowser for help on using the repository browser.