home *** CD-ROM | disk | FTP | other *** search
/ PC World 2005 April / PCWorld_2005-04_cd.bin / akce / web / phptriad / phptriad2-2-1.exe / php / pear / scripts / pearwin.php < prev    next >
PHP Script  |  2001-11-13  |  4KB  |  119 lines

  1. <?php 
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP version 4.0                                                      |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2001 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 2.02 of the PHP license,      |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available at through the world-wide-web at                           |
  11. // | http://www.php.net/license/2_02.txt.                                 |
  12. // | If you did not receive a copy of the PHP license and are unable to   |
  13. // | obtain it through the world-wide-web, please send a note to          |
  14. // | license@php.net so we can mail you a copy immediately.               |
  15. // +----------------------------------------------------------------------+
  16. // | Authors: Stig Bakken <ssb@fast.no>                                   |
  17. // |          Tomas V.V.Cox <cox@idecnet.com>                             |
  18. // +----------------------------------------------------------------------+
  19. //
  20. // $Id: pearwin.php,v 1.2.2.1 2001/11/13 01:26:51 ssb Exp $
  21.  
  22. require_once 'PEAR.php';
  23. require_once 'Console/Getopt.php';
  24.  
  25. error_reporting(E_ALL ^ E_NOTICE);
  26.  
  27. $options = Console_Getopt::getopt($argv, "h?v:e:p:d:");
  28. if (PEAR::isError($options)) {
  29.     usage($options);
  30. }
  31.  
  32. $opts = $options[0];
  33. foreach ($opts as $opt) {
  34.     $param = $opt[1];
  35.     switch ($opt[0]) {
  36.         case 'v':
  37.             $verbose = $param;
  38.             break;
  39.         case 'e':
  40.             if ($param{0} != getenv('DIRECTORY_SEPARATOR')) {
  41.                 usage (new PEAR_Error("no absolute path (eg. /usr/lib/php)\n"));
  42.             }
  43.             $ext_dir = $param;
  44.             break;
  45.         case 'p':
  46.             if ($param{0} != getenv('DIRECTORY_SEPARATOR')) {
  47.                 usage (new PEAR_Error("no absolute path (eg. /usr/lib/php)\n"));
  48.             }
  49.             $script_dir = $param;
  50.             break;
  51.         case 'd':
  52.             if ($param{0} != getenv('DIRECTORY_SEPARATOR')) {
  53.                 usage (new PEAR_Error("no absolute path (eg. /usr/lib/php)\n"));
  54.             }
  55.             $doc_dir = $param;
  56.             break;
  57.     }
  58. }
  59.  
  60. $verbose    = (isset($verbose)) ? $verbose : 1;
  61. $script_dir = (isset($script_dir)) ? $script_dir : getenv('PEAR_INSTALL_DIR');
  62. $ext_dir    = (isset($ext_dir)) ? $ext_dir : getenv('PEAR_EXTENSION_DIR');
  63. $doc_dir    = (isset($doc_dir)) ? $doc_dir : '';
  64.  
  65. PEAR::setErrorHandling(PEAR_ERROR_PRINT);
  66. $command = $options[1][1];
  67.  
  68. switch ($command) {
  69.     case 'install':
  70.         include_once 'PEAR/Installer.php';
  71.         $package = $options[1][2];
  72.         $installer =& new PEAR_Installer($script_dir, $ext_dir, $doc_dir);
  73.         $installer->debug = $verbose;
  74.         if (PEAR::isError($installer->Install($package))) {
  75.             print "\ninstall failed\n";
  76.         } else {
  77.             print "install ok\n";
  78.         }
  79.         break;
  80.     case 'package':
  81.         include_once 'PEAR/Packager.php';
  82.         $pkginfofile = $options[1][2];
  83.         $packager =& new PEAR_Packager($script_dir, $ext_dir, $doc_dir);
  84.         $packager->debug = $verbose;
  85.         if (PEAR::isError($packager->Package($pkginfofile))) {
  86.             print "\npackage failed\n";
  87.         } else {
  88.             print "package ok\n";
  89.         }
  90.         break;
  91.     default:
  92.         usage();
  93.         break;
  94. }
  95.  
  96. function usage($obj = null)
  97. {
  98.     $stderr = fopen('php://stderr', 'w');
  99.     if ($obj !== null) {
  100.         fputs($stderr, $obj->getMessage());
  101.     }
  102.     fputs($stderr,
  103.           "Usage: pear [-v n] [-h] [-p <dir>] [-e <dir>] [-d <dir>] command <parameters>\n".
  104.           "Options:\n".
  105.           "     -v        set verbosity level to <n> (0-2, default 1)\n".
  106.           "     -p <dir>  set script install dir (absolute path)\n".
  107.           "     -e <dir>  set extension install dir (absolute path)\n".
  108.           "     -d <dir>  set documentation dest dir (absolute path)\n".
  109.           "     -h, -?    display help/usage (this message)\n".
  110.           "Commands:\n".
  111.           "   install <package file>\n".
  112.           "   package [package info file]\n".
  113.           "\n");
  114.     fclose($stderr);
  115.     exit;
  116. }
  117.  
  118. ?>
  119.