source: lfs-latest.php@ 56fb88f6

10.0 10.0-rc1 10.1 10.1-rc1 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 9.1 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 56fb88f6 was 912108f, checked in by Bruce Dubbs <bdubbs@…>, 4 years ago

Update currency for zstd

git-svn-id: http://svn.linuxfromscratch.org/LFS/trunk/BOOK@11728 4aa44e1e-78dd-0310-a6d2-fbcd4c07a689

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