function doMakeRPM($command, $options, $params)
 {
     require_once 'System.php';
     require_once 'Archive/Tar.php';
     if (sizeof($params) != 1) {
         return $this->raiseError("bad parameter(s), try \"help {$command}\"");
     }
     if (!file_exists($params[0])) {
         return $this->raiseError("file does not exist: {$params['0']}");
     }
     $reg =& $this->config->getRegistry();
     $pkg =& $this->getPackageFile($this->config, $this->_debug);
     $pf =& $pkg->fromAnyFile($params[0], PEAR_VALIDATE_NORMAL);
     if (PEAR::isError($pf)) {
         $u = $pf->getUserinfo();
         if (is_array($u)) {
             foreach ($u as $err) {
                 if (is_array($err)) {
                     $err = $err['message'];
                 }
                 $this->ui->outputData($err);
             }
         }
         return $this->raiseError("{$params['0']} is not a valid package");
     }
     $tmpdir = System::mktemp(array('-d', 'pear2rpm'));
     $instroot = System::mktemp(array('-d', 'pear2rpm'));
     $tmp = $this->config->get('verbose');
     $this->config->set('verbose', 0);
     $installer = $this->getInstaller($this->ui);
     require_once 'PEAR/Downloader/Package.php';
     $pack = new PEAR_Downloader_Package($installer);
     $pack->setPackageFile($pf);
     $params[0] =& $pack;
     $installer->setOptions(array('installroot' => $instroot, 'nodeps' => true, 'soft' => true));
     $installer->setDownloadedPackages($params);
     $info = $installer->install($params[0], array('installroot' => $instroot, 'nodeps' => true, 'soft' => true));
     $pkgdir = $pf->getPackage() . '-' . $pf->getVersion();
     $info['rpm_xml_dir'] = '/var/lib/pear';
     $this->config->set('verbose', $tmp);
     if (isset($options['spec-template'])) {
         $spec_template = $options['spec-template'];
     } else {
         $spec_template = '@DATA-DIR@/PEAR/template.spec';
     }
     $info['possible_channel'] = '';
     $info['extra_config'] = '';
     if (isset($options['rpm-pkgname'])) {
         $rpm_pkgname_format = $options['rpm-pkgname'];
     } else {
         if ($pf->getChannel() == 'pear.php.net' || $pf->getChannel() == 'pecl.php.net') {
             $alias = 'PEAR';
         } else {
             $chan =& $reg->getChannel($pf->getChannel());
             $alias = $chan->getAlias();
             $alias = strtoupper($alias);
             $info['possible_channel'] = $pf->getChannel() . '/';
         }
         $rpm_pkgname_format = $alias . '::%s';
     }
     $info['extra_headers'] = '';
     $info['doc_files'] = '';
     $info['files'] = '';
     $info['package2xml'] = '';
     $info['rpm_package'] = sprintf($rpm_pkgname_format, $pf->getPackage());
     $srcfiles = 0;
     foreach ($info['filelist'] as $name => $attr) {
         if (!isset($attr['role'])) {
             continue;
         }
         $name = preg_replace('![/:\\\\]!', '/', $name);
         if ($attr['role'] == 'doc') {
             $info['doc_files'] .= " {$name}";
             // Map role to the rpm vars
         } else {
             $c_prefix = '%{_libdir}/php/pear';
             switch ($attr['role']) {
                 case 'php':
                     $prefix = $c_prefix;
                     break;
                 case 'ext':
                     $prefix = '%{_libdir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'src':
                     $srcfiles++;
                     $prefix = '%{_includedir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'test':
                     $prefix = "{$c_prefix}/tests/" . $pf->getPackage();
                     break;
                 case 'data':
                     $prefix = "{$c_prefix}/data/" . $pf->getPackage();
                     break;
                 case 'script':
                     $prefix = '%{_bindir}';
                     break;
                 default:
                     // non-standard roles
                     $prefix = "{$c_prefix}/{$attr['role']}/" . $pf->getPackage();
                     $info['extra_config'] .= "\n        -d {$attr[role]}_dir={$c_prefix}/{$attr[role]} \\";
                     $this->ui->outputData('WARNING: role "' . $attr['role'] . '" used, ' . 'and will be installed in "' . $c_prefix . '/' . $attr['role'] . '/' . $pf->getPackage() . ' - hand-edit the final .spec if this is wrong', $command);
                     break;
             }
             $name = str_replace('\\', '/', $name);
             $info['files'] .= "{$prefix}/{$name}\n";
         }
     }
     if ($srcfiles > 0) {
         require_once 'OS/Guess.php';
         $os = new OS_Guess();
         $arch = $os->getCpu();
     } else {
         $arch = 'noarch';
     }
     $cfg = array('master_server', 'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'test_dir');
     foreach ($cfg as $k) {
         if ($k == 'master_server') {
             $chan = $reg->getChannel($pf->getChannel());
             $info[$k] = $chan->getServer();
             continue;
         }
         $info[$k] = $this->config->get($k);
     }
     $info['arch'] = $arch;
     $fp = @fopen($spec_template, "r");
     if (!$fp) {
         return $this->raiseError("could not open RPM spec file template {$spec_template}: {$php_errormsg}");
     }
     $info['package'] = $pf->getPackage();
     $info['version'] = $pf->getVersion();
     $info['release_license'] = $pf->getLicense();
     if ($pf->getDeps()) {
         if ($pf->getPackagexmlVersion() == '1.0') {
             $requires = $conflicts = array();
             foreach ($pf->getDeps() as $dep) {
                 if (isset($dep['optional']) && $dep['optional'] == 'yes') {
                     continue;
                 }
                 if ($dep['type'] != 'pkg') {
                     continue;
                 }
                 if (isset($dep['channel']) && $dep['channel'] != 'pear.php.net' && $dep['channel'] != 'pecl.php.net') {
                     $chan =& $reg->getChannel($dep['channel']);
                     $package = strtoupper($chan->getAlias()) . '::' . $dep['name'];
                 } else {
                     $package = 'PEAR::' . $dep['name'];
                 }
                 $trans = array('>' => '>', '<' => '<', '>=' => '>=', '<=' => '<=', '=' => '=', 'gt' => '>', 'lt' => '<', 'ge' => '>=', 'le' => '<=', 'eq' => '=');
                 if ($dep['rel'] == 'has') {
                     $requires[] = $package;
                 } elseif ($dep['rel'] == 'not') {
                     $conflicts[] = $package;
                 } elseif ($dep['rel'] == 'ne') {
                     $conflicts[] = $package . ' = ' . $dep['version'];
                 } elseif (isset($trans[$dep['rel']])) {
                     $requires[] = $package . ' ' . $trans[$dep['rel']] . ' ' . $dep['version'];
                 }
             }
             if (count($requires)) {
                 $info['extra_headers'] .= 'Requires: ' . implode(', ', $requires) . "\n";
             }
             if (count($conflicts)) {
                 $info['extra_headers'] .= 'Conflicts: ' . implode(', ', $conflicts) . "\n";
             }
         } else {
             $info['package2xml'] = '2';
             // tell the spec to use package2.xml
             $requires = $conflicts = array();
             $deps = $pf->getDeps(true);
             if (isset($deps['required']['package'])) {
                 if (!isset($deps['required']['package'][0])) {
                     $deps['required']['package'] = array($deps['required']['package']);
                 }
                 foreach ($deps['required']['package'] as $dep) {
                     if ($dep['channel'] != 'pear.php.net' && $dep['channel'] != 'pecl.php.net') {
                         $chan =& $reg->getChannel($dep['channel']);
                         $package = strtoupper($chan->getAlias()) . '::' . $dep['name'];
                     } else {
                         $package = 'PEAR::' . $dep['name'];
                     }
                     if (isset($dep['conflicts']) && (isset($dep['min']) || isset($dep['max']))) {
                         $deprange = array();
                         if (isset($dep['min'])) {
                             $deprange[] = array($dep['min'], '>=');
                         }
                         if (isset($dep['max'])) {
                             $deprange[] = array($dep['max'], '<=');
                         }
                         if (isset($dep['exclude'])) {
                             if (!is_array($dep['exclude']) || !isset($dep['exclude'][0])) {
                                 $dep['exclude'] = array($dep['exclude']);
                             }
                             if (count($deprange)) {
                                 $excl = $dep['exclude'];
                                 // change >= to > if excluding the min version
                                 // change <= to < if excluding the max version
                                 for ($i = 0; $i < count($excl); $i++) {
                                     if (isset($deprange[0]) && $excl[$i] == $deprange[0][0]) {
                                         $deprange[0][1] = '<';
                                         unset($dep['exclude'][$i]);
                                     }
                                     if (isset($deprange[1]) && $excl[$i] == $deprange[1][0]) {
                                         $deprange[1][1] = '>';
                                         unset($dep['exclude'][$i]);
                                     }
                                 }
                             }
                             if (count($dep['exclude'])) {
                                 $dep['exclude'] = array_values($dep['exclude']);
                                 $newdeprange = array();
                                 // remove excludes that are outside the existing range
                                 for ($i = 0; $i < count($dep['exclude']); $i++) {
                                     if ($dep['exclude'][$i] < $dep['min'] || $dep['exclude'][$i] > $dep['max']) {
                                         unset($dep['exclude'][$i]);
                                     }
                                 }
                                 $dep['exclude'] = array_values($dep['exclude']);
                                 usort($dep['exclude'], 'version_compare');
                                 // take the remaining excludes and
                                 // split the dependency into sub-ranges
                                 $lastmin = $deprange[0];
                                 for ($i = 0; $i < count($dep['exclude']) - 1; $i++) {
                                     $newdeprange[] = '(' . $package . " {$lastmin[1]} {$lastmin[0]} and " . $package . ' < ' . $dep['exclude'][$i] . ')';
                                     $lastmin = array($dep['exclude'][$i], '>');
                                 }
                                 if (isset($dep['max'])) {
                                     $newdeprange[] = '(' . $package . " {$lastmin[1]} {$lastmin[0]} and " . $package . ' < ' . $dep['max'] . ')';
                                 }
                                 $conflicts[] = implode(' or ', $deprange);
                             } else {
                                 $conflicts[] = $package . " {$deprange[0][1]} {$deprange[0][0]}" . (isset($deprange[1]) ? " and {$package} {$deprange[1][1]} {$deprange[1][0]}" : '');
                             }
                         }
                         continue;
                     }
                     if (!isset($dep['min']) && !isset($dep['max']) && !isset($dep['exclude'])) {
                         if (isset($dep['conflicts'])) {
                             $conflicts[] = $package;
                         } else {
                             $requires[] = $package;
                         }
                     } else {
                         if (isset($dep['min'])) {
                             $requires[] = $package . ' >= ' . $dep['min'];
                         }
                         if (isset($dep['max'])) {
                             $requires[] = $package . ' <= ' . $dep['max'];
                         }
                         if (isset($dep['exclude'])) {
                             $ex = $dep['exclude'];
                             if (!is_array($ex)) {
                                 $ex = array($ex);
                             }
                             foreach ($ex as $ver) {
                                 $conflicts[] = $package . ' = ' . $ver;
                             }
                         }
                     }
                 }
                 require_once 'Archive/Tar.php';
                 $tar = new Archive_Tar($pf->getArchiveFile());
                 $tar->pushErrorHandling(PEAR_ERROR_RETURN);
                 $a = $tar->extractInString('package2.xml');
                 $tar->popErrorHandling();
                 if ($a === null || PEAR::isError($a)) {
                     $info['package2xml'] = '';
                     // this doesn't have a package.xml version 1.0
                     $requires[] = 'PEAR::PEAR >= ' . $deps['required']['pearinstaller']['min'];
                 }
                 if (count($requires)) {
                     $info['extra_headers'] .= 'Requires: ' . implode(', ', $requires) . "\n";
                 }
                 if (count($conflicts)) {
                     $info['extra_headers'] .= 'Conflicts: ' . implode(', ', $conflicts) . "\n";
                 }
             }
         }
     }
     // remove the trailing newline
     $info['extra_headers'] = trim($info['extra_headers']);
     if (function_exists('file_get_contents')) {
         fclose($fp);
         $spec_contents = preg_replace('/@([a-z0-9_-]+)@/e', '$info["\\1"]', file_get_contents($spec_template));
     } else {
         $spec_contents = preg_replace('/@([a-z0-9_-]+)@/e', '$info["\\1"]', fread($fp, filesize($spec_template)));
         fclose($fp);
     }
     $spec_file = "{$info['rpm_package']}-{$info['version']}.spec";
     $wp = fopen($spec_file, "wb");
     if (!$wp) {
         return $this->raiseError("could not write RPM spec file {$spec_file}: {$php_errormsg}");
     }
     fwrite($wp, $spec_contents);
     fclose($wp);
     $this->ui->outputData("Wrote RPM spec file {$spec_file}", $command);
     return true;
 }
Exemple #2
0
 /**
  * @param string filename
  * @param array attributes from <file> tag in package.xml
  * @param string path to install the file in
  * @param array options from command-line
  * @access private
  */
 function _installFile($file, $atts, $tmp_path, $options)
 {
     // {{{ return if this file is meant for another platform
     static $os;
     if (!isset($this->_registry)) {
         $this->_registry =& $this->config->getRegistry();
     }
     if (isset($atts['platform'])) {
         if (empty($os)) {
             $os = new OS_Guess();
         }
         if (strlen($atts['platform']) && $atts['platform'][0] == '!') {
             $negate = true;
             $platform = substr($atts['platform'], 1);
         } else {
             $negate = false;
             $platform = $atts['platform'];
         }
         if ((bool) $os->matchSignature($platform) === $negate) {
             $this->log(3, "skipped {$file} (meant for {$atts['platform']}, we are " . $os->getSignature() . ")");
             return PEAR_INSTALLER_SKIPPED;
         }
     }
     // }}}
     $channel = $this->pkginfo->getChannel();
     // {{{ assemble the destination paths
     switch ($atts['role']) {
         case 'doc':
         case 'data':
         case 'test':
             $dest_dir = $this->config->get($atts['role'] . '_dir', null, $channel) . DIRECTORY_SEPARATOR . $this->pkginfo->getPackage();
             unset($atts['baseinstalldir']);
             break;
         case 'ext':
         case 'php':
             $dest_dir = $this->config->get($atts['role'] . '_dir', null, $channel);
             break;
         case 'script':
             $dest_dir = $this->config->get('bin_dir', null, $channel);
             break;
         case 'src':
         case 'extsrc':
             $this->source_files++;
             return;
         default:
             return $this->raiseError("Invalid role `{$atts['role']}' for file {$file}");
     }
     $save_destdir = $dest_dir;
     if (!empty($atts['baseinstalldir'])) {
         $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
     }
     if (dirname($file) != '.' && empty($atts['install-as'])) {
         $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'];
     }
     $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
     // Clean up the DIRECTORY_SEPARATOR mess
     $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
     list($dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), array(DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), array($dest_file, $orig_file));
     $final_dest_file = $installed_as = $dest_file;
     if (isset($this->_options['packagingroot'])) {
         $installedas_dest_dir = dirname($final_dest_file);
         $installedas_dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
         $final_dest_file = $this->_prependPath($final_dest_file, $this->_options['packagingroot']);
     } else {
         $installedas_dest_dir = dirname($final_dest_file);
         $installedas_dest_file = $installedas_dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
     }
     $dest_dir = dirname($final_dest_file);
     $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
     // }}}
     if (empty($this->_options['register-only']) && !@is_dir($dest_dir)) {
         if (!$this->mkDirHier($dest_dir)) {
             return $this->raiseError("failed to mkdir {$dest_dir}", PEAR_INSTALLER_FAILED);
         }
         $this->log(3, "+ mkdir {$dest_dir}");
     }
     // pretty much nothing happens if we are only registering the install
     if (empty($this->_options['register-only'])) {
         if (empty($atts['replacements'])) {
             if (!file_exists($orig_file)) {
                 return $this->raiseError("file {$orig_file} does not exist", PEAR_INSTALLER_FAILED);
             }
             if (!@copy($orig_file, $dest_file)) {
                 return $this->raiseError("failed to write {$dest_file}", PEAR_INSTALLER_FAILED);
             }
             $this->log(3, "+ cp {$orig_file} {$dest_file}");
             if (isset($atts['md5sum'])) {
                 $md5sum = md5_file($dest_file);
             }
         } else {
             // {{{ file with replacements
             if (!file_exists($orig_file)) {
                 return $this->raiseError("file does not exist", PEAR_INSTALLER_FAILED);
             }
             if (function_exists('file_get_contents')) {
                 $contents = file_get_contents($orig_file);
             } else {
                 $fp = fopen($orig_file, "r");
                 $contents = @fread($fp, filesize($orig_file));
                 fclose($fp);
             }
             if ($contents === false) {
                 $contents = '';
             }
             if (isset($atts['md5sum'])) {
                 $md5sum = md5($contents);
             }
             $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 {
                         if (!isset($options['soft'])) {
                             $this->log(0, "invalid php-const replacement: {$a['to']}");
                         }
                         continue;
                     }
                 } elseif ($a['type'] == 'pear-config') {
                     if ($a['to'] == 'master_server') {
                         $chan = $this->_registry->getChannel($channel);
                         if (!PEAR::isError($chan)) {
                             $to = $chan->getServer();
                         } else {
                             $to = $this->config->get($a['to'], null, $channel);
                         }
                     } else {
                         $to = $this->config->get($a['to'], null, $channel);
                     }
                     if (is_null($to)) {
                         if (!isset($options['soft'])) {
                             $this->log(0, "invalid pear-config replacement: {$a['to']}");
                         }
                         continue;
                     }
                 } elseif ($a['type'] == 'package-info') {
                     if ($t = $this->pkginfo->packageInfo($a['to'])) {
                         $to = $t;
                     } else {
                         if (!isset($options['soft'])) {
                             $this->log(0, "invalid package-info replacement: {$a['to']}");
                         }
                         continue;
                     }
                 }
                 if (!is_null($to)) {
                     $subst_from[] = $a['from'];
                     $subst_to[] = $to;
                 }
             }
             $this->log(3, "doing " . sizeof($subst_from) . " substitution(s) for {$final_dest_file}");
             if (sizeof($subst_from)) {
                 $contents = str_replace($subst_from, $subst_to, $contents);
             }
             $wp = @fopen($dest_file, "wb");
             if (!is_resource($wp)) {
                 return $this->raiseError("failed to create {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED);
             }
             if (fwrite($wp, $contents) === false) {
                 return $this->raiseError("failed writing to {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED);
             }
             fclose($wp);
             // }}}
         }
         // {{{ check the md5
         if (isset($md5sum)) {
             if (strtolower($md5sum) == strtolower($atts['md5sum'])) {
                 $this->log(2, "md5sum ok: {$final_dest_file}");
             } else {
                 if (empty($options['force'])) {
                     // delete the file
                     @unlink($dest_file);
                     if (!isset($options['ignore-errors'])) {
                         return $this->raiseError("bad md5sum for file {$final_dest_file}", PEAR_INSTALLER_FAILED);
                     } else {
                         if (!isset($options['soft'])) {
                             $this->log(0, "warning : bad md5sum for file {$final_dest_file}");
                         }
                     }
                 } else {
                     if (!isset($options['soft'])) {
                         $this->log(0, "warning : bad md5sum for file {$final_dest_file}");
                     }
                 }
             }
         }
         // }}}
         // {{{ set file permissions
         if (!OS_WINDOWS) {
             if ($atts['role'] == 'script') {
                 $mode = 0777 & ~(int) octdec($this->config->get('umask'));
                 $this->log(3, "+ chmod +x {$dest_file}");
             } else {
                 $mode = 0666 & ~(int) octdec($this->config->get('umask'));
             }
             $this->addFileOperation("chmod", array($mode, $dest_file));
             if (!@chmod($dest_file, $mode)) {
                 if (!isset($options['soft'])) {
                     $this->log(0, "failed to change mode of {$dest_file}");
                 }
             }
         }
         // }}}
         $this->addFileOperation("rename", array($dest_file, $final_dest_file, $atts['role'] == 'ext'));
     }
     // Store the full path where the file was installed for easy unistall
     $this->addFileOperation("installed_as", array($file, $installed_as, $save_destdir, dirname(substr($installedas_dest_file, strlen($save_destdir)))));
     //$this->log(2, "installed: $dest_file");
     return PEAR_INSTALLER_OK;
 }
Exemple #3
0
 /**
  * This makes unit-testing a heck of a lot easier
  */
 function matchSignature($pattern)
 {
     return $this->_os->matchSignature($pattern);
 }
Exemple #4
0
 /**
  * Operating system  dependencies check method
  *
  * @param string $os  Name of the operating system
  *
  * @return mixed bool false if no error or the error string
  */
 function checkOS(&$errmsg, $os)
 {
     // XXX Fixme: Implement a more flexible way, like
     // comma separated values or something similar to PEAR_OS
     static $myos;
     if (empty($myos)) {
         $myos = new OS_Guess();
     }
     // only 'has' relation is currently supported
     if ($myos->matchSignature($os)) {
         return false;
     }
     $errmsg = "'{$os}' operating system not supported";
     return PEAR_DEPENDENCY_CONFLICT;
 }
Exemple #5
0
 /** 
  * Resolve the system name
  *
  * @access private
  */
 function _setSystemName()
 {
     $OS_Guess = new OS_Guess();
     $sysname = $OS_Guess->getSysname();
     /* Nasty hack for Debian, as it uses a custom ping version */
     if ('linux' == $sysname) {
         if (file_exists('/etc/debian_version')) {
             $sysname = 'debian';
         }
     }
     return $sysname;
 }
Exemple #6
0
 function doMakeRPM($command, $options, $params)
 {
     if (sizeof($params) != 1) {
         return $this->raiseError("bad parameter(s), try \"help {$command}\"");
     }
     if (!file_exists($params[0])) {
         return $this->raiseError("file does not exist: {$params['0']}");
     }
     include_once "Archive/Tar.php";
     include_once "PEAR/Installer.php";
     include_once "System.php";
     $tar = new Archive_Tar($params[0]);
     $tmpdir = System::mktemp('-d pear2rpm');
     $instroot = System::mktemp('-d pear2rpm');
     $tmp = $this->config->get('verbose');
     $this->config->set('verbose', 0);
     $installer = new PEAR_Installer($this->ui);
     $info = $installer->install($params[0], array('installroot' => $instroot, 'nodeps' => true));
     $pkgdir = "{$info['package']}-{$info['version']}";
     $info['rpm_xml_dir'] = '/var/lib/pear';
     $this->config->set('verbose', $tmp);
     if (!$tar->extractList("package.xml", $tmpdir, $pkgdir)) {
         return $this->raiseError("failed to extract {$params['0']}");
     }
     if (!file_exists("{$tmpdir}/package.xml")) {
         return $this->raiseError("no package.xml found in {$params['0']}");
     }
     if (isset($options['spec-template'])) {
         $spec_template = $options['spec-template'];
     } else {
         $spec_template = $this->config->get('data_dir') . '/PEAR/template.spec';
     }
     if (isset($options['rpm-pkgname'])) {
         $rpm_pkgname_format = $options['rpm-pkgname'];
     } else {
         $rpm_pkgname_format = "PEAR::%s";
     }
     $info['extra_headers'] = '';
     $info['doc_files'] = '';
     $info['files'] = '';
     $info['rpm_package'] = sprintf($rpm_pkgname_format, $info['package']);
     $srcfiles = 0;
     foreach ($info['filelist'] as $name => $attr) {
         if ($attr['role'] == 'doc') {
             $info['doc_files'] .= " {$name}";
             // Map role to the rpm vars
         } else {
             $c_prefix = '%{_libdir}/php/pear';
             switch ($attr['role']) {
                 case 'php':
                     $prefix = $c_prefix;
                     break;
                 case 'ext':
                     $prefix = '%{_libdir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'src':
                     $srcfiles++;
                     $prefix = '%{_includedir}/php';
                     break;
                     // XXX good place?
                 // XXX good place?
                 case 'test':
                     $prefix = "{$c_prefix}/tests/" . $info['package'];
                     break;
                 case 'data':
                     $prefix = "{$c_prefix}/data/" . $info['package'];
                     break;
                 case 'script':
                     $prefix = '%{_bindir}';
                     break;
             }
             $info['files'] .= "{$prefix}/{$name}\n";
         }
     }
     if ($srcfiles > 0) {
         include_once "OS/Guess.php";
         $os = new OS_Guess();
         $arch = $os->getCpu();
     } else {
         $arch = 'noarch';
     }
     $cfg = array('master_server', 'php_dir', 'ext_dir', 'doc_dir', 'bin_dir', 'data_dir', 'test_dir');
     foreach ($cfg as $k) {
         $info[$k] = $this->config->get($k);
     }
     $info['arch'] = $arch;
     $fp = @fopen($spec_template, "r");
     if (!$fp) {
         return $this->raiseError("could not open RPM spec file template {$spec_template}: {$php_errormsg}");
     }
     $spec_contents = preg_replace('/@([a-z0-9_-]+)@/e', '$info["\\1"]', fread($fp, filesize($spec_template)));
     fclose($fp);
     $spec_file = "{$info['rpm_package']}-{$info['version']}.spec";
     $wp = fopen($spec_file, "wb");
     if (!$wp) {
         return $this->raiseError("could not write RPM spec file {$spec_file}: {$php_errormsg}");
     }
     fwrite($wp, $spec_contents);
     fclose($wp);
     $this->ui->outputData("Wrote RPM spec file {$spec_file}", $command);
     return true;
 }
 function _installFile($file, $atts, $tmp_path)
 {
     static $os;
     if (isset($atts['platform'])) {
         if (empty($os)) {
             include_once "OS/Guess.php";
             $os = new OS_Guess();
         }
         // return if this file is meant for another platform
         if (!$os->matchSignature($atts['platform'])) {
             $this->log(3, "skipped {$file} (meant for {$atts['platform']}, we are " . $os->getSignature() . ")");
             return PEAR_INSTALLER_SKIPPED;
         }
     }
     switch ($atts['role']) {
         case 'doc':
         case 'data':
         case 'test':
             $dest_dir = $this->config->get($atts['role'] . '_dir') . DIRECTORY_SEPARATOR . $this->pkginfo['package'];
             unset($atts['baseinstalldir']);
             break;
         case 'ext':
         case 'php':
             $dest_dir = $this->config->get($atts['role'] . '_dir');
             break;
         case 'script':
             $dest_dir = $this->config->get('bin_dir');
             break;
         case 'src':
         case 'extsrc':
             $this->source_files++;
             return;
         default:
             return $this->raiseError("Invalid role `{$atts['role']}' for file {$file}");
     }
     if (!empty($atts['baseinstalldir'])) {
         $dest_dir .= DIRECTORY_SEPARATOR . $atts['baseinstalldir'];
     }
     if (dirname($file) != '.' && empty($atts['install-as'])) {
         $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'];
     }
     $orig_file = $tmp_path . DIRECTORY_SEPARATOR . $file;
     // Clean up the DIRECTORY_SEPARATOR mess
     $ds2 = DIRECTORY_SEPARATOR . DIRECTORY_SEPARATOR;
     list($dest_file, $orig_file) = preg_replace(array('!\\\\+!', '!/!', "!{$ds2}+!"), DIRECTORY_SEPARATOR, array($dest_file, $orig_file));
     $installed_as = $dest_file;
     $final_dest_file = $this->_prependPath($dest_file, $this->installroot);
     $dest_dir = dirname($final_dest_file);
     $dest_file = $dest_dir . DIRECTORY_SEPARATOR . '.tmp' . basename($final_dest_file);
     if (!@is_dir($dest_dir)) {
         if (!$this->mkDirHier($dest_dir)) {
             return $this->raiseError("failed to mkdir {$dest_dir}", PEAR_INSTALLER_FAILED);
         }
         $this->log(3, "+ mkdir {$dest_dir}");
     }
     if (empty($atts['replacements'])) {
         if (!@copy($orig_file, $dest_file)) {
             return $this->raiseError("failed to write {$dest_file}", PEAR_INSTALLER_FAILED);
         }
         $this->log(3, "+ cp {$orig_file} {$dest_file}");
         if (isset($atts['md5sum'])) {
             $md5sum = md5_file($dest_file);
         }
     } else {
         $fp = fopen($orig_file, "r");
         $contents = fread($fp, filesize($orig_file));
         fclose($fp);
         if (isset($atts['md5sum'])) {
             $md5sum = md5($contents);
         }
         $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']);
             } elseif ($a['type'] == 'package-info') {
                 $to = $this->pkginfo[$a['to']];
             }
             if ($to) {
                 $subst_from[] = $a['from'];
                 $subst_to[] = $to;
             }
         }
         $this->log(3, "doing " . sizeof($subst_from) . " substitution(s) for {$final_dest_file}");
         if (sizeof($subst_from)) {
             $contents = str_replace($subst_from, $subst_to, $contents);
         }
         $wp = @fopen($dest_file, "w");
         if (!is_resource($wp)) {
             return $this->raiseError("failed to create {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED);
         }
         if (!fwrite($wp, $contents)) {
             return $this->raiseError("failed writing to {$dest_file}: {$php_errormsg}", PEAR_INSTALLER_FAILED);
         }
         fclose($wp);
     }
     if (isset($md5sum)) {
         if ($md5sum == $atts['md5sum']) {
             $this->log(3, "md5sum ok: {$final_dest_file}");
         } else {
             $this->log(0, "warning : bad md5sum for file {$final_dest_file}");
         }
     }
     if (!OS_WINDOWS) {
         if ($atts['role'] == 'script') {
             $mode = 0777 & ~(int) octdec($this->config->get('umask'));
             $this->log(3, "+ chmod +x {$dest_file}");
         } else {
             $mode = 0666 & ~(int) octdec($this->config->get('umask'));
         }
         $this->addFileOperation("chmod", array($mode, $dest_file));
         if (!@chmod($dest_file, $mode)) {
             $this->log(0, "failed to change mode of {$dest_file}");
         }
     }
     $this->addFileOperation("rename", array($dest_file, $final_dest_file));
     // XXX SHOULD BE DONE ONLY AFTER COMMIT
     // Store the full path where the file was installed for easy unistall
     $this->pkginfo['filelist'][$file]['installed_as'] = $installed_as;
     //$this->log(2, "installed: $dest_file");
     return PEAR_INSTALLER_OK;
 }
Exemple #8
0
 /**
  * Factory for Net_Traceroute
  *
  * Call this method to create a new instance of Net_Traceroute
  *
  * @return object Net_Traceroute
  * @access public
  */
 function factory()
 {
     $OS_Guess = new OS_Guess();
     $sysname = $OS_Guess->getSysname();
     $traceroute_path = '';
     if (($traceroute_path = Net_Traceroute::_setTraceroutePath($sysname)) == NET_TRACEROUTE_CANT_LOCATE_TRACEROUTE_BINARY) {
         return PEAR::throwError(NET_TRACEROUTE_CANT_LOCATE_TRACEROUTE_BINARY_MSG, NET_TRACEROUTE_CANT_LOCATE_TRACEROUTE_BINARY);
     } else {
         return new Net_Traceroute($traceroute_path, $sysname);
     }
 }
Exemple #9
0
 /** 
  * Resolve the system name
  *
  * @access private
  */
 function _setSystemName()
 {
     $OS_Guess = new OS_Guess();
     $sysname = $OS_Guess->getSysname();
     // Refine the sysname for different Linux bundles/vendors. (This
     // should go away if OS_Guess was ever extended to give vendor
     // and vendor-version guesses.)
     //
     // Bear in mind that $sysname is eventually used to craft a
     // method name to figure out which backend gets used to parse
     // the ping output. Elsewhere, we'll set $sysname back before
     // that.
     if ('linux' == $sysname) {
         if (file_exists('/etc/lsb-release') && false !== ($release = @file_get_contents('/etc/lsb-release')) && preg_match('/gutsy/i', $release)) {
             $sysname = 'linuxredhat9';
         } else {
             if (file_exists('/etc/debian_version')) {
                 $sysname = 'linuxdebian';
             } else {
                 if (file_exists('/etc/redhat-release') && false !== ($release = @file_get_contents('/etc/redhat-release'))) {
                     if (preg_match('/release 8/i', $release)) {
                         $sysname = 'linuxredhat8';
                     } elseif (preg_match('/release 9/i', $release)) {
                         $sysname = 'linuxredhat9';
                     }
                 }
             }
         }
     }
     return $sysname;
 }
Exemple #10
0
 /**
  * Constructor; initializes the system variable.
  */
 function System_Folders()
 {
     $og = new OS_Guess();
     $this->sys = $og->getSysname();
 }
Exemple #11
0
//lets look at some pear
echo PHP_EOL;
//C:\php\pear\docs\XML_Util\examples\example.php
require_once 'XML/Util.php';
/**
 * building document type declaration
 */
print 'building DocType declaration:<br>';
print htmlspecialchars(XML_Util::getDocTypeDeclaration('package', 'http://pear.php.net/dtd/package-1.0'));
print "\n<br><br>\n";
$modes = mcrypt_list_modes();
echo "mcrypt_list_modes <br>\n";
echo print_r_xml($modes);
//F:\bit5411\php\PEAR\OS\Guess.php  class OS_Guess
require_once 'OS/Guess.php';
$phpwhat = new OS_Guess();
//$phpwhat = OS_Guess::getSignature();  //fatal this
$tmp = $phpwhat->getSignature();
echo $tmp;
echo PHP_EOL;
$tmp = $phpwhat->getSysname();
echo $tmp;
echo PHP_EOL;
$tmp = $phpwhat->getNodename();
echo $tmp;
echo PHP_EOL;
$tmp = $phpwhat->getCpu();
echo $tmp;
echo PHP_EOL;
$tmp = $phpwhat->getRelease();
echo $tmp;