/opensource.apple.com/source/apache_mod_php/apache_mod_php-18.9/php/pear/make-pear-bundle.php
PHP | 139 lines | 104 code | 22 blank | 13 comment | 16 complexity | e39117fa61248fc6728553cb5f030ee3 MD5 | raw file
Possible License(s): LGPL-2.0, MPL-2.0, GPL-2.0, ISC, LGPL-2.1, Apache-2.0, MPL-2.0-no-copyleft-exception, BSD-3-Clause, WTFPL, MIT, AGPL-1.0, AGPL-3.0
- <!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>make-pear-bundle.php</title>
- <style type="text/css">
- .enscript-comment { font-style: italic; color: rgb(178,34,34); }
- .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
- .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
- .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
- .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
- .enscript-string { font-weight: bold; color: rgb(188,143,143); }
- .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
- .enscript-type { font-weight: bold; color: rgb(34,139,34); }
- .enscript-highlight { text-decoration: underline; color: 0; }
- </style>
- </head>
- <body id="top">
- <h1 style="margin:8px;" id="f1">make-pear-bundle.php <span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
- <hr/>
- <div></div>
- <pre>
- #!/usr/bin/php
- <?php # $Id: make-pear-bundle.php,v 1.2.2.2 2006/08/18 12:44:27 pajoye Exp $
- /* piece together a windows pear distro */
-
- if (!$argv[1] || !$argv[2]) {
- echo "Usage: {$argv[0]} dist_dir src_dir\n";
- exit(1);
- }
-
- $dist_dir = $argv[1];
- $cvs_dir = $argv[2];
-
- /* 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("<a href="http://go-pear.org/">http://go-pear.org/</a>", "$dist_dir/PEAR/go-pear.php");
- echo "Downloading go-pear.bat\n";
- copy("$cvs_dir/pear/go-pear.bat", "$dist_dir/go-pear.bat");
-
- /* import the package list -- sets $packages variable */
- include $cvs_dir . "/pear/go-pear-list.php";
-
- /* 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 = "<a href="http://pear.php.net/get/">http://pear.php.net/get/</a>$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");
- ?>
- </pre>
- <hr />
- </body></html>