2002-05-20 18:46:01 +08:00
|
|
|
<?php
|
|
|
|
|
2002-11-13 08:49:37 +08:00
|
|
|
/* $Id$ */
|
|
|
|
|
2002-05-20 18:46:01 +08:00
|
|
|
$pear_dir = dirname(__FILE__);
|
|
|
|
ini_set('include_path', $pear_dir);
|
|
|
|
include_once 'PEAR.php';
|
|
|
|
include_once 'PEAR/Installer.php';
|
|
|
|
include_once 'PEAR/Registry.php';
|
|
|
|
include_once 'PEAR/Frontend/CLI.php';
|
|
|
|
|
2005-08-21 02:31:29 +08:00
|
|
|
$a = true;
|
|
|
|
if (!PEAR::loadExtension('xml')) {
|
|
|
|
$a = false;
|
|
|
|
echo "[PEAR] xml extension is required\n";
|
|
|
|
}
|
|
|
|
if (!PEAR::loadExtension('pcre')) {
|
|
|
|
$a = false;
|
|
|
|
echo "[PEAR] pcre extension is required\n";
|
|
|
|
}
|
|
|
|
if (!$a) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2003-06-30 04:49:09 +08:00
|
|
|
$force = false;
|
2002-05-20 18:46:01 +08:00
|
|
|
$install_files = array();
|
2003-06-30 04:49:09 +08:00
|
|
|
array_shift($argv);
|
|
|
|
for ($i = 0; $i < sizeof($argv); $i++) {
|
|
|
|
$arg = $argv[$i];
|
2002-05-20 18:46:01 +08:00
|
|
|
$bn = basename($arg);
|
2003-06-30 04:49:09 +08:00
|
|
|
if (ereg('package-(.*)\.xml$', $bn, $matches) ||
|
|
|
|
ereg('([A-Za-z0-9_:]+)-.*\.(tar|tgz)$', $bn, $matches)) {
|
2003-07-03 13:09:36 +08:00
|
|
|
$install_files[$matches[1]] = $arg;
|
2003-06-30 04:49:09 +08:00
|
|
|
} elseif ($arg == '--force') {
|
|
|
|
$force = true;
|
|
|
|
} elseif ($arg == '-d') {
|
|
|
|
$with_dir = $argv[$i+1];
|
|
|
|
$i++;
|
2003-07-17 14:30:21 +08:00
|
|
|
} elseif ($arg == '-b') {
|
|
|
|
$bin_dir = $argv[$i+1];
|
|
|
|
$i++;
|
2002-05-20 18:46:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$config = &PEAR_Config::singleton();
|
|
|
|
|
|
|
|
// make sure we use only default values
|
|
|
|
$config_layers = $config->getLayers();
|
|
|
|
foreach ($config_layers as $layer) {
|
|
|
|
if ($layer == 'default') continue;
|
|
|
|
$config->removeLayer($layer);
|
|
|
|
}
|
2003-06-30 04:49:09 +08:00
|
|
|
$keys = $config->getKeys();
|
2002-05-20 18:46:01 +08:00
|
|
|
$config->set('verbose', 0, 'default');
|
2003-07-17 14:30:21 +08:00
|
|
|
// PEAR executables
|
|
|
|
if (!empty($bin_dir)) {
|
|
|
|
$config->set('bin_dir', $bin_dir, 'default');
|
|
|
|
}
|
2003-06-30 04:49:09 +08:00
|
|
|
// User supplied a dir prefix
|
|
|
|
if (!empty($with_dir)) {
|
|
|
|
$ds = DIRECTORY_SEPARATOR;
|
2003-08-15 04:14:34 +08:00
|
|
|
$config->set('php_dir', $with_dir, 'default');
|
2003-06-30 04:49:09 +08:00
|
|
|
$config->set('doc_dir', $with_dir . $ds . 'doc', 'default');
|
|
|
|
$config->set('data_dir', $with_dir . $ds . 'data', 'default');
|
|
|
|
$config->set('test_dir', $with_dir . $ds . 'test', 'default');
|
|
|
|
}
|
2003-06-30 04:50:05 +08:00
|
|
|
/* Print PEAR Conf (useful for debuging do NOT REMOVE)
|
2003-06-30 04:49:09 +08:00
|
|
|
sort($keys);
|
|
|
|
foreach ($keys as $key) {
|
|
|
|
echo $config->getPrompt($key) . ": " . $config->get($key) . "\n";
|
|
|
|
}
|
|
|
|
exit;
|
|
|
|
// end print
|
|
|
|
//*/
|
2002-05-20 18:46:01 +08:00
|
|
|
|
2002-11-13 08:02:11 +08:00
|
|
|
$php_dir = $config->get('php_dir');
|
2003-06-30 04:49:09 +08:00
|
|
|
$options = array();
|
|
|
|
$install_root = getenv('INSTALL_ROOT');
|
2002-11-13 08:02:11 +08:00
|
|
|
if (!empty($install_root)) {
|
|
|
|
$options['installroot'] = $install_root;
|
|
|
|
$reg_dir = $install_root . $php_dir;
|
|
|
|
} else {
|
|
|
|
$reg_dir = $php_dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
$reg = &new PEAR_Registry($reg_dir);
|
2002-05-20 18:46:01 +08:00
|
|
|
$ui = &new PEAR_Frontend_CLI();
|
|
|
|
$installer = &new PEAR_Installer($ui);
|
2003-06-30 04:49:09 +08:00
|
|
|
//$installer->registry = &$reg; // This should be changed in Installer/Registry
|
2002-05-20 18:46:01 +08:00
|
|
|
|
|
|
|
foreach ($install_files as $package => $instfile) {
|
|
|
|
if ($reg->packageExists($package)) {
|
|
|
|
$info = $installer->infoFromAny($instfile);
|
|
|
|
if (PEAR::isError($info)) {
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $info->getMessage()));
|
2002-05-20 18:46:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$new_ver = $info['version'];
|
|
|
|
$old_ver = $reg->packageInfo($package, 'version');
|
|
|
|
if (version_compare($new_ver, $old_ver, 'gt')) {
|
2002-11-13 08:02:11 +08:00
|
|
|
$options['upgrade'] = true;
|
|
|
|
$err = $installer->install($instfile, $options);
|
2002-05-20 18:46:01 +08:00
|
|
|
if (PEAR::isError($err)) {
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
|
2002-05-20 18:46:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %-15s- upgraded: %s", $package, $new_ver));
|
2002-05-20 18:46:01 +08:00
|
|
|
} else {
|
2003-06-30 04:49:09 +08:00
|
|
|
if ($force) {
|
2002-11-13 08:02:11 +08:00
|
|
|
$options['force'] = true;
|
|
|
|
$err = $installer->install($instfile, $options);
|
2002-05-20 18:46:01 +08:00
|
|
|
if (PEAR::isError($err)) {
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
|
2002-05-20 18:46:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
|
2002-05-20 18:46:01 +08:00
|
|
|
} else {
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %-15s- already installed: %s", $package, $old_ver));
|
2002-05-20 18:46:01 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2002-11-13 08:02:11 +08:00
|
|
|
$options['nodeps'] = true;
|
|
|
|
$err = $installer->install($instfile, $options);
|
2002-05-20 18:46:01 +08:00
|
|
|
if (PEAR::isError($err)) {
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %s: %s", $package, $err->getMessage()));
|
2002-05-20 18:46:01 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$new_ver = $reg->packageInfo($package, 'version');
|
2002-06-10 00:29:50 +08:00
|
|
|
$ui->outputData(sprintf("[PEAR] %-15s- installed: %s", $package, $new_ver));
|
2002-05-20 18:46:01 +08:00
|
|
|
}
|
2003-07-03 14:45:49 +08:00
|
|
|
if ($package == 'PEAR') {
|
|
|
|
if (is_file($ufile = $config->getConfFile('user'))) {
|
|
|
|
$ui->outputData('Warning! a PEAR user config file already exists from ' .
|
|
|
|
'a previous PEAR installation at ' .
|
|
|
|
"'$ufile'. You may probably want to remove it.");
|
|
|
|
}
|
2003-07-03 15:08:21 +08:00
|
|
|
$config->set('verbose', 1, 'default');
|
2003-07-03 14:45:49 +08:00
|
|
|
foreach ($config->getKeys() as $key) {
|
|
|
|
$data[$key] = $config->get($key);
|
|
|
|
}
|
2003-07-10 09:34:46 +08:00
|
|
|
$cnf_file = $config->getConfFile('system');
|
|
|
|
if (!empty($install_root)) {
|
|
|
|
$cnf_file = $install_root . DIRECTORY_SEPARATOR . $cnf_file;
|
|
|
|
}
|
|
|
|
$config->writeConfigFile($cnf_file, 'system', $data);
|
|
|
|
$ui->outputData('Wrote PEAR system config file at: ' . $cnf_file);
|
|
|
|
$ui->outputData('You may want to add: ' . $config->get('php_dir') . ' to your php.ini include_path');
|
2003-07-03 14:45:49 +08:00
|
|
|
}
|
2002-05-20 18:46:01 +08:00
|
|
|
}
|
2003-06-30 04:49:09 +08:00
|
|
|
?>
|