$this->statedir = "/var/lib/php"; // XXX FIXME Windows
}
- // }}}
- // {{{ destructor
-
- function _PEAR_Installer()
- {
- chdir($this->pwd);
- $this->_PEAR_Common();
- }
-
// }}}
// {{{ install()
{
// XXX FIXME Add here code to manage packages database
//$this->loadPackageList("$this->statedir/packages.lst");
- $this->pwd = getcwd();
+ $oldcwd = getcwd();
$need_download = false;
if (preg_match('#^(http|ftp)://#', $pkgfile)) {
$need_download = true;
$pkgfile = getcwd() . DIRECTORY_SEPARATOR . basename($pkgfile);
if (PEAR::isError($tmpdir = $this->mkTempDir())) {
+ chdir($oldcwd);
return $tmpdir;
}
$this->log(2, '+ tmp dir created at ' . $tmpdir);
$tar = new Archive_Tar($pkgfile, true);
if (!$tar->extract($tmpdir)) {
+ chdir($oldcwd);
return $this->raiseError("Unable to unpack $pkgfile");
}
$file = basename($pkgfile);
// Assume the decompressed dir name
if (($pos = strrpos($file, '.')) === false) {
+ chdir($oldcwd);
return $this->raiseError('package doesn\'t follow the package name convention');
}
$pkgdir = substr($file, 0, $pos);
$descfile = $tmpdir . DIRECTORY_SEPARATOR . $pkgdir . DIRECTORY_SEPARATOR . 'package.xml';
if (!is_file($descfile)) {
+ chdir($oldcwd);
return $this->raiseError("No package.xml file after extracting the archive.");
}
// Parse xml file -----------------------------------------------
$pkginfo = $this->infoFromDescriptionFile($descfile);
if (PEAR::isError($pkginfo)) {
+ chdir($oldcwd);
return $pkginfo;
}
// Copy files to dest dir ---------------------------------------
if (!is_dir($this->phpdir)) {
+ chdir($oldcwd);
return $this->raiseError("No script destination directory found\n",
null, PEAR_ERROR_DIE);
}
$fname = $tmp_path . DIRECTORY_SEPARATOR . $fname;
$this->_installFile($fname, $dest_dir, $atts);
}
+ chdir($oldcwd);
return true;
}
$this->log(1, "installed file $dest_file");
return true;
}
+
// }}}
}
+
?>
\ No newline at end of file
require_once 'PEAR.php';
require_once 'PEAR/Config.php';
require_once 'PEAR/Remote.php';
+require_once 'PEAR/Registry.php';
require_once 'Console/Getopt.php';
error_reporting(E_ALL ^ E_NOTICE);
// {{{ config file and option parsing
-$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sS");
+$options = Console_Getopt::getopt($argv, "c:C:d:D:h?sSqv");
if (PEAR::isError($options)) {
usage($options);
}
$config = new PEAR_Config($pear_user_config, $pear_default_config);
$store_user_config = false;
$store_default_config = false;
+$verbose = 0;
foreach ($opts as $opt) {
$param = $opt[1];
case 'S':
$store_default_config = true;
break;
+ case 'v':
+ $verbose++;
+ break;
+ case 'q':
+ $verbose--;
+ break;
}
}
$ext_dir = $config->get("ext_dir");
$doc_dir = $config->get("doc_dir");
+$command = $options[1][1];
+$rest = array_slice($options[1], 2);
+
+$command_options = array(
+ "list" => "v",
+);
+
+if (isset($command_options[$command])) {
+ $tmp = Console_Getopt::getopt($rest, $command_options[$command]);
+ if (PEAR::isError($tmp)) {
+ usage($tmp);
+ }
+ $cmdopt = $tmp[0];
+ $cmdargs = $tmp[1];
+} else {
+ $cmdopt = array();
+ $cmdargs = $rest;
+}
+
+
// }}}
-$command = $options[1][1];
switch ($command) {
// {{{ install
}
// }}}
- // {{{ list-packages
+ // {{{ list
+
+ case 'list': {
+ $reg = new PEAR_Registry;
+ $installed = $reg->packageInfo();
+ $i = $j = 0;
+ print "Installed packages:\n===================\n";
+ foreach ($installed as $package) {
+ if ($i++ % 20 == 0) {
+ if ($j++ > 0) {
+ print "\n";
+ }
+ printf("%-20s %-10s %-15s %s\n",
+ "Package", "Stable", "Lead", "Category");
+ print str_repeat("=", 75)."\n";
+ }
+ $stable = $package['stable'];
+ printf("%-20s %-10s %-15s %s\n", $package['name'],
+ $stable ? $stable : "???",
+ $package['lead'], $package['category']);
+ }
+ break;
+ }
+
+ // }}}
+ // {{{ list-remote
- case 'list-packages': {
+ case 'list-remote': {
$remote = new PEAR_Remote($config);
$result = $remote->call('package.listAll');
$i = $j = 0;
+ print "Available packages:\n===================\n";
foreach ($result as $package) {
if ($i++ % 20 == 0) {
if ($j++ > 0) {
fputs($stderr,
"Usage: pear [options] command <parameters>\n".
"Options:\n".
- " -v set verbosity level to <n> (0-2, default 1)\n".
- " -p <dir> set script install dir (absolute path)\n".
- " -e <dir> set extension install dir (absolute path)\n".
- " -d <dir> set documentation dest dir (absolute path)\n".
- " -h, -? display help/usage (this message)\n".
+ " -v increase verbosity level (default 1)\n".
+ " -q be quiet, decrease verbosity level\n".
+ " -c file find user configuration in `file'\n".
+ " -C file find system configuration in `file'\n".
+ " -d foo=bar set user config variable `foo' to `bar'\n".
+ " -D foo=bar set system config variable `foo' to `bar'\n".
+ " -s store user configuration\n".
+ " -s store system configuration\n".
+ " -h, -? display help/usage (this message)\n".
"Commands:\n".
" install <package file>\n".
" package [package info file]\n".
+ " list\n".
+ " list-remote\n".
"\n");
fclose($stderr);
exit;