lfs-latest.php 15 KB

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