Ejemplo n.º 1
0
function get_packages($package, $dirpath)
{
    global $regex;
    global $book_index;
    global $url_fix;
    global $current;
    global $previous;
    if (isset($current) && $book_index != "{$current}") {
        return 0;
    }
    // Fix up directory path
    foreach ($url_fix as $u) {
        $replace = $u['replace'];
        $match = $u['match'];
        if (isset($u['pkg'])) {
            if ($package == $u['pkg']) {
                $dirpath = preg_replace("/{$match}/", "{$replace}", $dirpath);
                break;
            }
        } else {
            if (preg_match("/{$match}/", $dirpath)) {
                $dirpath = preg_replace("/{$match}/", "{$replace}", $dirpath);
                break;
            }
        }
    }
    // Check for ftp
    if (preg_match("/^ftp/", $dirpath)) {
        // glib type packages
        if ($book_index == "pygobject1" || $book_index == "pygobject" || $book_index == "pygtk" || $book_index == "pyatspi") {
            // Parent listing
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            $lines = http_get_file("{$dirpath}/");
            if ($book_index == "pygobject") {
                $dir = find_even_max($lines, '/^2[\\d\\.]+$/', '/^(2[\\d\\.]+)$/');
            } else {
                $dir = find_even_max($lines, '/^[\\d\\.]+$/', '/^([\\d\\.]+)$/');
            }
            $dirpath .= "/{$dir}/";
        }
        // gcc and similar
        if ($book_index == "gcc") {
            // Get the max directory and adjust the directory path
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            $lines = http_get_file("{$dirpath}/");
            return find_max($lines, "/gcc-\\d/", "/^.*gcc-(\\d[\\d\\.]+).*\$/");
        }
        // slang
        if ($book_index == "slang") {
            // Get the max directory and adjust the directory path
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position) . "/latest";
        }
        if ($book_index == "vala") {
            // Get the max directory and adjust the directory path
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            $lines = http_get_file("{$dirpath}/");
            $dir = find_even_max($lines, "/\\d[\\d\\.]+/", "/^(\\d[\\d\\.]+).*/");
            $dirpath .= "/{$dir}/";
        }
        if ($book_index == "cvs") {
            // Get the max directory
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            $lines = http_get_file("{$dirpath}/");
            return find_max($lines, "/\\d\\.[\\d\\.]+/", "/^.* (\\d\\.[\\d\\.]+)\$/");
        }
        // Get listing
        $lines = http_get_file("{$dirpath}/");
    } else {
        // glib type packages
        if ($book_index == "pygobject1" || $book_index == "pygobject" || $book_index == "pygtk" || $book_index == "pyatspi") {
            // Parent listing
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            $lines1 = http_get_file($dirpath);
            if ($book_index == "pygobject") {
                $dir = find_even_max($lines1, '/^\\s+2[\\d\\.]+.*$/', '/^\\s+(2[\\d\\.]+).*$/');
            } else {
                $dir = find_even_max($lines1, '/^\\s+[\\d\\.]+.*$/', '/^\\s+([\\d\\.]+).*$/');
            }
            $dirpath .= "/{$dir}/";
        }
        // Customize http directories as needed
        if ($book_index == "cmake") {
            $dirpath = max_parent($dirpath, 'v');
            $prev = $previous;
            // Special if there is no current version in $dirpath
            $lines = http_get_file($dirpath);
            $max = find_max($lines, "/{$package}/", "/^.*{$package}-([\\d\\.]*\\d)\\.tar.*\$/");
            if ($max != 0) {
                return $max;
            }
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position) . "/{$prev}";
        }
        if ($package == "npapi-sdk") {
            # We have to process the stupid javascript to get this to work
            exec("lynx -dump  {$dirpath}", $output);
            $max = find_max($output, "/npapi-sdk/", "/^.*npapi-sdk-([\\d\\.]*\\d)\\.tar.*\$/");
            return $max;
        }
        $strip = "yes";
        $lines = http_get_file($dirpath, $strip);
        if (!is_array($lines)) {
            return $lines;
        }
    }
    // End fetch
    if (isset($regex[$package])) {
        // Custom search for latest package name
        foreach ($lines as $l) {
            if (preg_match('/^\\h*$/', $l)) {
                continue;
            }
            $ver = preg_replace($regex[$package], "\$1", $l);
            if ($ver == $l && !preg_match('/^\\d\\.[\\d\\.]+$/', $ver)) {
                continue;
            }
            if ($book_index == "exiv") {
                $ver = "2-{$ver}";
            }
            return $ver;
            // Return first match of regex
        }
        return 0;
        // This is an error
    }
    if ($book_index == "doxygen") {
        return find_max($lines, '/doxygen/', '/^.*doxygen-([\\d\\.]+).src.tar.*$/');
    }
    if ($book_index == "llvm") {
        return find_max($lines, "/^.*{$book_index}-.*.src.*\$/", "/^.*{$book_index}-([\\d\\.]+)\\.src.*\$/");
    }
    if ($book_index == "elfutils") {
        return find_max($lines, "/^\\s*\\d[\\d\\.]+\\/.*\$/", "/^\\s*(\\d[\\d\\.]+)\\/.*\$/");
    }
    if ($book_index == "nasm") {
        return find_max($lines, '/^\\d/', '/^(\\d[\\d\\.]+\\d)\\/.*$/');
    }
    #  if ( $book_index == "python" || $book_index == "python1" )  // python docs
    #  {
    #    return find_max( $lines, "/python-\d/",
    #                             "/^python-(\d[\d\.]*\d)-docs.*$/" );
    #  }
    if ($book_index == "cmake") {
        $max = find_max($lines, "/{$package}/", "/^.*{$package}-([\\d\\.]*\\d)\\.tar.*\$/");
        if ($max == 0) {
            $max = find_max($lines, "/{$package}/", "/^.*{$package}-(\\d[\\d\\.]*\\d-rc\\d).*\$/");
        }
        return $max != 0 ? $max : "pending";
    }
    if ($book_index == "pygobject1" || $book_index == "pygobject ") {
        $package = "pygobject";
    }
    if ($book_index == "librep") {
        return find_max($lines, "/librep/", "/^.*[_-](\\d[\\d\\.]*\\d)\\.tar.*\$/");
    }
    if ($book_index == "apache-ant") {
        return find_max($lines, "/{$package}/", "/^.*{$package}-(\\d[\\d\\.]+\\d)-src.*\$/");
    }
    if ($book_index == "tk") {
        $dir = find_max($lines, '/\\d\\.[\\d\\.]+\\d/', '/^\\s+(\\d\\.[\\d\\.]+\\d).*$/');
        $lines = http_get_file("{$dirpath}/{$dir}");
        return find_max($lines, "/{$package}/", "/^.*{$package}([\\d\\.]*\\d)-src.tar.*\$/");
    }
    // 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;
}
Ejemplo n.º 2
0
function get_packages($package, $dirpath)
{
    global $regex;
    global $book_index;
    global $url_fix;
    global $current;
    if (isset($current) && $book_index != "{$current}") {
        return 0;
    }
    // Fix up directory path
    foreach ($url_fix as $u) {
        $replace = $u['replace'];
        $match = $u['match'];
        if (isset($u['pkg'])) {
            if ($package == $u['pkg']) {
                $dirpath = preg_replace("/{$match}/", "{$replace}", $dirpath);
                break;
            }
        } else {
            if (preg_match("/{$match}/", $dirpath)) {
                $dirpath = preg_replace("/{$match}/", "{$replace}", $dirpath);
                break;
            }
        }
    }
    // Check for ftp
    if (preg_match("/^ftp/", $dirpath)) {
        if ($book_index == "bind") {
            // Get the max directory and adjust the directory path
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            // Up 1
            $lines1 = http_get_file("{$dirpath}/");
            $dir = find_max($lines1, "/\\d\$/", "/^.* ([\\d\\.P\\-]+)\$/");
            $dirpath .= "/{$dir}/";
            $lines2 = http_get_file($dirpath);
            return find_max($lines2, "/bind-/", "/^.*bind-(\\d+[\\d\\.P\\-]+).tar.*\$/");
        }
        if ($book_index == "dhcp") {
            // Get the max directory and adjust the directory path
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $position = strrpos($dirpath, "/");
            $dirpath = substr($dirpath, 0, $position);
            $lines = http_get_file("{$dirpath}/");
            $dir = find_max($lines, "/\\d\$/", "/^.* (\\d\\.[\\d\\.P\\-]+)\$/");
            $dirpath .= "/{$dir}/";
        }
        // Get listing
        $lines = http_get_file("{$dirpath}/");
    } else {
        if ($book_index == "NetworkManager") {
            // Get the max directory and adjust the directory path
            $dirpath = rtrim($dirpath, "/");
            // Trim any trailing slash
            $lines1 = http_get_file($dirpath);
            $dir = find_max($lines1, "/\\d[\\d\\.]+/", "/^\\s*(\\d[\\d\\.]+).*\$/");
            $dirpath .= "/{$dir}/";
        }
        $lines = http_get_file($dirpath);
        if (!is_array($lines)) {
            return $lines;
        }
    }
    // End fetch
    if (isset($regex[$package])) {
        // Custom search for latest package name
        foreach ($lines as $l) {
            if (preg_match('/^\\h*$/', $l)) {
                continue;
            }
            $ver = preg_replace($regex[$package], "\$1", $l);
            if ($ver == $l) {
                continue;
            }
            if ($book_index == "exiv") {
                $ver = "2-{$ver}";
            }
            return $ver;
            // Return first match of regex
        }
        return 0;
        // This is an error
    }
    if ($book_index == "dhcp") {
        return find_max($lines, '/dhcp/', '/^.*dhcp-([\\d\\.P-]+).tar.*$/');
    }
    if ($book_index == "ncftp") {
        return find_max($lines, '/ncftp/', '/^.*ncftp-([\\d\\.]+)-src.tar.*$/');
    }
    if ($book_index == "net-tools-CVS") {
        return find_max($lines, '/net-tools/', '/^.*_(\\d+).tar.*$/');
    }
    if ($book_index == "ntp") {
        $dir = max_parent($dirpath, "ntp-");
        $lines = http_get_file("{$dir}");
        return find_max($lines, '/ntp-.*tar/', '/^ntp-([\\d\\.p]+).tar.*$/');
    }
    if ($book_index == "whois") {
        return find_max($lines, '/whois_/', '/^.*whois_([\\d\\.]+).tar.*$/');
    }
    if ($book_index == "wireshark") {
        return find_even_max($lines, '/wireshark/', '/^.*wireshark-([\\d\\.]+).tar.*$/');
    }
    // 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;
}
Ejemplo n.º 3
0
function get_packages($package, $dirpath)
{
    global $exceptions;
    global $regex;
    if ($package == "vim") {
        $dirpath = "http://mirrors-usa.go-parts.com/pub/vim/unix";
    }
    // 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 -5;
                        break;
                }
            }
        }
        $lines = ftp_rawlist($conn, $path);
        ftp_close($conn);
    } else {
        // 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 == "mpc") {
            $dirpath = "http://www.multiprecision.org/index.php?prog=mpc&page=download";
        }
        if ($package == "bzip2") {
            // 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 == "expat") {
            $dirpath = "http://sourceforge.net/projects/expat/files";
        }
        if ($package == "intltool") {
            $dirpath = "https://launchpad.net/intltool/trunk";
        }
        if ($package == "procps-ng") {
            $dirpath = "http://sourceforge.net/projects/procps-ng/files";
        }
        if ($package == "e2fsprogs") {
            $dirpath = "http://sourceforge.net/projects/e2fsprogs/files/e2fsprogs";
        }
        if ($package == "expect" || $package == "flex" || $package == "psmisc") {
            $dirpath = "http://sourceforge.net/projects/{$package}/files";
        }
        if ($package == "tcl-core") {
            $dirpath = "http://sourceforge.net/projects/tcl/files";
        }
        if ($package == "gcc") {
            $dirpath = max_parent($dirpath, "gcc-");
        }
        if ($package == "util-linux") {
            $dirpath = max_parent($dirpath, "v.");
        }
        $lines = http_get_file($dirpath);
        if (!is_array($lines)) {
            return -6;
        }
    }
    // 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 -7;
        // This is an error
    }
    if ($package == "shadow") {
        return find_max($lines, "/shadow-/", "/^.*shadow-([\\d\\.]*\\d).*\$/");
    }
    if ($package == "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;
    }
    if ($package == "attr" || $package == "acl") {
        return find_max($lines, "/{$package}/", "/^.*{$package}-([\\d\\.-]*\\d)\\.src.*\$/");
    }
    if ($package == "e2fsprogs") {
        return find_max($lines, "/v\\d/", "/^.*v(\\d[\\d\\.]+\\d).*\$/");
    }
    if ($package == "XML-Parser") {
        return find_max($lines, "/{$package}/", "/^.*{$package}-([\\d\\._]*\\d).tar.*\$/");
    }
    if ($package == "gmp") {
        return find_max($lines, "/{$package}/", "/^.*{$package}-([\\d\\._]*\\d[a-z]?).tar.*\$/");
    }
    if ($package == "grub") {
        return find_max($lines, "/grub/", "/^.*grub-(\\d\\..*).tar.xz.*\$/");
    }
    // Most packages are in the form $package-n.n.n
    // Occasionally there are dashes (e.g. 201-1)
    return find_max($lines, "/{$package}/", "/^.*{$package}-([\\d\\.-]*\\d)\\.tar.*\$/");
}