source: lfs-latest-git.php@ c8612fa

11.0 11.0-rc1 11.0-rc2 11.0-rc3 11.1 11.1-rc1 11.2 11.2-rc1 11.3 11.3-rc1 12.0 12.0-rc1 12.1 12.1-rc1 arm bdubbs/gcc13 ml-11.0 multilib renodr/libudev-from-systemd s6-init trunk xry111/arm64 xry111/arm64-12.0 xry111/clfs-ng xry111/lfs-next xry111/loongarch xry111/loongarch-12.0 xry111/loongarch-12.1 xry111/mips64el xry111/pip3 xry111/rust-wip-20221008 xry111/update-glibc
Last change on this file since c8612fa was c8612fa, checked in by Bruce Dubbs <bdubbs@…>, 3 years ago

Correct file location for git repo

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