PageRenderTime 55ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/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
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  2. "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
  3. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  4. <head>
  5. <title>make-pear-bundle.php</title>
  6. <style type="text/css">
  7. .enscript-comment { font-style: italic; color: rgb(178,34,34); }
  8. .enscript-function-name { font-weight: bold; color: rgb(0,0,255); }
  9. .enscript-variable-name { font-weight: bold; color: rgb(184,134,11); }
  10. .enscript-keyword { font-weight: bold; color: rgb(160,32,240); }
  11. .enscript-reference { font-weight: bold; color: rgb(95,158,160); }
  12. .enscript-string { font-weight: bold; color: rgb(188,143,143); }
  13. .enscript-builtin { font-weight: bold; color: rgb(218,112,214); }
  14. .enscript-type { font-weight: bold; color: rgb(34,139,34); }
  15. .enscript-highlight { text-decoration: underline; color: 0; }
  16. </style>
  17. </head>
  18. <body id="top">
  19. <h1 style="margin:8px;" id="f1">make-pear-bundle.php&nbsp;&nbsp;&nbsp;<span style="font-weight: normal; font-size: 0.5em;">[<a href="?txt">plain text</a>]</span></h1>
  20. <hr/>
  21. <div></div>
  22. <pre>
  23. #!/usr/bin/php
  24. &lt;?php # $Id: make-pear-bundle.php,v 1.2.2.2 2006/08/18 12:44:27 pajoye Exp $
  25. /* piece together a windows pear distro */
  26. if (!$argv[1] || !$argv[2]) {
  27. echo &quot;Usage: {$argv[0]} dist_dir src_dir\n&quot;;
  28. exit(1);
  29. }
  30. $dist_dir = $argv[1];
  31. $cvs_dir = $argv[2];
  32. /* very light-weight function to extract a single named file from
  33. * a gzipped tarball. This makes assumptions about the files
  34. * based on the PEAR info set in $packages. */
  35. function extract_file_from_tarball($pkg, $filename, $dest_dir) /* {{{ */
  36. {
  37. global $packages;
  38. $name = $pkg . '-' . $packages[$pkg];
  39. $tarball = $dest_dir . &quot;/&quot; . $name . '.tgz';
  40. $filename = $name . '/' . $filename;
  41. $destfilename = $dest_dir . &quot;/&quot; . basename($filename);
  42. $fp = gzopen($tarball, 'rb');
  43. $done = false;
  44. do {
  45. /* read the header */
  46. $hdr_data = gzread($fp, 512);
  47. if (strlen($hdr_data) == 0)
  48. break;
  49. $checksum = 0;
  50. for ($i = 0; $i &lt; 148; $i++)
  51. $checksum += ord($hdr_data{$i});
  52. for ($i = 148; $i &lt; 156; $i++)
  53. $checksum += 32;
  54. for ($i = 156; $i &lt; 512; $i++)
  55. $checksum += ord($hdr_data{$i});
  56. $hdr = unpack(&quot;a100filename/a8mode/a8uid/a8gid/a12size/a12mtime/a8checksum/a1typeflag/a100link/a6magic/a2version/a32uname/a32gname/a8devmajor/a8devminor&quot;, $hdr_data);
  57. $hdr['checksum'] = octdec(trim($hdr['checksum']));
  58. if ($hdr['checksum'] != $checksum) {
  59. echo &quot;Checksum for $tarball $hdr[filename] is invalid\n&quot;;
  60. print_r($hdr);
  61. return;
  62. }
  63. $hdr['size'] = octdec(trim($hdr['size']));
  64. echo &quot;File: $hdr[filename] $hdr[size]\n&quot;;
  65. if ($filename == $hdr['filename']) {
  66. echo &quot;Found the file we want\n&quot;;
  67. $dest = fopen($destfilename, 'wb');
  68. $x = stream_copy_to_stream($fp, $dest, $hdr['size']);
  69. fclose($dest);
  70. echo &quot;Wrote $x bytes into $destfilename\n&quot;;
  71. break;
  72. }
  73. /* skip body of the file */
  74. $size = 512 * ceil((int)$hdr['size'] / 512);
  75. echo &quot;Skipping $size bytes\n&quot;;
  76. gzseek($fp, gztell($fp) + $size);
  77. } while (!$done);
  78. } /* }}} */
  79. echo &quot;Creating PEAR in $dist_dir\n&quot;;
  80. /* Let's do a PEAR-less pear setup */
  81. if (!file_exists($dist_dir)) {
  82. mkdir($dist_dir);
  83. }
  84. if (!file_exists($dist_dir)) {
  85. die(&quot;could not make $dist_dir&quot;);
  86. }
  87. mkdir(&quot;$dist_dir/PEAR&quot;);
  88. mkdir(&quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  89. /* grab the bootstrap script */
  90. echo &quot;Downloading go-pear\n&quot;;
  91. copy(&quot;<a href="http://go-pear.org/">http://go-pear.org/</a>&quot;, &quot;$dist_dir/PEAR/go-pear.php&quot;);
  92. echo &quot;Downloading go-pear.bat\n&quot;;
  93. copy(&quot;$cvs_dir/pear/go-pear.bat&quot;, &quot;$dist_dir/go-pear.bat&quot;);
  94. /* import the package list -- sets $packages variable */
  95. include $cvs_dir . &quot;/pear/go-pear-list.php&quot;;
  96. /* download the packages into the destination */
  97. echo &quot;Fetching packages\n&quot;;
  98. foreach ($packages as $name =&gt; $version) {
  99. $filename = &quot;$name-$version.tgz&quot;;
  100. $destfilename = &quot;$dist_dir/PEAR/go-pear-bundle/$filename&quot;;
  101. if (file_exists($destfilename))
  102. continue;
  103. $url = &quot;<a href="http://pear.php.net/get/">http://pear.php.net/get/</a>$filename&quot;;
  104. echo &quot;Downloading $name from $url\n&quot;;
  105. flush();
  106. copy($url, $destfilename);
  107. }
  108. echo &quot;Download complete. Extracting bootstrap files\n&quot;;
  109. /* Now, we want PEAR.php, Getopt.php (Console_Getopt) and Tar.php (Archive_Tar)
  110. * broken out of the tarballs */
  111. extract_file_from_tarball('PEAR', 'PEAR.php', &quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  112. extract_file_from_tarball('Archive_Tar', 'Archive/Tar.php', &quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  113. extract_file_from_tarball('Console_Getopt', 'Console/Getopt.php', &quot;$dist_dir/PEAR/go-pear-bundle&quot;);
  114. ?&gt;
  115. </pre>
  116. <hr />
  117. </body></html>