Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 132 lines (108 sloc) 4.241 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132
#!/usr/bin/php
<?php # $Id$
/* piece together a windows pear distro */

if (!$_SERVER['argv'][1]) {
echo "Usage: {$_SERVER['argv'][0]} dist_dir\n";
exit(1);
}

$dist_dir = $_SERVER['argv'][1];

/* very light-weight function to extract a single named file from
* a gzipped tarball. This makes assumptions about the files
* based on the PEAR info set in $packages. */
function extract_file_from_tarball($pkg, $filename, $dest_dir) /* {{{ */
{
global $packages;

$name = $pkg . '-' . $packages[$pkg];
$tarball = $dest_dir . "/" . $name . '.tgz';
$filename = $name . '/' . $filename;
$destfilename = $dest_dir . "/" . basename($filename);

$fp = gzopen($tarball, 'rb');

$done = false;
do {
/* read the header */
$hdr_data = gzread($fp, 512);
if (strlen($hdr_data) == 0)
break;
$checksum = 0;
for ($i = 0; $i < 148; $i++)
$checksum += ord($hdr_data{$i});
for ($i = 148; $i < 156; $i++)
$checksum += 32;
for ($i = 156; $i < 512; $i++)
$checksum += ord($hdr_data{$i});

$hdr = unpack("a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor", $hdr_data);

$hdr['checksum'] = octdec(trim($hdr['checksum']));

if ($hdr['checksum'] != $checksum) {
echo "Checksum for $tarball $hdr[filename] is invalid\n";
print_r($hdr);
return;
}

$hdr['size'] = octdec(trim($hdr['size']));
echo "File: $hdr[filename] $hdr[size]\n";

if ($filename == $hdr['filename']) {
echo "Found the file we want\n";
$dest = fopen($destfilename, 'wb');
$x = stream_copy_to_stream($fp, $dest, $hdr['size']);
fclose($dest);
echo "Wrote $x bytes into $destfilename\n";
break;
}

/* skip body of the file */
$size = 512 * ceil((int)$hdr['size'] / 512);
echo "Skipping $size bytes\n";
gzseek($fp, gztell($fp) + $size);

} while (!$done);

} /* }}} */

echo "Creating PEAR in $dist_dir\n";

/* Let's do a PEAR-less pear setup */
if (!file_exists($dist_dir)) {
    mkdir($dist_dir);
}
if (!file_exists($dist_dir)) {
    die("could not make $dist_dir");
}
mkdir("$dist_dir/PEAR");
mkdir("$dist_dir/PEAR/go-pear-bundle");

/* grab the bootstrap script */
echo "Downloading go-pear\n";
copy("http://pear.php.net/go-pear", "$dist_dir/PEAR/go-pear.php");
echo "Downloading go-pear.bat\n";
copy("http://cvs.php.net/viewvc.cgi/pear-core/scripts/go-pear.bat?revision=1.1", "$dist_dir/go-pear.bat");

/* This is a list of packages and versions
* that will be used to create the PEAR folder
* in the windows snapshot.
*/
$packages = array(
// required packages for the installer
"PEAR" => "1.5.1",
"Console_Getopt" => "1.2.1",
"Archive_Tar" => "1.3.2",
"Structures_Graph" => "1.0.2",

// required packages for the web frontend
"PEAR_Frontend_Web" => "0.5.1",
"HTML_Template_IT" => "1.1.4",
"Net_UserAgent_Detect" => "2.0.1",
);


/* download the packages into the destination */
echo "Fetching packages\n";

foreach ($packages as $name => $version) {
$filename = "$name-$version.tgz";
$destfilename = "$dist_dir/PEAR/go-pear-bundle/$filename";
if (file_exists($destfilename))
continue;
$url = "http://pear.php.net/get/$filename";
echo "Downloading $name from $url\n";
flush();
copy($url, $destfilename);
}

echo "Download complete. Extracting bootstrap files\n";

/* Now, we want PEAR.php, Getopt.php (Console_Getopt) and Tar.php (Archive_Tar)
* broken out of the tarballs */
extract_file_from_tarball('PEAR', 'PEAR.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Archive_Tar', 'Archive/Tar.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Console_Getopt', 'Console/Getopt.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Structures_Graph', 'Structures/Graph.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Structures_Graph', 'Structures/Graph/Node.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Structures_Graph', 'Structures/Graph/Manipulator/AcyclicTest.php', "$dist_dir/PEAR/go-pear-bundle");
extract_file_from_tarball('Structures_Graph', 'Structures/Graph/Manipulator/TopologicalSorter.php', "$dist_dir/PEAR/go-pear-bundle");
?>
Something went wrong with that request. Please try again.