Update to firefox-78.10.0 in svn
[beyond_linux_from_scratch.git] / scripts / blfs-include.php
blobd1f0d01c29106ecdb7ae40692938a3268410a423
1 <?php
3 /* This include file needs the following to be defined externally:
5 HTML_DIR environment variable -- where to put html output
6 WGET_DIR environment variable -- where to find wget-list
8 $renames array of changes from extracted package name to
9 desired display name
11 $ignores array of packages to ignore
13 $START_PACKAGE first package in wget-list to evaluate
14 $STOP_PACKAGE last package in wget-list to evaluate
16 $CHAPTER string chapter number e.g. "4"
18 get_pattern() function to extract package name from wget-list line
22 $book = array();
23 $book_index = 0;
25 $vers = array();
27 date_default_timezone_set( "GMT" );
28 $date = date( "Y-m-d (D) H:i:s" );
30 $d = getenv( 'HTML_DIR' );
31 $HTML_DIR = ($d) ? $d : '.';
33 $d = getenv( 'WGET_DIR' );
34 $WGET_DIR = ($d) ? $d : '.';
36 $start = false;
38 function find_max( $lines, $regex_match, $regex_replace, $skip_high = FALSE )
40 $a = array();
41 foreach ( $lines as $line )
43 if ( ! preg_match( $regex_match, $line ) ) continue;
44 //echo "line=$line\n";
45 // Isolate the version and put in an array
46 $slice = preg_replace( $regex_replace, "$1", $line );
47 //echo "slice=$slice\n";
48 if ( "x$slice" == "x$line" &&
49 ! preg_match( "/^\d[\d\.]*$/", $slice ) ) continue;
50 //echo "found\n";
51 // Skip minor versions in the 90s if requested
52 if ( $skip_high )
54 list( $major, $minor, $micro, $rest ) = explode( ".", $slice . ".0.0.0.0" );
55 if ( $micro >= 80 ) continue;
56 if ( $minor >= 80 ) continue;
59 array_push( $a, $slice );
62 // SORT_NATURAL requires php-5.4.0 or later
63 rsort( $a, SORT_NATURAL ); // Max version is at the top
65 return ( isset( $a[0] ) ) ? $a[0] : 0;
68 function find_even_max( $lines, $regex_match, $regex_replace )
70 $a = array();
71 foreach ( $lines as $line )
73 if ( ! preg_match( $regex_match, $line ) ) continue;
75 // Isolate the version and put in an array
76 $slice = preg_replace( $regex_replace, "$1", $line );
78 if ( "x$slice" == "x$line" ) continue;
80 // Remove trailing things like -P2
81 $slice1 = preg_replace( "/^(.*)-.*$/", "$1", $slice );
83 // Skip odd numbered minor versions and minors > 80
84 // Sometimes there is no period in $slice
85 if ( preg_match( "/\./", $slice1 ) )
87 list( $major, $minor, $other ) = explode( ".", $slice1 . ".0", 3 );
88 if ( $minor % 2 == 1 ) continue;
89 if ( $minor > 80 ) continue;
92 array_push( $a, $slice );
95 // SORT_NATURAL requires php-5.4.0 or later
96 rsort( $a, SORT_NATURAL ); // Max version is at the top
98 return ( isset( $a[0] ) ) ? $a[0] : 0;
101 function find_odd_max( $lines, $regex_match, $regex_replace )
103 $a = array();
104 foreach ( $lines as $line )
106 if ( ! preg_match( $regex_match, $line ) ) continue;
108 // Isolate the version and put in an array
109 $slice = preg_replace( $regex_replace, "$1", $line );
111 if ( "x$slice" == "x$line" ) continue;
113 // Skip even numbered minor versions and minors > 80
114 list( $major, $minor ) = explode( ".", $slice . ".0", 2 );
115 if ( $minor % 2 == 0 ) continue;
116 if ( $minor > 80 ) continue;
118 array_push( $a, $slice );
121 // SORT_NATURAL requires php-5.4.0 or later
122 rsort( $a, SORT_NATURAL ); // Max version is at the top
124 return ( isset( $a[0] ) ) ? $a[0] : 0;
127 function backup_dir( $path, $dirlen, $diff )
129 $path = rtrim ( $path, "/" ); // Trim any trailing slash
130 $position = strrpos( $path, "/" );
131 $basedir = substr ( $path, 0, $position );
132 $lastdir = substr ( $path, -$dirlen ); // last $dirlen characters
133 $precision= $dirlen - 2;
134 $format = "%$dirlen.${precision}f";
135 $newdir = sprintf( $format, (float)$lastdir - $diff ); // backup
136 $fullpath = $basedir . "/" . $newdir;
137 // Get values from that diretory
138 $newlines = http_get_file( "$fullpath/" );
139 return $newlines;
142 function http_get_file( $url )
144 if ( preg_match( "/graphviz/", $url ) ||
145 preg_match( "/libgcrypt/",$url ) ||
146 preg_match( "/libksba/", $url ) ||
147 preg_match( "/swig/", $url ) ||
148 preg_match( "/ntfs/", $url ) ||
149 preg_match( "/docutils/", $url ) ||
150 preg_match( "/vsftpd/", $url ) ||
151 preg_match( "/php/", $url ) ||
152 preg_match( "/xfce4-pulseaudio-plugin/", $url ) ||
153 preg_match( "/llvm/", $url ) )
155 exec( "links -dump $url", $lines );
156 return $lines;
159 // Do not strip tags
160 if ( preg_match( "/gpm/", $url ) ||
161 preg_match( "/libvdpau/", $url ) ||
162 preg_match( "/shared-mime-info/", $url ) ||
163 preg_match( "/imagemagick/", $url ) ||
164 preg_match( "/w1.fi/", $url ) ||
165 preg_match( "/allbsd/", $url ) || // paxmirabilis
166 preg_match( "/alsa/", $url ) )
168 exec( "wget -q --no-check-certificate -O- $url", $dir );
169 return $dir;
172 if ( preg_match( "/ntfs-3g/", $url ) )
174 exec( "curl -L -s -m40 -A Firefox/41.0 $url", $page );
175 #$s = implode( "\n", $dir );
176 #$dir = strip_tags( $s );
177 #$strip = explode( "\n", $dir );
178 return $page;
181 if ( preg_match( "/gc_source/", $url ) ||
182 preg_match( "/abisource/", $url ) )
184 exec( "wget -q --no-check-certificate -O- $url", $dir );
185 $s = implode( "\n", $dir );
186 $dir = strip_tags( $s );
187 $strip = explode( "\n", $dir );
188 return $strip;
191 if ( ! preg_match( "/sourceforge/", $url ) ||
192 preg_match( "/jfs/", $url ) ||
193 preg_match( "/liba52/", $url ) ||
194 preg_match( "/cracklib/", $url ) ||
195 preg_match( "/libmpeg2/", $url ) ||
196 preg_match( "/tcl/", $url ) ||
197 preg_match( "/tk/", $url ) ||
198 preg_match( "/docutils/", $url ) ||
199 preg_match( "/expect/", $url ) )
201 exec( "curl -4 -L -s -m40 -A Firefox/41.0 $url", $dir );
202 $s = implode( "\n", $dir );
203 $dir = strip_tags( $s );
204 $strip = explode( "\n", $dir );
205 //print_r($strip);
206 return $strip;
208 else if ( preg_match( "/scons/", $url ) )
210 exec( "wget -q -O- $url", $dir );
211 $s = implode( "\n", $dir );
212 $dir = strip_tags( $s );
213 $strip = explode( "\n", $dir );
214 //print_r($strip);
215 return $strip;
217 else
219 //echo "url=$url\n";
220 exec( "links -dump $url", $lines );
221 return $lines;
225 function max_parent( $dirpath, $prefix )
227 // First, remove a directory
228 $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash
229 $position = strrpos( $dirpath, "/" );
230 $dirpath = substr ( $dirpath, 0, $position );
232 $lines = http_get_file( $dirpath );
234 $regex_match = "#${prefix}[\d\.]+/#";
235 $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#";
236 $max = find_max( $lines, $regex_match, $regex_replace );
238 return "$dirpath/$max";
241 function get_current()
243 global $vers;
244 global $book;
245 global $START_PACKAGE;
246 global $STOP_PACKAGE;
247 global $WGET_DIR;
248 global $start;
250 $wget_file = "$WGET_DIR/wget-list";
252 $contents = file_get_contents( $wget_file );
253 $wget = explode( "\n", $contents );
255 foreach ( $wget as $line )
257 if ( $line == "" ) continue;
258 if ( preg_match( "/patch/", $line ) ) continue; // Skip patches
259 if ( preg_match( "/metacpan/", $line ) ) continue; // Skip perl depeperl dependenciess
261 $file = basename( $line );
262 $url = dirname ( $line );
264 $file = preg_replace( "/\.tar\..z.*$/", "", $file ); // Remove .tar.?z*$
265 $file = preg_replace( "/\.tar$/", "", $file ); // Remove .tar$
266 $file = preg_replace( "/\.gz$/", "", $file ); // Remove .gz$
267 $file = preg_replace( "/\.orig$/", "", $file ); // Remove .orig$
268 $file = preg_replace( "/\.src$/", "", $file ); // Remove .src$
269 $file = preg_replace( "/\.tgz$/", "", $file ); // Remove .tgz$
271 if ( preg_match( "/php_manual/", $file ) ) continue;
273 $pattern = get_pattern( $file );
275 // Workaround because graphviz does not have version in filename
276 if ( preg_match( "/graphviz/", $file ) )
278 $file = preg_replace( '/graphviz/', "graphviz-$pattern", $file );
279 $pattern = '/\D*(\d.*\d)\D*$/';
282 $version = preg_replace( $pattern, "$1", $file ); // Isolate version
283 $version = preg_replace( "/^-/", "", $version ); // Remove leading #-
285 $basename = strstr( $file, $version, true );
286 $basename = rtrim( $basename, "-" );
287 $basename = rtrim( $basename, "_" );
289 if ( $basename == $START_PACKAGE ) $start = true;
290 if ( ! $start ) continue;
292 // Custom for tidy in Chapter 11 (github is not friendly)
293 //if ( preg_match( "/tidy-html/", $line ) )
295 // $version = $file;
296 // $basename = 'tidy';
299 // Custom for tripwire/github
300 if ( preg_match( "/tripwire/", $line ) )
301 $basename = 'tripwire';
303 // Custom for Chapter 10
304 if ( preg_match( "/opencv_contrib/", $line ) )
305 $basename = 'opencv_contrib';
307 // Custom for Chapter 43
308 if ( preg_match( "/chromium-launcher/", $line ) )
309 $basename = 'chromium-launcher';
311 // Custom for Chapter 55
312 if ( $version == "install-tl-unx" )
314 $version = "Unversioned";
315 $basename = "install-tl-unx";
318 if ( preg_match( "/biber/", $line ) )
319 $basename = "biber";
321 if ( preg_match( "/hg\.mozilla\.org/", $line ) )
322 $basename = "firefox";
324 // Skip chromium-freetype
325 if ( preg_match( "/chromium-freetype/", $line ) ) continue;
327 // Skip UCD.zip in ibus package
328 if ( preg_match( "/UCD/", $line ) ) continue;
330 if ( $version == "biblatex-biber" )
332 $version = basename( $url );
333 $basename = "biblatex-biber";
336 if ( $basename == "fontforge-dist" )
338 //$version = basename( $url );
339 $basename = "fontforge";
342 $index = $basename;
343 while ( isset( $book[ $index ] ) ) $index .= "1";
345 if ( $index == "fuse1" ) $basename = "fuse1";
347 $book[ $index ] = array( 'basename' => $basename,
348 'url' => $url,
349 'version' => $version );
351 // Custom for chapter 12 -- there is both p7zip, unzip, and zip there
352 if ( preg_match( "/p7zip|unzip/", $line ) ) continue;
354 // Custom for chapter 30 -- there is both yelp and yelp-sxl
355 if ( preg_match( "/yelp-xsl/", $line ) ) continue;
357 if ( preg_match( "/$STOP_PACKAGE/", $line ) ) break;
361 function html()
363 global $book;
364 global $date;
365 global $vers;
366 global $CHAPTER;
367 global $CHAPTERS;
368 global $HTML_DIR;
369 global $renames;
370 global $ignores;
372 $leftnav = file_get_contents( 'leftnav.html' );
374 $f = "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'
375 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'>
376 <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'>
377 <head>
378 <title>BLFS Chapter 4 Package Currency Check - $date</title>
379 <link rel='stylesheet' href='currency.css' type='text/css' />
380 </head>
381 <body>
382 $leftnav
383 <h1>BLFS $CHAPTERS Package Currency Check</h1>
384 <h2>As of $date GMT</h2>
386 <table>
387 <tr><th>BLFS Package</th> <th>BLFS Version</th> <th>Latest</th> <th>Flag</th></tr>\n";
389 // Get the latest version of each package
390 foreach ( $vers as $pkg => $v )
392 $v = $book[ $pkg ][ 'version' ];
393 $flag = ( $vers[ $pkg ] != $v ) ? "*" : "";
395 $name = $pkg;
397 foreach ( $renames as $n => $newname )
399 if ( $pkg == $n ) $name = $newname;
402 if ( isset( $ignores[ $pkg ] ) ) continue;
404 $f .= "<tr><td>$name</td>";
405 $f .= "<td>$v</td>";
406 $f .= "<td>${vers[ $pkg ]}</td>";
407 $f .= "<td class='center'>$flag</td></tr>\n";
410 $f .= "</table>
411 </body>
412 </html>\n";
414 file_put_contents( "$HTML_DIR/chapter$CHAPTER.html", $f );