diff options
-rw-r--r-- | clfs-systemd-latest-files.php | 387 |
1 files changed, 387 insertions, 0 deletions
diff --git a/clfs-systemd-latest-files.php b/clfs-systemd-latest-files.php new file mode 100644 index 0000000..fa882dd --- /dev/null +++ b/clfs-systemd-latest-files.php @@ -0,0 +1,387 @@ +#!/usr/bin/php +<?php +$dirs = array(); +$vers = array(); + +date_default_timezone_set( "America/Chicago" ); +$date = date( "Y-m-d H:i:s" ); + +// Special cases +$exceptions = array(); +$exceptions[ 'gmp' ] = "UPDIR=/.*(gmp-\d[\d\.-]*\d).*/:DOWNDIR="; + +$regex = array(); +$regex[ 'bzip2' ] = "/^.*current version is ([\d\.]+).*$/"; +$regex[ 'expect' ] = "/^.*Download expect([\d\.]+)\.tar.*$/"; +$regex[ 'less' ] = "/^.*current released version is less-(\d+).*$/"; +$regex[ 'mpc' ] = "/^Version ([\d\.]+).*$/"; +$regex[ 'mpfr' ] = "/^mpfr-([\d\.]+)\.tar.*$/"; +$regex[ 'sysvinit' ] = "/^.*sysvinit-([\d\.]+)dsf\.tar.*$/"; +$regex[ 'tcl' ] = "/^.*Download tcl([\d\.]+)-src.*$/"; +$regex[ 'tzdata' ] = "/^.*tzdata([\d]+[a-z]).*$/"; +$regex[ 'xz' ] = "/^.*xz-([\d\.]*\d).*$/"; +$regex[ 'zlib' ] = "/^.*zlib ([\d\.]*\d).*$/"; + +function find_max( $lines, $regex_match, $regex_replace ) +{ + $a = array(); + foreach ( $lines as $line ) + { + if ( ! preg_match( $regex_match, $line ) ) continue; + + // Isolate the version and put in an array + $slice = preg_replace( $regex_replace, "$1", $line ); + if ( $slice == $line ) continue; + + array_push( $a, $slice ); + } + + // SORT_NATURAL requires php-5.4.0 or later + rsort( $a, SORT_NATURAL ); // Max version is at the top + return ( isset( $a[0] ) ) ? $a[0] : 0; +} + +function http_get_file( $url ) +{ + $r = new HttpRequest( $url, HttpRequest::METH_GET ); + $r->setOptions( array('redirect' => 3) ); + + try + { + $r->send(); + if ($r->getResponseCode() == 200) + { + $dir = $r->getResponseBody(); + } + else + { + //echo "Respose code " . $r->getResponseCode() . "($package)\n"; + //echo $r->getResponseBody() . "($package)\n"; + return "-2"; + } + } + catch (HttpException $ex) + { + //echo $ex; + return "-3"; + } + + $dir = strip_tags( $dir ); + return explode( "\n", $dir ); // An array of lines from the url +} + +function max_parent( $dirpath, $prefix ) +{ + // First, remove a directory + $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash + $position = strrpos( $dirpath, "/" ); + $dirpath = substr ( $dirpath, 0, $position ); + + $lines = http_get_file( $dirpath ); + + $regex_match = "#${prefix}[\d\.]+/#"; + $regex_replace = "#^.*(${prefix}[\d\.]+)/.*$#"; + $max = find_max( $lines, $regex_match, $regex_replace ); + + return "$dirpath/$max"; +} + +function get_packages( $package, $dirpath ) +{ + global $exceptions; + global $regex; + + // Check for ftp + if ( preg_match( "/^ftp/", $dirpath ) ) + { + $dirpath = substr( $dirpath, 6 ); // Remove ftp:// + $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash + $position = strpos( $dirpath, "/" ); // Divide at first slash + $server = substr( $dirpath, 0, $position ); + $path = substr( $dirpath, $position ); + + $conn = ftp_connect( $server ); + ftp_login( $conn, "anonymous", "" ); + + // See if we need special handling + if ( isset( $exceptions[ $package ] ) ) + { + $specials = explode( ":", $exceptions[ $package ] ); + + foreach ( $specials as $i ) + { + list( $op, $regexp ) = explode( "=", $i ); + + switch ($op) + { + case "UPDIR": + // Remove last dir from $path + $position = strrpos( $path, "/" ); + $path = substr( $path, 0, $position ); + + // Get dir listing + $lines = ftp_rawlist ($conn, $path); + $max = find_max( $lines, $regexp, $regexp ); + break; + + case "DOWNDIR": + // Append found directory + $path .= "/$max"; + break; + + default: + echo "Error in specials array for $package\n"; + return 0; + break; + } + } + } + + $lines = ftp_rawlist ($conn, $path); + ftp_close( $conn ); + } + else // http + { + // Customize http directories as needed + if ( $package == "tzdata" ) + { + // Remove two directories + $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash + $position = strrpos( $dirpath, "/" ); + $dirpath = substr ( $dirpath, 0, $position ); + $position = strrpos( $dirpath, "/" ); + $dirpath = substr ( $dirpath, 0, $position ); + //echo "$dirpath\n"; + } + + if ( $package == "bzip2" || + $package == "mpc" ) + { + // Remove one directory + $dirpath = rtrim ( $dirpath, "/" ); // Trim any trailing slash + $position = strrpos( $dirpath, "/" ); + $dirpath = substr ( $dirpath, 0, $position ); + //echo "$dirpath\n"; + } + + if ( $package == "mpfr" ) + { + $dirpath = "http://mpfr.loria.fr/mpfr-current"; + } + + if ( $package == "e2fsprogs" || + $package == "expect" || + $package == "flex" || + $package == "tcl" || + $package == "psmisc" ) + { + $dirpath = "http://sourceforge.net/projects/$package/files"; + } + + if ( $package == "gcc" ) $dirpath = max_parent( $dirpath, "gcc-" ); + if ( $package == "util-linux" ) $dirpath = max_parent( $dirpath, "v." ); + + $lines = http_get_file( $dirpath ); + } // End fetch + + if ( isset( $regex[ $package ] ) ) + { + // Custom search for latest package name + foreach ( $lines as $l ) + { + $ver = preg_replace( $regex[ $package ], "$1", $l ); + if ( $ver == $l ) continue; + return $ver; // Return first match of regex + } + + return 0; // This is an error + } + + if ( $package == "perl" ) // Custom for perl + { + $tmp = array(); + + foreach ( $lines as $l ) + { + if ( preg_match( "/sperl/", $l ) ) continue; // Don't want this + $ver = preg_replace( "/^.*perl-([\d\.]+\d)\.tar.*$/", "$1", $l ); + if ( $ver == $l ) continue; + list( $s1, $s2, $rest ) = explode( ".", $ver ); + if ( $s2 % 2 == 1 ) continue; // Remove odd minor versions + array_push( $tmp, $l ); + } + + $lines = $tmp; + } + + // Most packages are in the form $package-n.n.n + // Occasionally there are dashes (e.g. 201-1) + $max = find_max( $lines, "/$package/", "/^.*$package-([\d\.-]*\d)\.tar.*$/" ); + return $max; +} + +function get_current() +{ + global $dirs; + global $vers; + + // Fetch from git and get wget-list + $current = array(); + $clfsgit = "git://git.cross-lfs.org/cross-lfs.git"; + + $tmpdir = exec( "mktemp -d /tmp/clfscheck.XXXXXX" ); + $chkout = "$tmpdir/cross-lfs"; + $cdir = getcwd(); + chdir( $tmpdir ); + exec ( "git clone --quiet $clfsgit" ); + chdir( $chkout ); + exec ( "git checkout --quiet systemd" ); + chdir( $tmpdir ); + + $PAGE = "$tmpdir/cross-lfs/BOOK/materials/*chapter.xml"; + $STYLESHEET = "$tmpdir/cross-lfs/BOOK/stylesheets/wget.xsl"; + + exec( "xsltproc --xinclude --nonet $STYLESHEET $PAGE | uniq", $current ); + exec( "rm -rf $tmpdir" ); + + foreach ( $current as $line ) + { + $file = basename( $line ) . "\n"; + if ( preg_match( "/patch$/", $file ) ) { continue; } // Skip patches + + $file = preg_replace( "/bz2/", '', $file ); // The 2 confusses the regex + + $file = rtrim( $file ); + $pkg_pattern = "/(\D*).*/"; + $pattern = "/\D*(\d.*\d)\D*/"; + + if ( preg_match( "/e2fsprogs/", $file ) ) + { + $pattern = "/e2\D*(\d.*\d)\D*/"; + $pkg_pattern = "/(e2\D*).*/"; + } + + else if ( preg_match( "/tzdata/", $file ) ) + { + $pattern = "/\D*(\d.*[a-z])\.tar\D*/"; + } + + $version = preg_replace( $pattern, "$1", $file ); // Isolate version + $version = preg_replace( "/^\d-/", "", $version ); // Remove leading #- + + // Touch up package names + $pkg_name = preg_replace( $pkg_pattern, "$1", $file ); + $pkg_name = trim( $pkg_name, "-" ); + + if ( preg_match( "/bzip|iproute/", $pkg_name ) ) { $pkg_name .= "2"; } + if ( preg_match( "/^m$/" , $pkg_name ) ) { $pkg_name .= "4"; } + + $dirs[ $pkg_name ] = dirname( $line ); + $vers[ $pkg_name ] = $version; + } +} + +function mail_to_clfs() +{ + global $date; + global $vers; + global $dirs; + + $to = "kb0iic@berzerkula.org"; + $from = "William Harrington <kb0iic@berzerkula.org>"; + $subject = "CLFS GIT Systemd Package Currency Check - $date GMT"; + $headers = "From: William Harrington <kb0iic@berzerkula.org"; + + $message = "Package CLFS Upstream Flag\n\n"; + + foreach ( $dirs as $pkg => $dir ) + { + //if ( $pkg != "tzdata" ) continue; //debug + $v = get_packages( $pkg, $dir ); + + $flag = ( $vers[ $pkg ] != $v ) ? "*" : ""; + + // Pad for output + $pad = " "; + $p = substr( $pkg . $pad, 0, 15 ); + $l = substr( $vers[ $pkg ] . $pad, 0, 7 ); + $c = substr( $v . $pad, 0, 10 ); + + $message .= "$p $l $c $flag\n"; + } + + //echo $message; + mail( $to, $subject, $message ); +} + +function html() +{ + + global $date; + global $vers; + global $dirs; + + echo "<!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' + 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> +<html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> +<head> +<title>CLFS GIT Package Currency Check - $date</title> +<style type='text/css'> +h1, h2 { + text-align : center; +} + +table { + border-width : 1px; + border-spacing : 0px; + border-style : outset; + border-color : gray; + border-collapse : separate; + background-color: white; + margin : 0px auto; +} + +table th { + border-width : 1px; + padding : 2px; + border-style : inset; + border-color : gray; + background-color: white; +} + +table td { + border-width : 1px; + padding : 2px; + border-style : inset; + border-color : gray; + background-color: white; +} +</style> + +</head> +<body> +<h1>CLFS GIT Package Currency Check</h1> +<h2>As of $date GMT</h1> + +<table> +<tr><th>CLFS GIT Package</th> <th>CLFS GIT Version</th> <th>Latest</th> <th>Flag</th></tr>\n"; + + // Get the latest version of each package + foreach ( $dirs as $pkg => $dir ) + { + $v = get_packages( $pkg, $dir ); + $flag = ( $vers[ $pkg ] != $v ) ? "*" : ""; + echo "<tr><td>$pkg</td> <td>${vers[ $pkg ]}</td> <td>$v</td> <td>$flag</td></tr>\n"; + } + + echo "</table> +</body> +</html>\n"; + +} + +get_current(); // Get what is in the book +mail_to_clfs(); +//html(); // Write html output +?> + |