Blame SOURCES/install-pear.php

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