#!/usr/bin/php 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" ); $cdir = getcwd(); chdir( $tmpdir ); exec ( "git clone --quiet $clfsgit" ); chdir( $cdir ); $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 "; $subject = "CLFS GIT Standard Package Currency Check - $date GMT"; $headers = "From: William Harrington $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 " CLFS GIT Package Currency Check - $date

CLFS GIT Package Currency Check

As of $date GMT

\n"; // Get the latest version of each package foreach ( $dirs as $pkg => $dir ) { $v = get_packages( $pkg, $dir ); $flag = ( $vers[ $pkg ] != $v ) ? "*" : ""; echo "\n"; } echo "
CLFS GIT Package CLFS GIT Version Latest Flag
$pkg ${vers[ $pkg ]} $v $flag
\n"; } get_current(); // Get what is in the book mail_to_clfs(); //html(); // Write html output ?>