source: lfs-latest.php@ 94801bf

10.0 10.0-rc1 10.1 10.1-rc1 11.0 11.0-rc1 11.0-rc2 11.0-rc3 9.0 9.0-rc1 9.1 9.1-rc1 cross-chap5 ml-11.0 multilib old-trunk trunk xry111/git-transition xry111/glibc-2.34 xry111/tester-nohack xry111/usr-move
Last change on this file since 94801bf was 94801bf, checked in by Bruce Dubbs <bdubbs@…>, 2 years ago

Update currency for bc

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

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