source: lfs-latest.php@ 602a01f

multilib-10.1
Last change on this file since 602a01f was 602a01f, checked in by Thomas Trepl <thomas@…>, 4 years ago

Merge changes from trunk to multilib

git-svn-id: http://svn.linuxfromscratch.org/LFS/branches/multilib@12041 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

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