source: lfs-latest-git.php@ 176404f

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 176404f was c519d456, checked in by Bruce Dubbs <bdubbs@…>, 3 years ago

Set up currency for MakrupSafe and Jinja2

  • Property mode set to 100644
File size: 15.5 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( "lynx -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 = "https://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 == "MarkupSafe" ) $dirpath = "https://pypi.python.org/pypi/MarkupSafe/";
131if ( $package == "Jinja" ) $dirpath = "https://pypi.python.org/pypi/Jinja2/";
132if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
133if ( $package == "tcl" ) $dirpath = "http://sourceforge.net/projects/tcl/files";
134if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
135if ( $package == "vim" ) $dirpath = "https://github.com/vim/vim/releases";
136if ( $package == "zstd" ) $dirpath = "https://github.com/facebook/zstd/releases";
137//if ( $package == "vim" ) $dirpath = "ftp://ftp.vim.org/pub/vim/unix";
138
139 // Check for ftp
140 if ( preg_match( "/^ftp/", $dirpath ) )
141 {
142 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
143 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
144 $position = strpos( $dirpath, "/" ); // Divide at first slash
145 $server = substr( $dirpath, 0, $position );
146 $path = substr( $dirpath, $position );
147
148 $conn = ftp_connect( $server );
149 ftp_login( $conn, "anonymous", "" );
150
151 // See if we need special handling
152 if ( isset( $exceptions[ $package ] ) )
153 {
154 $specials = explode( ":", $exceptions[ $package ] );
155
156 foreach ( $specials as $i )
157 {
158 list( $op, $regexp ) = explode( "=", $i );
159
160 switch ($op)
161 {
162 case "UPDIR":
163 // Remove last dir from $path
164 $position = strrpos( $path, "/" );
165 $path = substr( $path, 0, $position );
166
167 // Get dir listing
168 $lines = ftp_rawlist ($conn, $path);
169 $max = find_max( $lines, $regexp, $regexp );
170 break;
171
172 case "DOWNDIR":
173 // Append found directory
174 $path .= "/$max";
175 break;
176
177 default:
178 echo "Error in specials array for $package\n";
179 return -5;
180 break;
181 }
182 }
183 }
184
185 $lines = ftp_rawlist ($conn, $path);
186 ftp_close( $conn );
187 }
188 else // http(s)
189 {
190 // Customize http directories as needed
191 if ( $package == "tzdata" )
192 {
193 // Remove two directories
194 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
195 $position = strrpos( $dirpath, "/" );
196 $dirpath = substr ( $dirpath, 0, $position );
197 $position = strrpos( $dirpath, "/" );
198 $dirpath = substr ( $dirpath, 0, $position );
199 }
200
201 $lines = http_get_file( $dirpath );
202 if ( ! is_array( $lines ) ) return -6;
203 } // End fetch
204
205 if ( isset( $regex[ $package ] ) )
206 {
207 // Custom search for latest package name
208 foreach ( $lines as $l )
209 {
210 $ver = preg_replace( $regex[ $package ], "$1", $l );
211 if ( $ver == $l ) continue;
212 return $ver; // Return first match of regex
213 }
214
215 return -7; // This is an error
216 }
217
218 if ( $package == "perl" ) // Custom for perl
219 {
220 $tmp = array();
221
222 foreach ( $lines as $l )
223 {
224 if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this
225 $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l );
226 if ( $ver == $l ) continue;
227 list( $s1, $s2, $rest ) = explode( ".", $ver );
228 if ( $s2 % 2 == 1 ) continue; // Remove odd minor versions
229 array_push( $tmp, $l );
230 }
231
232 $lines = $tmp;
233 }
234
235 if ( $package == "attr" ||
236 $package == "acl" )
237 {
238 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d).tar.*$/" );
239 }
240
241 if ( $package == "e2fsprogs" )
242 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]+\d).*$/" );
243
244 if ( $package == "expect" )
245 return find_max( $lines, "/expect/", "/^.*expect(\d[\d\.]+\d).tar.*$/" );
246
247 if ( $package == "elfutils" )
248 return find_max( $lines, "/^\d/", "/^(\d[\d\.]+\d)\/.*$/" );
249
250 if ( $package == "XML-Parser" )
251 {
252 $max = find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d).tar.*$/" );
253 # 2.44_01 is a developer release
254 if ( $max == "2.44_01" ) { return "2.44"; }
255 return $max;
256 }
257
258 if ( $package == "tcl" )
259 return find_max( $lines, "/tcl/", "/^.*tcl(\d[\d\.]*\d)-src.*$/" );
260
261 if ( $package == "ninja" )
262 return find_max( $lines, "/v\d/", "/^.*v(\d[\d\.]*\d).*$/" );
263
264 if ( $package == "gmp" )
265 return find_max( $lines, "/$package/", "/^.*$package-([\d\._]*\d[a-z]?).tar.*$/" );
266
267 if ( $package == "dbus" )
268 return find_even_max( $lines, "/$package/", "/^.*$package-([\d\.]+).tar.*$/" );
269
270 if ( $package == "file" )
271 {
272 $max = find_max( $lines, "/FILE5/", "/^.*FILE(5_\d+)*$/" );
273 return str_replace( "_", ".", $max );
274 }
275
276 if ( $package == "procps-ng" )
277 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+)$/" );
278
279 if ( $package == "psmisc" )
280 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+) .*$/" );
281
282 if ( $package == "grub" )
283 return find_max( $lines, "/grub/", "/^.*grub-([\d\.]+).tar.xz.*$/" );
284
285 if ( $package == "Jinja" )
286 return find_max( $lines, "/Jinja/", "/^.*Jinja2 ([\d\.]+).*$/" );
287
288 if ( $package == "openssl" )
289 return find_max( $lines, "/openssl/", "/^.*openssl-([\d\.p]*\d.?).tar.*$/" );
290
291 if ( $package == "vim" )
292 return find_max( $lines, "/v\d\./", "/^.*v([\d\.]+).*$/" );
293
294 if ( $package == "zstd" )
295 return find_max( $lines, "/Zstandard v/", "/^.*v([\d\.]+).*$/" );
296
297 // Most packages are in the form $package-n.n.n
298 // Occasionally there are dashes (e.g. 201-1)
299 return find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" );
300}
301
302function get_current()
303{
304 global $dirs;
305 global $vers;
306
307 // Fetech from git and get wget-list
308 $current = array();
309 #$lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
310 $lfsgit = "git://git.linuxfromscratch.org/lfs.git";
311
312 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
313 $cdir = getcwd();
314 chdir( $tmpdir );
315 #exec ( "svn --quiet export $lfssvn LFS" );
316 exec ( "git clone $lfsgit LFS" );
317
318 # Make version.ent
319 chdir( "$tmpdir/LFS" );
320 exec ( "./git-version.sh" );
321
322 chdir( $cdir );
323
324 $PAGE = "$tmpdir/LFS/chapter03/chapter03.xml";
325 $STYLESHEET = "$tmpdir/LFS/stylesheets/wget-list.xsl";
326
327 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
328 exec( "rm -rf $tmpdir" );
329
330 foreach ( $current as $line )
331 {
332 $file = basename( $line ) . "\n";
333 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
334
335 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
336
337 $file = rtrim( $file );
338 $pkg_pattern = "/(\D*).*/";
339 //$pattern = "/\D*(\d.*\d)\D*/";
340 $pattern = "/\D*(\d.*\d)\D*/";
341
342 if ( preg_match( "/e2fsprogs/", $file ) )
343 {
344 $pattern = "/e2\D*(\d.*\d)\D*/";
345 $pkg_pattern = "/(e2\D*).*/";
346 }
347
348 else if ( preg_match( "/tzdata/", $file ) )
349 {
350 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
351 }
352
353 else if ( preg_match( "/openssl/", $file ) )
354 {
355 $pattern = "/\D*(\d.*\d.*).tar.*$/";
356 }
357
358 else if ( preg_match( "/gmp/", $file ) )
359 {
360 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
361 }
362
363 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
364 else if ( preg_match( "/python/" , $file ) ) continue;
365
366 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
367 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
368
369 // Touch up package names
370 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
371 $pkg_name = trim( $pkg_name, "-" );
372
373 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
374 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
375 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
376
377 $dirs[ $pkg_name ] = dirname( $line );
378 $vers[ $pkg_name ] = $version;
379 }
380}
381
382function mail_to_lfs()
383{
384 global $date;
385 global $vers;
386 global $dirs;
387
388 $to = "lfs-book@lists.linuxfromscratch.org";
389 $from = "bdubbs@linuxfromscratch.org";
390 $subject = "LFS Package Currency Check - $date GMT";
391 $headers = "From: bdubbs@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
481function write_to_stdout()
482{
483
484 global $date;
485 global $vers;
486 global $dirs;
487
488 echo "
489LFS Package Currency Check
490As of $date GMT
491
492LFS Package LFS Version Latest Flag\n";
493
494 // Get the latest version of each package
495 foreach ( $dirs as $pkg => $dir )
496 {
497 $p_name = sprintf( "%-15s", $pkg ); // package name formatted
498
499 $b_version = $vers[ $pkg ]; // book version
500 $b_string = sprintf( "%-11s", $b_version ); // book version formatted
501
502 $latest = get_packages( $pkg, $dir ); // latest version
503 $l_string = sprintf( "%-6s", $latest ); // latest version formatted
504
505 $flag = ( $b_version != $latest ) ? "*" : "";
506 echo "$p_name $b_string $l_string $flag\n";
507 }
508}
509
510get_current(); // Get what is in the book
511mail_to_lfs();
512//html(); // Write html output
513//write_to_stdout(); // For debugging
514?>
Note: See TracBrowser for help on using the repository browser.