function run($command, $options, $params)
{
- $installer = &new PEAR_Installer($this->config->get('php_dir'),
- $this->config->get('ext_dir'),
- $this->config->get('doc_dir'));
+ $installer = &new PEAR_Installer($this->config);
$installer->setFrontend($this->ui);
$installer->debug = $this->config->get('verbose');
* Valid file roles
* @var array
*/
- var $file_roles = array('php','ext','test','doc','data','extsrc');
+ var $file_roles = array('php','ext','test','doc','data','extsrc','script');
+
+ /**
+ * Valid replacement types
+ * @var array
+ */
+ var $replacement_types = array('php-const', 'pear-config');
/**
* User Interface object (PEAR_Frontend_* class). If null,
*/
var $ui = null;
+ var $current_path = null;
+
// }}}
// {{{ constructor
$this->dir_role = $attribs['role'];
}
break;
+ case 'file':
+ if (isset($attribs['name'])) {
+ $path = '';
+ if (count($this->dir_names)) {
+ foreach ($this->dir_names as $dir) {
+ $path .= $dir . DIRECTORY_SEPARATOR;
+ }
+ }
+ $path .= $attribs['name'];
+ unset($attribs['name']);
+ $this->current_path = $path;
+ $this->filelist[$path] = $attribs;
+ // Set the baseinstalldir only if the file don't have this attrib
+ if (!isset($this->filelist[$path]['baseinstalldir']) &&
+ isset($this->dir_install))
+ {
+ $this->filelist[$path]['baseinstalldir'] = $this->dir_install;
+ }
+ // Set the Role
+ if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) {
+ $this->filelist[$path]['role'] = $this->dir_role;
+ }
+ }
+ break;
+ case 'replace':
+ $this->filelist[$this->current_path]['replacements'][] = $attribs;
+ break;
+
case 'libfile':
$this->lib_atts = $attribs;
$this->lib_atts['role'] = 'extsrc';
array_pop($this->dir_names);
break;
case 'file':
- $this->current_file = $data;
- $path = '';
- if (count($this->dir_names)) {
- foreach ($this->dir_names as $dir) {
- $path .= $dir . DIRECTORY_SEPARATOR;
+ if ($data) {
+ $path = '';
+ if (count($this->dir_names)) {
+ foreach ($this->dir_names as $dir) {
+ $path .= $dir . DIRECTORY_SEPARATOR;
+ }
+ }
+ $path .= $data;
+ $this->filelist[$path] = $this->current_attributes;
+ // Set the baseinstalldir only if the file don't have this attrib
+ if (!isset($this->filelist[$path]['baseinstalldir']) &&
+ isset($this->dir_install))
+ {
+ $this->filelist[$path]['baseinstalldir'] = $this->dir_install;
+ }
+ // Set the Role
+ if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) {
+ $this->filelist[$path]['role'] = $this->dir_role;
}
- }
- $path .= $this->current_file;
- $this->filelist[$path] = $this->current_attributes;
- // Set the baseinstalldir only if the file don't have this attrib
- if (!isset($this->filelist[$path]['baseinstalldir']) &&
- isset($this->dir_install))
- {
- $this->filelist[$path]['baseinstalldir'] = $this->dir_install;
- }
- // Set the Role
- if (!isset($this->filelist[$path]['role']) && isset($this->dir_role)) {
- $this->filelist[$path]['role'] = $this->dir_role;
}
break;
case 'libfile':
if (isset($pkginfo['filelist'])) {
$ret .= "$indent <filelist>\n";
foreach ($pkginfo['filelist'] as $file => $fa) {
- if ($fa['role'] == 'extsrc') {
+ if (@$fa['role'] == 'extsrc') {
$ret .= "$indent <libfile>\n";
$ret .= "$indent <libname>$file</libname>\n";
$ret .= "$indent <sources>$fa[sources]</sources>\n";
$ret .= "$indent </libfile>\n";
} else {
- $ret .= "$indent <file role=\"$fa[role]\"";
+ @$ret .= "$indent <file role=\"$fa[role]\"";
if (isset($fa['baseinstalldir'])) {
- $ret .= " baseinstalldir=\"$fa[baseinstalldir]\"";
+ $ret .= ' baseinstalldir="' .
+ htmlspecialchars($fa['baseinstalldir']) . '"';
}
if (isset($fa['md5sum'])) {
$ret .= " md5sum=\"$fa[md5sum]\"";
}
- $ret .= ">$file</file>\n";
+ if (!empty($fa['replace'])) {
+ $ret .= ' replace="yes"';
+ }
+ if (!empty($fa['install-as'])) {
+ $ret .= ' install-as="' .
+ htmlspecialchars($fa['install-as']) . '"';
+ }
+ $ret .= ' name="' . htmlspecialchars($file) . '"';
+ if (empty($fa['replacements'])) {
+ $ret .= "/>\n";
+ } else {
+ $ret .= ">\n";
+ foreach ($fa['replacements'] as $r) {
+ $ret .= "$indent <replace";
+ foreach ($r as $k => $v) {
+ $ret .= " $k=\"" . htmlspecialchars($v) .'"';
+ }
+ $ret .= "/>\n";
+ }
+ @$ret .= "$indent </file>\n";
+ }
}
}
$ret .= "$indent </filelist>\n";
$GLOBALS['_PEAR_Config_instance'] = null;
define('PEAR_CONFIG_DEFAULT_DOCDIR',
- PHP_DATADIR.DIRECTORY_SEPARATOR.'pear'.DIRECTORY_SEPARATOR.'doc');
+ PHP_DATADIR.DIRECTORY_SEPARATOR.'doc'.DIRECTORY_SEPARATOR.'pear');
// in case a --without-pear PHP installation is used
if (!defined('PEAR_INSTALL_DIR')) {
}
/**
- * This is a class for storing simple configuration values keeping
- * track of which are system-defined, user-defined or defaulted. By
- * default, only user-defined settings are stored back to the user's
- * configuration file.
- *
- * Configuration member is a simple associative array. Used keys:
- *
- * master_server which server to query for mirror lists etc.
- * server which server/mirror we're currently using
- * username PEAR username
- * password PEAR password (stored base64-encoded)
- * php_dir Where to install .php files
- * ext_dir Directory to install compiled libs in
- * doc_dir Directory to install documentation in
- *
+ * This is a class for storing configuration data, keeping track of
+ * which are system-defined, user-defined or defaulted.
*/
class PEAR_Config extends PEAR
{
'doc_dir' => array(
'type' => 'directory',
'default' => PEAR_CONFIG_DEFAULT_DOCDIR,
- 'doc' => 'directory where documentation is located',
+ 'doc' => 'directory where documentation is installed',
+ ),
+ 'bin_dir' => array(
+ 'type' => 'directory',
+ 'default' => PHP_BINDIR,
+ 'doc' => 'directory where executables are installed',
),
'username' => array(
'type' => 'string',
}
// }}}
+ // {{{ getLayers()
/**
- * Returns the layers defined (except the 'default' one)
- *
- * @return array of the defined layers
- */
+ * Returns the layers defined (except the 'default' one)
+ *
+ * @return array of the defined layers
+ */
function getLayers()
{
$cf = $this->configuration;
unset($cf['default']);
return array_keys($cf);
}
+
+ // }}}
}
?>
\ No newline at end of file
{
// {{{ properties
- /** name of the package directory, for example Foo-1.0 */
+ /** name of the package directory, for example Foo-1.0
+ * @var string
+ */
var $pkgdir;
- /** directory where PHP code files go */
+ /** directory where PHP code files go
+ * @var string
+ */
var $phpdir;
- /** directory where PHP extension files go */
+ /** directory where PHP extension files go
+ * @var string
+ */
var $extdir;
- /** directory where documentation goes */
+ /** directory where documentation goes
+ * @var string
+ */
var $docdir;
/** directory where the package wants to put files, relative
- * to one of the three previous dirs
+ * to one of the previous dirs
+ * @var string
*/
var $destdir = '';
- /** debug level (integer) */
+ /** debug level
+ * @var int
+ */
var $debug = 1;
- /** temporary directory */
+ /** temporary directory
+ * @var string
+ */
var $tmpdir;
- /** PEAR_Registry object used by the installer */
+ /** PEAR_Registry object used by the installer
+ * @var object
+ */
var $registry;
+ /** PEAR_Config object used by the installer
+ * @var object
+ */
+ var $config;
+
// }}}
// {{{ constructor
- function PEAR_Installer($phpdir = PEAR_INSTALL_DIR,
- $extdir = PEAR_EXTENSION_DIR,
- $docdir = null)
+ function PEAR_Installer(&$config)
{
$this->PEAR();
- $this->phpdir = $phpdir;
- $this->extdir = $extdir;
- if ($docdir === null) {
- $docdir = PHP_DATADIR . DIRECTORY_SEPARATOR . 'pear' .
- DIRECTORY_SEPARATOR . 'doc';
- }
- $this->docdir = $docdir;
+ $this->config = &$config;
}
// }}}
function _installFile($file, $atts, $tmp_path)
{
- $type = strtolower($atts['role']);
- switch ($type) {
- case 'test':
+ switch ($atts['role']) {
+ case 'test': case 'data': case 'ext':
// don't install test files for now
- $this->log(2, "+ Test file $file won't be installed yet");
+ $this->log(2, "+ $file: $atts[role] file not installed yet");
return true;
- break;
case 'doc':
- $dest_dir = $this->docdir . DIRECTORY_SEPARATOR .
- $this->pkginfo['package'];
+ $dest_dir = $this->config->get('doc_dir') .
+ DIRECTORY_SEPARATOR . $this->pkginfo['package'];
break;
+ case 'extsrc':
+ // don't install test files for now
+ $this->log(2, "+ $file: no support for building extensions yet");
+ return true;
case 'php':
- default: {
- $dest_dir = $this->phpdir;
- if (isset($atts['baseinstalldir'])) {
- $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
- }
- if (dirname($file) != '.') {
- $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
- }
+ $dest_dir = $this->config->get('php_dir');
+ break;
+ case 'script': {
+ $dest_dir = $this->config->get('bin_dir');
break;
}
+ default:
+ break;
+ }
+ if (isset($atts['baseinstalldir'])) {
+ $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
+ }
+ if (dirname($file) != '.') {
+ $dest_dir .= DIRECTORY_SEPARATOR . dirname($file);
+ }
+ if (empty($atts['install-as'])) {
+ $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
+ } else {
+ $dest_file = $dest_dir . DIRECTORY_SEPARATOR . $atts['install-as'];
}
- $dest_file = $dest_dir . DIRECTORY_SEPARATOR . basename($file);
if (!@is_dir($dest_dir)) {
if (!$this->mkDirHier($dest_dir)) {
$this->log(0, "failed to mkdir $dest_dir");
$this->log(2, "+ created dir $dest_dir");
}
$orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
- $orig_perms = fileperms($orig_file);
- if (!@copy($orig_file, $dest_file)) {
- $this->log(0, "failed to copy $orig_file to $dest_file");
- return false;
+ if (empty($atts['replacements'])) {
+ if (!@copy($orig_file, $dest_file)) {
+ $this->log(0, "failed to copy $orig_file to $dest_file");
+ return false;
+ }
+ $this->log(2, "+ copy $orig_file to $dest_file");
+ } else {
+ $fp = fopen($orig_file, "r");
+ $contents = fread($fp, filesize($orig_file));
+ fclose($fp);
+ $subst_from = $subst_to = array();
+ foreach ($atts['replacements'] as $a) {
+ $to = '';
+ if ($a['type'] == 'php-const') {
+ if (preg_match('/^[a-z0-9_]+$/i', $a['to'])) {
+ eval("\$to = $a[to];");
+ } else {
+ $this->log(0, "invalid php-const replacement: $a[to]");
+ continue;
+ }
+ } elseif ($a['type'] == 'pear-config') {
+ $to = $this->config->get($a['to']);
+ }
+ if ($to) {
+ $subst_from = $a['from'];
+ $subst_to = $to;
+ }
+ }
+ if (sizeof($subst_from)) {
+ $contents = str_replace($subst_from, $subst_to, $contents);
+ }
+ $wp = @fopen($dest_file, "w");
+ if (!is_resource($wp)) {
+ $this->log(0, "failed to create $dest_file");
+ return false;
+ }
+ fwrite($wp, $contents);
+ fclose($wp);
+ }
+ if (!OS_WINDOWS) {
+ if ($atts['role'] == 'script') {
+ $mode = 0755;
+ } else {
+ $mode = 0644;
+ }
+ if (!@chmod($dest_file, $mode)) {
+ $this->log(0, "failed to change mode of $dest_file");
+ }
}
- chmod($dest_file, $orig_perms);
- $this->log(2, "+ copy $orig_file to $dest_file");
// Store the full path where the file was installed for easy unistall
$this->pkginfo['filelist'][$file]['installed_as'] = $dest_file;
// - soft : fail silently
//
if (empty($this->registry)) {
- $this->registry = new PEAR_Registry($this->phpdir);
+ $this->registry = new PEAR_Registry($this->config->get('php_dir'));
}
$oldcwd = getcwd();
$need_download = false;
// info from the package it self we want to access from _installFile
$this->pkginfo = $pkginfo;
if (empty($options['register_only'])) {
- if (!is_dir($this->phpdir)) {
+ if (!is_dir($this->config->get('php_dir'))) {
chdir($oldcwd);
return $this->raiseError("no script destination directory\n",
null, PEAR_ERROR_DIE);
function uninstall($package)
{
if (empty($this->registry)) {
- $this->registry = new PEAR_Registry($this->phpdir);
+ $this->registry = new PEAR_Registry($this->config->get('php_dir'));
}
// Delete the files
logout
</notes>
<filelist>
- <file type="php" name="PEAR.php"/>
+ <file role="php" name="PEAR.php"/>
<dir name="PEAR">
- <file type="php" name="Autoloader.php"/>
- <file type="php" name="Command.php"/>
+ <file role="php" name="Autoloader.php"/>
+ <file role="php" name="Command.php"/>
<dir name="Command">
- <file type="php" name="Auth.php"/>
- <file type="php" name="Common.php"/>
- <file type="php" name="Config.php"/>
- <file type="php" name="Install.php"/>
- <file type="php" name="Package.php"/>
- <file type="php" name="Registry.php"/>
- <file type="php" name="Remote.php"/>
+ <file role="php" name="Auth.php"/>
+ <file role="php" name="Common.php"/>
+ <file role="php" name="Config.php"/>
+ <file role="php" name="Install.php"/>
+ <file role="php" name="Package.php"/>
+ <file role="php" name="Registry.php"/>
+ <file role="php" name="Remote.php"/>
</dir>
- <file type="php" name="Common.php"/>
- <file type="php" name="Config.php"/>
- <file type="php" name="Dependency.php"/>
+ <file role="php" name="Common.php"/>
+ <file role="php" name="Config.php"/>
+ <file role="php" name="Dependency.php"/>
<dir name="Frontend">
- <file type="php" name="CLI.php"/>
+ <file role="php" name="CLI.php"/>
</dir>
- <file type="php" name="Installer.php"/>
- <file type="php" name="Packager.php"/>
- <file type="php" name="Registry.php"/>
- <file type="php" name="Remote.php"/>
+ <file role="php" name="Installer.php"/>
+ <file role="php" name="Packager.php"/>
+ <file role="php" name="Registry.php"/>
+ <file role="php" name="Remote.php"/>
</dir>
<dir name="scripts">
- <file baseinstalldir="/" type="script" install-as="pear" name="pear.in" replace="yes">
+ <file baseinstalldir="/" role="script" install-as="pear" name="pear.in" replace="yes">
<replace from="@prefix@" to="PHP_PREFIX" type="php-const"/>
</file>
</dir>
<!--
- $Id: package.dtd,v 1.21 2002-04-09 00:03:18 ssb Exp $
+ $Id: package.dtd,v 1.22 2002-04-09 08:10:08 ssb Exp $
This is the PEAR package description, version 1.0b6.
It should be used with the informal public identifier:
platform CDATA #IMPLIED
md5sum CDATA #IMPLIED
name CDATA #REQUIRED
- replace (yes|no) 'no'
install-as CDATA #IMPLIED>
<!ELEMENT replace EMPTY>