source: lfs-latest.php@ 788f897

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

MultiLib: Merge changes from trunk

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

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