source: lfs-latest-git.php@ d18d285

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 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 d18d285 was d18d285, checked in by Bruce Dubbs <bdubbs@…>, 2 years ago

Update currency to use https everywhere

  • Property mode set to 100644
File size: 15.6 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 = "https://sourceforge.net/projects/expat/files";
115if ( $package == "elfutils" ) $dirpath = "https://sourceware.org/ftp/elfutils";
116if ( $package == "expect" ) $dirpath = "https://sourceforge.net/projects/expect/files";
117if ( $package == "file" ) $dirpath = "https://github.com/file/file/tags";
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 == "libffi" ) $dirpath = "https://github.com/libffi/libffi/releases";
123if ( $package == "meson" ) $dirpath = "https://github.com/mesonbuild/meson/releases";
124if ( $package == "mpc" ) $dirpath = "https://ftp.gnu.org/gnu/mpc";
125if ( $package == "mpfr" ) $dirpath = "https://mpfr.loria.fr/mpfr-current";
126if ( $package == "ncurses" ) $dirpath = "https://invisible-mirror.net/archives/ncurses";
127if ( $package == "ninja" ) $dirpath = "https://github.com/ninja-build/ninja/releases";
128if ( $package == "procps-ng" ) $dirpath = "https://gitlab.com/procps-ng/procps/-/tags";
129if ( $package == "psmisc" ) $dirpath = "https://gitlab.com/psmisc/psmisc/-/tags";
130if ( $package == "Python" ) $dirpath = "https://www.python.org/downloads/source/";
131if ( $package == "shadow" ) $dirpath = "https://github.com/shadow-maint/shadow/releases";
132if ( $package == "MarkupSafe" ) $dirpath = "https://pypi.python.org/pypi/MarkupSafe/";
133if ( $package == "Jinja" ) $dirpath = "https://pypi.python.org/pypi/Jinja2/";
134if ( $package == "systemd" ) $dirpath = "https://github.com/systemd/systemd/releases";
135if ( $package == "tcl" ) $dirpath = "https://sourceforge.net/projects/tcl/files";
136if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." );
137if ( $package == "vim" ) $dirpath = "https://github.com/vim/vim/tags";
138if ( $package == "zstd" ) $dirpath = "https://github.com/facebook/zstd/releases";
139
140 // Check for ftp
141 if ( preg_match( "/^ftp/", $dirpath ) )
142 {
143 echo "ftp should not occur\n";
144 /*
145 $dirpath = substr( $dirpath, 6 ); // Remove ftp://
146 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
147 $position = strpos( $dirpath, "/" ); // Divide at first slash
148 $server = substr( $dirpath, 0, $position );
149 $path = substr( $dirpath, $position );
150
151 $conn = ftp_connect( $server );
152 ftp_login( $conn, "anonymous", "" );
153
154 // See if we need special handling
155 if ( isset( $exceptions[ $package ] ) )
156 {
157 $specials = explode( ":", $exceptions[ $package ] );
158
159 foreach ( $specials as $i )
160 {
161 list( $op, $regexp ) = explode( "=", $i );
162
163 switch ($op)
164 {
165 case "UPDIR":
166 // Remove last dir from $path
167 $position = strrpos( $path, "/" );
168 $path = substr( $path, 0, $position );
169
170 // Get dir listing
171 $lines = ftp_rawlist ($conn, $path);
172 $max = find_max( $lines, $regexp, $regexp );
173 break;
174
175 case "DOWNDIR":
176 // Append found directory
177 $path .= "/$max";
178 break;
179
180 default:
181 echo "Error in specials array for $package\n";
182 return -5;
183 break;
184 }
185 }
186 }
187
188 $lines = ftp_rawlist ($conn, $path);
189 ftp_close( $conn );
190*/
191 }
192 else // http(s)
193 {
194 // Customize http directories as needed
195 if ( $package == "tzdata" )
196 {
197 // Remove two directories
198 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
199 $position = strrpos( $dirpath, "/" );
200 $dirpath = substr ( $dirpath, 0, $position );
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
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
280 if ( $package == "procps-ng" )
281 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+)$/" );
282
283 if ( $package == "psmisc" )
284 return find_max( $lines, "/v\d/", "/^.*v([\d\.]+) .*$/" );
285
286 if ( $package == "grub" )
287 return find_max( $lines, "/grub/", "/^.*grub-([\d\.]+).tar.xz.*$/" );
288
289 if ( $package == "Jinja" )
290 return find_max( $lines, "/Jinja/", "/^.*Jinja2 ([\d\.]+).*$/" );
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 git and get wget-list
312 $current = array();
313 #$lfssvn = "svn://svn.linuxfromscratch.org/LFS/trunk";
314 $lfsgit = "git://git.linuxfromscratch.org/lfs.git";
315
316 $tmpdir = exec( "mktemp -d /tmp/lfscheck.XXXXXX" );
317 $cdir = getcwd();
318 chdir( $tmpdir );
319 #exec ( "svn --quiet export $lfssvn LFS" );
320 exec ( "git clone $lfsgit LFS" );
321
322 # Make version.ent
323 chdir( "$tmpdir/LFS" );
324 exec ( "./git-version.sh systemd" );
325
326 chdir( $cdir );
327
328 $PAGE = "$tmpdir/LFS/chapter03/chapter03.xml";
329 $STYLESHEET = "$tmpdir/LFS/stylesheets/wget-list.xsl";
330
331 exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE", $current );
332 exec( "rm -rf $tmpdir" );
333
334 foreach ( $current as $line )
335 {
336 $file = basename( $line ) . "\n";
337 if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches
338
339 $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex
340
341 $file = rtrim( $file );
342 $pkg_pattern = "/(\D*).*/";
343 //$pattern = "/\D*(\d.*\d)\D*/";
344 $pattern = "/\D*(\d.*\d)\D*/";
345
346 if ( preg_match( "/e2fsprogs/", $file ) )
347 {
348 $pattern = "/e2\D*(\d.*\d)\D*/";
349 $pkg_pattern = "/(e2\D*).*/";
350 }
351
352 else if ( preg_match( "/tzdata/", $file ) )
353 {
354 $pattern = "/\D*(\d.*[a-z])\.tar\D*/";
355 }
356
357 else if ( preg_match( "/openssl/", $file ) )
358 {
359 $pattern = "/\D*(\d.*\d.*).tar.*$/";
360 }
361
362 else if ( preg_match( "/gmp/", $file ) )
363 {
364 $pattern = "/\D*(\d.*[a-z]*)\.tar\D*/";
365 }
366
367 else if ( preg_match( "/systemd-man-pages/", $file ) ) continue;
368 else if ( preg_match( "/python/" , $file ) ) continue;
369
370 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
371 $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #-
372
373 // Touch up package names
374 $pkg_name = preg_replace( $pkg_pattern, "$1", $file );
375 $pkg_name = trim( $pkg_name, "-" );
376
377 if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; }
378 if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; }
379 if ( preg_match( "/shadow/" , $pkg_name ) ) { $pkg_name = "shadow"; }
380
381 $dirs[ $pkg_name ] = dirname( $line );
382 $vers[ $pkg_name ] = $version;
383 }
384}
385
386function mail_to_lfs()
387{
388 global $date;
389 global $vers;
390 global $dirs;
391
392 $to = "lfs-book@lists.linuxfromscratch.org";
393 $from = "bdubbs@linuxfromscratch.org";
394 $subject = "LFS Package Currency Check - $date GMT";
395 $headers = "From: bdubbs@linuxfromscratch.org";
396
397 $message = "Package LFS Upstream Flag\n\n";
398
399 foreach ( $dirs as $pkg => $dir )
400 {
401 //if ( $pkg != "gmp" ) continue; //debug
402 $v = get_packages( $pkg, $dir );
403
404 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
405
406 // Pad for output
407 $pad = " ";
408 $p = substr( $pkg . $pad, 0, 15 );
409 $l = substr( $vers[ $pkg ] . $pad, 0, 10 );
410 $c = substr( $v . $pad, 0, 10 );
411
412 $message .= "$p $l $c $flag\n";
413 }
414
415 exec ( "echo '$message' | mailx -r $from -s '$subject' $to" );
416}
417
418function html()
419{
420
421 global $date;
422 global $vers;
423 global $dirs;
424
425 echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
426 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
427<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
428<head>
429<title>LFS Package Currency Check - $date</title>
430<style type='text/css'>
431h1, h2 {
432 text-align : center;
433}
434
435table {
436 border-width : 1px;
437 border-spacing : 0px;
438 border-style : outset;
439 border-color : gray;
440 border-collapse : separate;
441 background-color: white;
442 margin : 0px auto;
443}
444
445table th {
446 border-width : 1px;
447 padding : 2px;
448 border-style : inset;
449 border-color : gray;
450 background-color: white;
451}
452
453table td {
454 border-width : 1px;
455 padding : 2px;
456 border-style : inset;
457 border-color : gray;
458 background-color: white;
459}
460</style>
461
462</head>
463<body>
464<h1>LFS Package Currency Check</h1>
465<h2>As of $date GMT</h1>
466
467<table>
468<tr><th>LFS Package</th> <th>LFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
469
470 // Get the latest version of each package
471 foreach ( $dirs as $pkg => $dir )
472 {
473 $v = get_packages( $pkg, $dir );
474 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
475 echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n";
476 }
477
478 echo "</table>
479</body>
480</html>\n";
481
482}
483
484function write_to_stdout()
485{
486
487 global $date;
488 global $vers;
489 global $dirs;
490
491 echo "
492LFS Package Currency Check
493As of $date GMT
494
495LFS Package LFS Version Latest Flag\n";
496
497 // Get the latest version of each package
498 foreach ( $dirs as $pkg => $dir )
499 {
500 $p_name = sprintf( "%-15s", $pkg ); // package name formatted
501
502 $b_version = $vers[ $pkg ]; // book version
503 $b_string = sprintf( "%-11s", $b_version ); // book version formatted
504
505 $latest = get_packages( $pkg, $dir ); // latest version
506 $l_string = sprintf( "%-6s", $latest ); // latest version formatted
507
508 $flag = ( $b_version != $latest ) ? "*" : "";
509 echo "$p_name $b_string $l_string $flag\n";
510 }
511}
512
513get_current(); // Get what is in the book
514mail_to_lfs();
515//html(); // Write html output
516//write_to_stdout(); // For debugging
517?>
Note: See TracBrowser for help on using the repository browser.