source: lfs-latest.php@ 5ec731c

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

LFS-8.2-rc1

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