Blame SOURCES/install-pear.php

04b387
04b387
while (@ob_end_flush());
04b387
/* $Id$ */
04b387
04b387
error_reporting(1803);
04b387
04b387
if (ini_get('date.timezone') === '' && function_exists('date_default_timezone_set')) {
04b387
    date_default_timezone_set('UTC');
04b387
}
04b387
04b387
$pear_dir = dirname(__FILE__);
04b387
ini_set('include_path', '');
04b387
if (function_exists('mb_internal_encoding')) {
04b387
    mb_internal_encoding('ASCII');
04b387
}
04b387
set_time_limit(0);
04b387
include_once 'PEAR.php';
04b387
include_once 'PEAR/Installer.php';
04b387
include_once 'PEAR/Registry.php';
04b387
include_once 'PEAR/PackageFile.php';
04b387
include_once 'PEAR/Downloader/Package.php';
04b387
include_once 'PEAR/Frontend.php';
04b387
$a = true;
04b387
if (!PEAR::loadExtension('xml')) {
04b387
    $a = false;
04b387
    echo "[PEAR] xml extension is required\n";
04b387
}
04b387
if (!PEAR::loadExtension('pcre')) {
04b387
    $a = false;
04b387
    echo "[PEAR] pcre extension is required\n";
04b387
}
04b387
if (!$a) {
04b387
    return -1;
04b387
}
04b387
04b387
$force = false;
04b387
$install_files = array();
04b387
array_shift($argv);
04b387
$debug = false;
04b387
for ($i = 0; $i < sizeof($argv); $i++) {
04b387
    $arg = $argv[$i];
04b387
    $bn = basename($arg);
04b387
    if (preg_match('/package-(.*)\.xml$/', $bn, $matches) ||
04b387
        preg_match('/([A-Za-z0-9_:]+)-.*\.(tar|tgz)$/', $bn, $matches)) {
04b387
        $install_files[$matches[1]] = $arg;
04b387
    } elseif ($arg == '-a' || $arg == '--cache') {
04b387
        $cache_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '--force') {
04b387
        $force = true;
04b387
    } elseif ($arg == '-dp') {
04b387
        $prefix = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-ds') {
04b387
        $suffix = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-d' || $arg == '--dir') {
04b387
        $with_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-b' || $arg == '--bin') {
04b387
        $bin_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-c' || $arg == '--config') {
04b387
        $cfg_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-w' || $arg == '--www') {
04b387
        $www_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-p' || $arg == '--php') {
04b387
        $php_bin = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-o' || $arg == '--download') {
04b387
        $download_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-m' || $arg == '--metadata') {
04b387
        $metadata_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-t' || $arg == '--temp') {
04b387
        $temp_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-A' || $arg == '--data') {
04b387
        $data_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-D' || $arg == '--doc') {
04b387
        $doc_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '-T' || $arg == '--test') {
04b387
        $test_dir = $argv[$i+1];
04b387
        $i++;
04b387
    } elseif ($arg == '--debug') {
04b387
        $debug = 1;
04b387
    } elseif ($arg == '--extremedebug') {
04b387
        $debug = 2;
04b387
    }
04b387
}
04b387
04b387
$config = PEAR_Config::singleton();
04b387
04b387
if (PEAR::isError($config)) {
04b387
    $locs = PEAR_Config::getDefaultConfigFiles();
04b387
    die("ERROR: One of $locs[user] or $locs[system] is corrupt, please remove them and try again");
04b387
}
04b387
04b387
// make sure we use only default values
04b387
$config_layers = $config->getLayers();
04b387
foreach ($config_layers as $layer) {
04b387
    if ($layer == 'default') continue;
04b387
    $config->removeLayer($layer);
04b387
}
04b387
$keys = $config->getKeys();
04b387
if ($debug) {
04b387
    $config->set('verbose', 5, 'default');
04b387
} else {
04b387
    $config->set('verbose', 0, 'default');
04b387
}
04b387
// PEAR executables
04b387
if (!empty($bin_dir)) {
04b387
    $config->set('bin_dir', $bin_dir, 'default');
04b387
}
04b387
04b387
// Cache files
04b387
if (!empty($cache_dir)) {
04b387
    $config->set('cache_dir', $cache_dir, 'default');
04b387
}
04b387
04b387
// Config files
04b387
if (!empty($cfg_dir)) {
04b387
    $config->set('cfg_dir', $cfg_dir, 'default');
04b387
}
04b387
04b387
// Web files
04b387
if (!empty($www_dir)) {
04b387
    $config->set('www_dir', $www_dir, 'default');
04b387
}
04b387
04b387
// Downloaded files
04b387
if (!empty($download_dir)) {
04b387
    $config->set('download_dir', $download_dir, 'default');
04b387
}
04b387
04b387
// Temporary files
04b387
if (!empty($temp_dir)) {
04b387
    $config->set('temp_dir', $temp_dir, 'default');
04b387
}
04b387
04b387
// Documentation files
04b387
if (!empty($doc_dir)) {
04b387
    $config->set('doc_dir', $doc_dir, 'default');
04b387
}
04b387
04b387
// Data files
04b387
if (!empty($data_dir)) {
04b387
    $config->set('data_dir', $data_dir, 'default');
04b387
}
04b387
04b387
// Unit tests
04b387
if (!empty($test_dir)) {
04b387
    $config->set('test_dir', $test_dir, 'default');
04b387
}
04b387
04b387
// User supplied a dir prefix
04b387
if (!empty($with_dir)) {
04b387
    $ds = DIRECTORY_SEPARATOR;
04b387
    $config->set('php_dir', $with_dir, 'default');
04b387
    // Metadata
04b387
    if (!empty($metadata_dir)) {
04b387
        $config->set('metadata_dir', $metadata_dir, 'default');
04b387
    }
04b387
    if (empty($doc_dir)) {
04b387
        $config->set('doc_dir', $with_dir . $ds . 'doc', 'default');
04b387
    }
04b387
    if (empty($data_dir)) {
04b387
        $config->set('data_dir', $with_dir . $ds . 'data', 'default');
04b387
    }
04b387
    if (empty($test_dir)) {
04b387
        $config->set('test_dir', $with_dir . $ds . 'test', 'default');
04b387
    }
04b387
    if (empty($www_dir)) {
04b387
        $config->set('www_dir', $with_dir . $ds . 'htdocs', 'default');
04b387
    }
04b387
    if (empty($cfg_dir)) {
04b387
        $config->set('cfg_dir', $with_dir . $ds . 'cfg', 'default');
04b387
    }
04b387
    if (!is_writable($config->get('cache_dir'))) {
04b387
        include_once 'System.php';
04b387
        $cdir = System::mktemp(array('-d', 'pear'));
04b387
        if (PEAR::isError($cdir)) {
04b387
            $ui->outputData("[PEAR] cannot make new temporary directory: " . $cdir);
04b387
            die(1);
04b387
        }
04b387
        $oldcachedir = $config->get('cache_dir');
04b387
        $config->set('cache_dir', $cdir);
04b387
    }
04b387
}
04b387
04b387
// PHP executable
04b387
if (!empty($php_bin)) {
04b387
    $config->set('php_bin', $php_bin);
04b387
}
04b387
04b387
// PHP prefix
04b387
if (isset($prefix)) {
04b387
    if ($prefix != 'a') {
04b387
        if ($prefix[0] == 'a') {
04b387
            $prefix = substr($prefix, 1);
04b387
        }
04b387
        $config->set('php_prefix', $prefix, 'system');
04b387
    }
04b387
}
04b387
04b387
// PHP suffix
04b387
if (isset($suffix)) {
04b387
    if ($suffix != 'a') {
04b387
        if ($suffix[0] == 'a') {
04b387
            $suffix = substr($suffix, 1);
04b387
        }
04b387
        $config->set('php_suffix', $suffix, 'system');
04b387
    }
04b387
}
04b387
04b387
/* Print PEAR Conf (useful for debuging do NOT REMOVE) */
04b387
if ($debug) {
04b387
    sort($keys);
04b387
    foreach ($keys as $key) {
04b387
        echo $key . '    ' .
04b387
            $config->getPrompt($key) . ": " . $config->get($key, null, 'default') . "\n";
04b387
    }
04b387
    if ($debug == 2) { // extreme debugging
04b387
        exit;
04b387
    }
04b387
}
04b387
// end print
04b387
04b387
$php_dir = $config->get('php_dir');
04b387
$options = array();
04b387
$options['upgrade'] = true;
04b387
$install_root = getenv('INSTALL_ROOT');
04b387
if (!empty($install_root)) {
04b387
    $options['packagingroot'] = $install_root;
04b387
    $reg = &new PEAR_Registry($options['packagingroot'], false, false, $metadata_dir);
04b387
} else {
04b387
    $reg = $config->getRegistry('default');
04b387
}
04b387
04b387
$ui = PEAR_Frontend::singleton('PEAR_Frontend_CLI');
04b387
if (PEAR::isError($ui)) {
04b387
    die($ui->getMessage());
04b387
}
04b387
$installer = new PEAR_Installer($ui);
04b387
$pkg = new PEAR_PackageFile($config, $debug);
04b387
04b387
foreach ($install_files as $package => $instfile) {
04b387
    $info = $pkg->fromAnyFile($instfile, PEAR_VALIDATE_INSTALLING);
04b387
    if (PEAR::isError($info)) {
04b387
        if (is_array($info->getUserInfo())) {
04b387
            foreach ($info->getUserInfo() as $err) {
04b387
                $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err['message']));
04b387
            }
04b387
        }
04b387
        $ui->outputData(sprintf("[PEAR] %s: %s", $package, $info->getMessage()));
04b387
        continue;
04b387
    }
04b387
    $new_ver = $info->getVersion();
04b387
    $downloaderpackage = new PEAR_Downloader_Package($installer);
04b387
    $err = $downloaderpackage->initialize($instfile);
04b387
    if (PEAR::isError($err)) {
04b387
        $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
04b387
        continue;
04b387
    }
04b387
    if ($reg->packageExists($package)) {
04b387
        $old_ver = $reg->packageInfo($package, 'version');
04b387
        if (version_compare($new_ver, $old_ver, 'gt')) {
04b387
            $installer->setOptions($options);
04b387
            $dp = array($downloaderpackage);
04b387
            $installer->setDownloadedPackages($dp);
04b387
            $err = $installer->install($downloaderpackage, $options);
04b387
            if (PEAR::isError($err)) {
04b387
                $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
04b387
                continue;
04b387
            }
04b387
            $ui->outputData(sprintf("[PEAR] %-15s- upgraded:  %s", $package, $new_ver));
04b387
        } else {
04b387
            if ($force) {
04b387
                $options['force'] = true;
04b387
                $installer->setOptions($options);
04b387
                $dp = array($downloaderpackage);
04b387
                $installer->setDownloadedPackages($dp);
04b387
                $err = $installer->install($downloaderpackage, $options);
04b387
                if (PEAR::isError($err)) {
04b387
                    $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
04b387
                    continue;
04b387
                }
04b387
                $ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
04b387
            } else {
04b387
                $ui->outputData(sprintf("[PEAR] %-15s- already installed: %s", $package, $old_ver));
04b387
            }
04b387
        }
04b387
    } else {
04b387
        $options['nodeps'] = true;
04b387
        $installer->setOptions($options);
04b387
        $dp = array($downloaderpackage);
04b387
        $installer->setDownloadedPackages($dp);
04b387
        $err = $installer->install($downloaderpackage, $options);
04b387
        if (PEAR::isError($err)) {
04b387
            $ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
04b387
            continue;
04b387
        }
04b387
        $ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
04b387
    }
04b387
    if ($package == 'PEAR') {
04b387
        if (is_file($ufile = $config->getConfFile('user'))) {
04b387
            $ui->outputData('Warning! a PEAR user config file already exists from ' .
04b387
                            'a previous PEAR installation at ' .
04b387
                            "'$ufile'. You may probably want to remove it.");
04b387
        }
04b387
        $config->set('verbose', 1, 'default');
04b387
        if (isset($oldcachedir)) {
04b387
            $config->set('cache_dir', $oldcachedir);
04b387
        }
04b387
        $data = array();
04b387
        foreach ($config->getKeys() as $key) {
04b387
            $data[$key] = $config->get($key);
04b387
        }
04b387
        $cnf_file = $config->getConfFile('system');
04b387
        if (!empty($install_root)) {
04b387
            $cnf_file = $install_root . DIRECTORY_SEPARATOR . $cnf_file;
04b387
        }
04b387
        $config->writeConfigFile($cnf_file, 'system', $data);
04b387
        $ui->outputData('Wrote PEAR system config file at: ' . $cnf_file);
04b387
        $ui->outputData('You may want to add: ' . $config->get('php_dir') . ' to your php.ini include_path');
04b387
    }
04b387
}
04b387
?>