PEAR
[ class tree: PEAR ] [ index: PEAR ] [ all elements ]

Source for file Install.php

Documentation is available at Install.php

  1. <?php
  2. //
  3. // +----------------------------------------------------------------------+
  4. // | PHP Version 5                                                        |
  5. // +----------------------------------------------------------------------+
  6. // | Copyright (c) 1997-2004 The PHP Group                                |
  7. // +----------------------------------------------------------------------+
  8. // | This source file is subject to version 3.0 of the PHP license,       |
  9. // | that is bundled with this package in the file LICENSE, and is        |
  10. // | available through the world-wide-web at the following url:           |
  11. // | http://www.php.net/license/3_0.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. // +----------------------------------------------------------------------+
  17. //
  18. // $Id: Install.php,v 1.53.2.1 2004/10/19 04:08:42 cellog Exp $
  19.  
  20. require_once "PEAR/Command/Common.php";
  21. require_once "PEAR/Installer.php";
  22.  
  23. /**
  24.  * PEAR commands for installation or deinstallation/upgrading of
  25.  * packages.
  26.  *
  27.  */
  28. class PEAR_Command_Install extends PEAR_Command_Common
  29. {
  30.     // {{{ properties
  31.  
  32.     var $commands = array(
  33.         'install' => array(
  34.             'summary' => 'Install Package',
  35.             'function' => 'doInstall',
  36.             'shortcut' => 'i',
  37.             'options' => array(
  38.                 'force' => array(
  39.                     'shortopt' => 'f',
  40.                     'doc' => 'will overwrite newer installed packages',
  41.                     ),
  42.                 'nodeps' => array(
  43.                     'shortopt' => 'n',
  44.                     'doc' => 'ignore dependencies, install anyway',
  45.                     ),
  46.                 'register-only' => array(
  47.                     'shortopt' => 'r',
  48.                     'doc' => 'do not install files, only register the package as installed',
  49.                     ),
  50.                 'soft' => array(
  51.                     'shortopt' => 's',
  52.                     'doc' => 'soft install, fail silently, or upgrade if already installed',
  53.                     ),
  54.                 'nobuild' => array(
  55.                     'shortopt' => 'B',
  56.                     'doc' => 'don\'t build C extensions',
  57.                     ),
  58.                 'nocompress' => array(
  59.                     'shortopt' => 'Z',
  60.                     'doc' => 'request uncompressed files when downloading',
  61.                     ),
  62.                 'installroot' => array(
  63.                     'shortopt' => 'R',
  64.                     'arg' => 'DIR',
  65.                     'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
  66.                     ),
  67.                 'ignore-errors' => array(
  68.                     'doc' => 'force install even if there were errors',
  69.                     ),
  70.                 'alldeps' => array(
  71.                     'shortopt' => 'a',
  72.                     'doc' => 'install all required and optional dependencies',
  73.                     ),
  74.                 'onlyreqdeps' => array(
  75.                     'shortopt' => 'o',
  76.                     'doc' => 'install all required dependencies',
  77.                     ),
  78.                 ),
  79.             'doc' => '<package> ...
  80. Installs one or more PEAR packages.  You can specify a package to
  81. install in four ways:
  82.  
  83. "Package-1.0.tgz" : installs from a local file
  84.  
  85. "http://example.com/Package-1.0.tgz" : installs from
  86. anywhere on the net.
  87.  
  88. "package.xml" : installs the package described in
  89. package.xml.  Useful for testing, or for wrapping a PEAR package in
  90. another package manager such as RPM.
  91.  
  92. "Package" : queries your configured server
  93. ({config master_server}) and downloads the newest package with
  94. the preferred quality/state ({config preferred_state}).
  95.  
  96. More than one package may be specified at once.  It is ok to mix these
  97. four ways of specifying packages.
  98. '),
  99.         'upgrade' => array(
  100.             'summary' => 'Upgrade Package',
  101.             'function' => 'doInstall',
  102.             'shortcut' => 'up',
  103.             'options' => array(
  104.                 'force' => array(
  105.                     'shortopt' => 'f',
  106.                     'doc' => 'overwrite newer installed packages',
  107.                     ),
  108.                 'nodeps' => array(
  109.                     'shortopt' => 'n',
  110.                     'doc' => 'ignore dependencies, upgrade anyway',
  111.                     ),
  112.                 'register-only' => array(
  113.                     'shortopt' => 'r',
  114.                     'doc' => 'do not install files, only register the package as upgraded',
  115.                     ),
  116.                 'nobuild' => array(
  117.                     'shortopt' => 'B',
  118.                     'doc' => 'don\'t build C extensions',
  119.                     ),
  120.                 'nocompress' => array(
  121.                     'shortopt' => 'Z',
  122.                     'doc' => 'request uncompressed files when downloading',
  123.                     ),
  124.                 'installroot' => array(
  125.                     'shortopt' => 'R',
  126.                     'arg' => 'DIR',
  127.                     'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
  128.                     ),
  129.                 'ignore-errors' => array(
  130.                     'doc' => 'force install even if there were errors',
  131.                     ),
  132.                 'alldeps' => array(
  133.                     'shortopt' => 'a',
  134.                     'doc' => 'install all required and optional dependencies',
  135.                     ),
  136.                 'onlyreqdeps' => array(
  137.                     'shortopt' => 'o',
  138.                     'doc' => 'install all required dependencies',
  139.                     ),
  140.                 ),
  141.             'doc' => '<package> ...
  142. Upgrades one or more PEAR packages.  See documentation for the
  143. "install" command for ways to specify a package.
  144.  
  145. When upgrading, your package will be updated if the provided new
  146. package has a higher version number (use the -f option if you need to
  147. upgrade anyway).
  148.  
  149. More than one package may be specified at once.
  150. '),
  151.         'upgrade-all' => array(
  152.             'summary' => 'Upgrade All Packages',
  153.             'function' => 'doInstall',
  154.             'shortcut' => 'ua',
  155.             'options' => array(
  156.                 'nodeps' => array(
  157.                     'shortopt' => 'n',
  158.                     'doc' => 'ignore dependencies, upgrade anyway',
  159.                     ),
  160.                 'register-only' => array(
  161.                     'shortopt' => 'r',
  162.                     'doc' => 'do not install files, only register the package as upgraded',
  163.                     ),
  164.                 'nobuild' => array(
  165.                     'shortopt' => 'B',
  166.                     'doc' => 'don\'t build C extensions',
  167.                     ),
  168.                 'nocompress' => array(
  169.                     'shortopt' => 'Z',
  170.                     'doc' => 'request uncompressed files when downloading',
  171.                     ),
  172.                 'installroot' => array(
  173.                     'shortopt' => 'R',
  174.                     'arg' => 'DIR',
  175.                     'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
  176.                     ),
  177.                 'ignore-errors' => array(
  178.                     'doc' => 'force install even if there were errors',
  179.                     ),
  180.                 ),
  181.             'doc' => '
  182. Upgrades all packages that have a newer release available.  Upgrades are
  183. done only if there is a release available of the state specified in
  184. "preferred_state" (currently {config preferred_state}), or a state considered
  185. more stable.
  186. '),
  187.         'uninstall' => array(
  188.             'summary' => 'Un-install Package',
  189.             'function' => 'doUninstall',
  190.             'shortcut' => 'un',
  191.             'options' => array(
  192.                 'nodeps' => array(
  193.                     'shortopt' => 'n',
  194.                     'doc' => 'ignore dependencies, uninstall anyway',
  195.                     ),
  196.                 'register-only' => array(
  197.                     'shortopt' => 'r',
  198.                     'doc' => 'do not remove files, only register the packages as not installed',
  199.                     ),
  200.                 'installroot' => array(
  201.                     'shortopt' => 'R',
  202.                     'arg' => 'DIR',
  203.                     'doc' => 'root directory used when installing files (ala PHP\'s INSTALL_ROOT)',
  204.                     ),
  205.                 'ignore-errors' => array(
  206.                     'doc' => 'force install even if there were errors',
  207.                     ),
  208.                 ),
  209.             'doc' => '<package> ...
  210. Uninstalls one or more PEAR packages.  More than one package may be
  211. specified at once.
  212. '),
  213.         'bundle' => array(
  214.             'summary' => 'Unpacks a Pecl Package',
  215.             'function' => 'doBundle',
  216.             'shortcut' => 'bun',
  217.             'options' => array(
  218.                 'destination' => array(
  219.                    'shortopt' => 'd',
  220.                     'arg' => 'DIR',
  221.                     'doc' => 'Optional destination directory for unpacking (defaults to current path or "ext" if exists)',
  222.                     ),
  223.                 'force' => array(
  224.                     'shortopt' => 'f',
  225.                     'doc' => 'Force the unpacking even if there were errors in the package',
  226.                 ),
  227.             ),
  228.             'doc' => '<package>
  229. Unpacks a Pecl Package into the selected location. It will download the
  230. package if needed.
  231. '),
  232.     );
  233.  
  234.     // }}}
  235.     // {{{ constructor
  236.  
  237.     /**
  238.      * PEAR_Command_Install constructor.
  239.      *
  240.      * @access public
  241.      */
  242.     function PEAR_Command_Install(&$ui&$config)
  243.     {
  244.         parent::PEAR_Command_Common($ui$config);
  245.     }
  246.  
  247.     // }}}
  248.  
  249.     // {{{ doInstall()
  250.  
  251.     function doInstall($command$options$params)
  252.     {
  253.         require_once 'PEAR/Downloader.php';
  254.         if (empty($this->installer)) {
  255.             $this->installer &new PEAR_Installer($this->ui);
  256.         }
  257.         if ($command == 'upgrade'{
  258.             $options['upgrade'= true;
  259.         }
  260.         if ($command == 'upgrade-all'{
  261.             include_once "PEAR/Remote.php";
  262.             $options['upgrade'= true;
  263.             $remote &new PEAR_Remote($this->config);
  264.             $state $this->config->get('preferred_state');
  265.             if (empty($state|| $state == 'any'{
  266.                 $latest $remote->call("package.listLatestReleases");
  267.             else {
  268.                 $latest $remote->call("package.listLatestReleases"$state);
  269.             }
  270.             if (PEAR::isError($latest)) {
  271.                 return $latest;
  272.             }
  273.             $reg = new PEAR_Registry($this->config->get('php_dir'));
  274.             $installed array_flip($reg->listPackages());
  275.             $params = array();
  276.             foreach ($latest as $package => $info{
  277.                 $package strtolower($package);
  278.                 if (!isset($installed[$package])) {
  279.                     // skip packages we don't have installed
  280.                     continue;
  281.                 }
  282.                 $inst_version $reg->packageInfo($package'version');
  283.                 if (version_compare("$info[version]""$inst_version""le")) {
  284.                     // installed version is up-to-date
  285.                     continue;
  286.                 }
  287.                 $params[$package;
  288.                 $this->ui->outputData(array('data' => "Will upgrade $package")$command);
  289.             }
  290.         }
  291.         $this->downloader &new PEAR_Downloader($this->ui$options$this->config);
  292.         $errors = array();
  293.         $downloaded = array();
  294.         $this->downloader->download($params);
  295.         $errors $this->downloader->getErrorMsgs();
  296.         if (count($errors)) {
  297.             $err['data'= array($errors);
  298.             $err['headline''Install Errors';
  299.             $this->ui->outputData($err);
  300.             return $this->raiseError("$command failed");
  301.         }
  302.         $downloaded $this->downloader->getDownloadedPackages();
  303.         $this->installer->sortPkgDeps($downloaded);
  304.         foreach ($downloaded as $pkg{
  305.             PEAR::pushErrorHandling(PEAR_ERROR_RETURN);
  306.             $info $this->installer->install($pkg['file']$options$this->config);
  307.             PEAR::popErrorHandling();
  308.             if (PEAR::isError($info)) {
  309.                 $this->ui->outputData('ERROR: ' .$info->getMessage());
  310.                 continue;
  311.             }
  312.             if (is_array($info)) {
  313.                 if ($this->config->get('verbose'> 0{
  314.                     $label = "$info[package] $info[version]";
  315.                     $out = array('data' => "$command ok: $label");
  316.                     if (isset($info['release_warnings'])) {
  317.                         $out['release_warnings'$info['release_warnings'];
  318.                     }
  319.                     $this->ui->outputData($out$command);
  320.                 }
  321.             else {
  322.                 return $this->raiseError("$command failed");
  323.             }
  324.         }
  325.         return true;
  326.     }
  327.  
  328.     // }}}
  329.     // {{{ doUninstall()
  330.  
  331.     function doUninstall($command$options$params)
  332.     {
  333.         if (empty($this->installer)) {
  334.             $this->installer &new PEAR_Installer($this->ui);
  335.         }
  336.         if (sizeof($params< 1{
  337.             return $this->raiseError("Please supply the package(s) you want to uninstall");
  338.         }
  339.         include_once 'PEAR/Registry.php';
  340.         $reg = new PEAR_Registry($this->config->get('php_dir'));
  341.         $newparams = array();
  342.         $badparams = array();
  343.         foreach ($params as $pkg{
  344.             $info $reg->packageInfo($pkg);
  345.             if ($info === null{
  346.                 $badparams[$pkg;
  347.             else {
  348.                 $newparams[$info;
  349.             }
  350.         }
  351.         $this->installer->sortPkgDeps($newparamstrue);
  352.         $params = array();
  353.         foreach($newparams as $info{
  354.             $params[$info['info']['package'];
  355.         }
  356.         $params array_merge($params$badparams);
  357.         foreach ($params as $pkg{
  358.             if ($this->installer->uninstall($pkg$options)) {
  359.                 if ($this->config->get('verbose'> 0{
  360.                     $this->ui->outputData("uninstall ok: $pkg"$command);
  361.                 }
  362.             else {
  363.                 return $this->raiseError("uninstall failed: $pkg");
  364.             }
  365.         }
  366.         return true;
  367.     }
  368.  
  369.     // }}}
  370.  
  371.  
  372.     // }}}
  373.     // {{{ doBundle()
  374.     /*
  375.     (cox) It just downloads and untars the package, does not do
  376.             any check that the PEAR_Installer::_installFile() does.
  377.     */
  378.  
  379.     function doBundle($command$options$params)
  380.     {
  381.         if (empty($this->installer)) {
  382.             $this->installer &new PEAR_Downloader($this->ui);
  383.         }
  384.         $installer &$this->installer;
  385.         if (sizeof($params< 1{
  386.             return $this->raiseError("Please supply the package you want to bundle");
  387.         }
  388.         $pkgfile $params[0];
  389.         $need_download = false;
  390.         if (preg_match('#^(http|ftp)://#'$pkgfile)) {
  391.             $need_download = true;
  392.         elseif (!@is_file($pkgfile)) {
  393.             if ($installer->validPackageName($pkgfile)) {
  394.                 $pkgfile $installer->getPackageDownloadUrl($pkgfile);
  395.                 $need_download = true;
  396.             else {
  397.                 if (strlen($pkgfile)) {
  398.                     return $this->raiseError("Could not open the package file: $pkgfile");
  399.                 else {
  400.                     return $this->raiseError("No package file given");
  401.                 }
  402.             }
  403.         }
  404.  
  405.         // Download package -----------------------------------------------
  406.         if ($need_download{
  407.             $downloaddir $installer->config->get('download_dir');
  408.             if (empty($downloaddir)) {
  409.                 if (PEAR::isError($downloaddir System::mktemp('-d'))) {
  410.                     return $downloaddir;
  411.                 }
  412.                 $installer->log(2'+ tmp dir created at ' $downloaddir);
  413.             }
  414.             $callback $this->ui ? array(&$installer'_downloadCallback': null;
  415.             $file $installer->downloadHttp($pkgfile$this->ui$downloaddir$callback);
  416.             if (PEAR::isError($file)) {
  417.                 return $this->raiseError($file);
  418.             }
  419.             $pkgfile $file;
  420.         }
  421.  
  422.        // Parse xml file -----------------------------------------------
  423.         $pkginfo $installer->infoFromTgzFile($pkgfile);
  424.         if (PEAR::isError($pkginfo)) {
  425.             return $this->raiseError($pkginfo);
  426.         }
  427.         $installer->validatePackageInfo($pkginfo$errors$warnings);
  428.         // XXX We allow warnings, do we have to do it?
  429.         if (count($errors)) {
  430.              if (empty($options['force'])) {
  431.                 return $this->raiseError("The following errors where found:\n".
  432.                                                  implode("\n"$errors));
  433.             else {
  434.                 $this->log(0"warning : the following errors were found:\n".
  435.                            implode("\n"$errors));
  436.             }
  437.         }
  438.         $pkgname $pkginfo['package'];
  439.  
  440.         // Unpacking -------------------------------------------------
  441.  
  442.         if (isset($options['destination'])) {
  443.             if (!is_dir($options['destination'])) {
  444.                 System::mkdir('-p ' $options['destination']);
  445.             }
  446.             $dest realpath($options['destination']);
  447.         else {
  448.             $pwd getcwd();
  449.             if (is_dir($pwd . DIRECTORY_SEPARATOR . 'ext')) {
  450.                 $dest $pwd . DIRECTORY_SEPARATOR . 'ext';
  451.             else {
  452.                 $dest $pwd;
  453.             }
  454.         }
  455.         $dest .= DIRECTORY_SEPARATOR . $pkgname;
  456.         $orig $pkgname '-' $pkginfo['version'];
  457.  
  458.         $tar = new Archive_Tar($pkgfile);
  459.         if (!@$tar->extractModify($dest$orig)) {
  460.             return $this->raiseError("unable to unpack $pkgfile");
  461.         }
  462.         $this->ui->outputData("Package ready at '$dest'");
  463.     // }}}
  464.     }
  465.  
  466.     // }}}
  467.  
  468. }
  469. ?>

Documentation generated on Mon, 11 Mar 2019 14:23:57 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.