source: lfs-latest.php@ 98d9003

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 8.1 8.2 8.3 8.4 9.0 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 98d9003 was 5d4c24a, checked in by Bruce Dubbs <bdubbs@…>, 7 years ago

Add currency script to LFS repo

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

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