⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 install.inc

📁 用来优化php载入速度
💻 INC
📖 第 1 页 / 共 5 页
字号:
<?php/*   +----------------------------------------------------------------------+   | Zend installation class                                              |   +----------------------------------------------------------------------+   | Copyright (c) 1998-2005 Zend Technologies Ltd.                       |   +----------------------------------------------------------------------+   | The contents of this source file is the sole property of             |   | Zend Technologies Ltd.  Unauthorized duplication or access is        |   | prohibited.                                                          |   +----------------------------------------------------------------------+   | Authors: Michael Spector <michael@zend.com>                          |   |          Anya Tarnyavsky <anya@zend.com>                             |   +----------------------------------------------------------------------+*/error_reporting (E_ALL);include_once ('basic_install.inc');include_once("gaugebox.inc");include_once ('license_downloader.inc');if(defined('SERIAL_NUMBER')){	include_once("forms.inc");}if (!defined ('LOG_FILE')) {	define ('LOG_FILE', getcwd()."/install.log");}class Install extends BasicInstall{	var $forms;  /* forms for displaying more complex dialogs */	function Install ($product, $version="")	{		set_time_limit(0);		error_reporting(E_ALL ^ E_NOTICE);		print ("Please, wait ...\n");		parent::BasicInstall();		global $_SERVER;		# Parse command line arguments:		$argc = count ($_SERVER["argv"]);		$argv = $_SERVER["argv"];		$this->cmdline_arg = array();		$this->cmdline_arg["__options"] = array();		for ($i=1; $i < $argc; $i++) {			if (preg_match ('/^\-\-?(.*)$/', $argv[$i], $match)) {				if (isset ($argv[$i+1]) && !preg_match ('/^\-\-?/', $argv[$i+1])) {					$this->cmdline_arg[strtolower($match[1])] = $argv[$i+1];					$argc++;				} else {					$this->cmdline_arg[strtolower($match[1])] = true;				}			} else {				$this->cmdline_arg["__options"][] = $argv[$i];			}		}		$this->cmdline_args = array (			"help" => "Show this help", 			"answers-file 'file'" => "Read installation configuration from file",			"save-answers 'file'" => "Save installation configuration to file"		);		// the following overriddes logger and error handler from the basic class		$this->logger = new InstallLogger (LOG_FILE);		$this->error_handler = new InstallErrorHandler ($this);		$this->conf['product'] = $product;		//$this->conf['version'] = $version;		//$this->conf['title'] = "$product $version";		$this->conf['backtitle'] = "$product Installation";		$this->conf['install_guide'] = 1;  // by default, there is Installation Guide		$this->conf['backup_suffix'] = "-". strtolower(preg_replace("/[\s\/]+/", "_", $product)).".bak";		$this->conf['progress_bar_started'] = false;		$this->conf['wrap_size'] = 75;		$this->conf['php_ini_opened'] = false;		$this->logger->log ("Starting installation of $product $version ...");		// define system information		// $uname = posix_uname();		$this->conf['uname'] = $this->my_uname();		if(empty($this->conf['uname']['nodename'])){			$this->conf['uname']['nodename'] = "localhost";		}		$this->logger->log ('System: ' . $this->conf['uname']['sysname'] .				   ' ' . $this->conf['uname']['release'] .				   ' ' . $this->conf['uname']['machine']);		$this->logger->log ('Hostname: ' . $this->conf['uname']['nodename']);		$this->conf['nl'] = "\n";		$this->conf['zend_ext_directive'] = "zend_extension";		if ($this->conf['uname']['sysname'] == "HP-UX") {			$this->conf['so_ext'] = ".sl";		} else {			$this->conf['so_ext'] = ".so";		}		// determine temporary directory		$this->conf['tmp_dir'] = getenv("ZEND_TMPDIR");		unset ($_ENV["ZEND_TMPDIR"]);		if(empty($this->conf['tmp_dir'])){			$this->conf['tmp_dir'] = "/tmp".$this->conf['slash']."zend_install.". getmypid();		}		$this->logger->log ('Setting TEMP=' . $this->conf['tmp_dir']);		// and create it		$this->my_delete($this->conf['tmp_dir']);		$this->my_mkdir($this->conf['tmp_dir']);		chmod($this->conf['tmp_dir'],0700);		$this->conf['interactive'] = true;		# Read default config values		$answers_file = null;		if (isset ($this->cmdline_arg["answers-file"])) {			$answers_file = $this->cmdline_arg["answers-file"];			if (!$this->my_file_exists ($answers_file)) {				$file = $this->search_file(array("../", "../data"), array($answers_file));				if (!empty ($file)) {					$answers_file = $file;				} else {				  $this->on_error ("{${answers_file}}: file doesn't exist!");				}			}		} else {			$config_file = strtolower(preg_replace("/\s+/", "_", $product)).".conf";			$answers_file = $this->search_file(array("../", "../data"), array($config_file));		}		if(!empty ($answers_file)) {			$default_config = parse_ini_file($answers_file);			foreach ($default_config as $name => $val) {				$this->conf[$name] = $val;			}			$this->conf['interactive'] = false;		}		$this->conf['webserver'] = "Web server";		$this->conf['comp_dirs_arr'] = array( /* possible directories where to get install components  */				1 =>  "../data",				2 =>  "../install",				3 =>  "../",				4 =>  "/"				);		// initialize components array		$this->conf['components'] = array();		$this->conf['webserver_docroot_arr'] = array();		// initialize file permissions		if($this->my_file_exists("permissions")){			$file_perms = file("permissions");			foreach ($file_perms as $num => $line){				if(preg_match("/^\s*\#/", $line) || preg_match("/^\s*$/", $line)){					continue;				}				list($file, $mode, $owner, $group) = preg_split("/\s+/", $line); // file mode owner group				$this->conf['file_perms'][$num] = array($file, $mode, $owner, $group);			}		}		else{			$this->conf['file_perms'] = array();		}		$this->conf['build_info'] = array();		$inventory_file = $this->search_file(array("../", "../data"), array("Inventory.xml"));		if($this->my_file_exists($inventory_file)) {			$inventory = $this->file2str ($inventory_file);			if(preg_match ("/\<Package\s+.*version=\"([^\"]+)\".*\>/iU", $inventory, $match)) {			  //$this->conf['build_info']['package.version'] = rtrim(preg_replace("/RC.*$/", "", $this->tag2version ($match[1])), '_');			  $this->conf['build_info']['package.version'] = $this->tag2version ($match[1]);			}			if(preg_match_all ("/\<Component\s([^\>]+)\>/iU", $inventory, $match)) {				for ($i=0; $i<count($match[0]); $i++) {					if(preg_match ("/version\=\"([^\"]+)\"/i", $match[1][$i], $ver_match)						&& preg_match ("/name\=\"([^\"]+)\"/i", $match[1][$i], $name_match)) {					  $name = preg_replace ("/-php-.*$/", "", $name_match[1]);					  					  $this->conf['build_info']["${name}.version"] = 					    $this->tag2version ($ver_match[1], $name);					}				}			}		}		// if version is specified as argument to ctor, take it, otherwise rely		// on one automatically determined from Inventory.xml		$this->conf['version'] = (empty ($version) ? 					  $this->conf['build_info']['package.version'] : $version);		$this->conf['title'] = "$product " . $this->conf['version'];		// compose version, as should be submitted for license download mechanism		if (empty ($this->conf['release']))		  {		    // $this->on_error("Undefined release name");		    $this->conf['release'] = 'release';		    $release = '0';		  }		elseif (preg_match ("/^beta(.)$/", $this->conf['release'], $arr))		  {		    $release = $arr[1];		  }		else		  {		    $release = '99'; // invalid build_id		  }		// this thingy is needed for license download; probably we should		// catch it later, somewhere in get_license() or in license_downloader.inc;		// otherwise (like for zend core) it is just not needed		/*		if(empty($this->conf['product_id'])){			$this->on_error("Undefined product ID");		}		*/		$this->conf['version_for_license'] = $this->conf['version'] . '-' . $release;				// get the basename of the calling script		$basename = basename(getenv("CALLING_SCRIPT"));		unset ($_ENV["CALLING_SCRIPT"]);		if ($basename == "install-tty" || !$this->conf['interactive']) {			unset($this->conf['dialog']);		} else {			$dialog = "./dialog";			if(!$this->my_file_exists($dialog)){			  $this->on_error ("File: $dialog does not exist!");			}			if(!is_executable($dialog)){				chmod($dialog, 0555);			}			$this->conf['dialog'] = $dialog;		}		if(defined('SERIAL_NUMBER')){			$this->forms =& new Forms($this, !empty($this->conf['dialog']));		}		if(!empty($this->conf['dialog'])){ // set common dialog setup			$this->conf['dialog'] .= sprintf(" --clear --backtitle %s --title %s",				escapeshellarg ($this->conf['backtitle']),				escapeshellarg ($this->conf['title'])			);			$this->conf['max_x'] = 78; // default size			$this->conf['max_y'] = 24;			$this->conf['dialog_tmp'] = $this->conf['tmp_dir'] . "/dialog.tmpfile";			$this->conf['dialog_error'] = "Error while executing the dialog utility.\n".                                                "Probable reason - wrong terminal settings.\n".				                "Please use install-tty instead.";		}		$this->conf['php_ini_backup_msg'] = "";		$this->conf['lic_error_file'] = "error.txt";		$this->conf['license_installed'] = false;		$this->restore_config();		foreach ($this->conf['saved_config'] as $key => $val) {			$this->conf[$key] = $val;		}		$this->conf['min_space_size'] = $this->my_du("../data");		$this->conf['installer_dir'] = dirname(getcwd());		$this->conf['installer_path'] = $this->conf['installer_dir'].":".$this->make_path($this->conf['installer_dir'], "data").":".$this->make_path($this->conf['installer_dir'], "zui_files");		// needed for searching zendid in path		putenv ('PATH=' . $this->conf['installer_path'] . ':' . getenv ('PATH'));	} // end of ctor	// ===================================	// Command line arguments functions	// ===================================	function add_cmdline_args ($options)	{		$this->cmdline_args = array_merge ($this->cmdline_args, $options);		$this->check_bad_arguments();		if ($this->get_cmdline_arg ("help") || $this->get_cmdline_arg ("h")) {			$this->help_and_die();		}	}	function help_and_die ($err=null)	{		$prog = getenv("CALLING_SCRIPT");		if ($err) {			$err = "ERROR: {$err}\n";		}		$help = <<<EOF{$err}USAGE: {$prog} [OPTIONS]Where OPTIONS are:EOF;		$space = 0;		foreach ($this->cmdline_args as $opt => $descr) {			if (strlen ($opt) > $space) {				$space = strlen ($opt);			}		}		$space += 12;		foreach ($this->cmdline_args as $opt => $descr) {			$help .= "--{$opt}".str_repeat (" ", $space-strlen($opt)).$descr."\n";		}		$this->msgbox ($help);		$this->cleanup();		die(-1);	}	function get_cmdline_arg($name)	{		return (isset($this->cmdline_arg[$name]) ? $this->cmdline_arg[$name] : null);	}	function check_bad_arguments()	{		$args = array();		foreach ($this->cmdline_args as $arg => $descr) {			$args[preg_replace ('/\s.*/', '', $arg)] = true;		}		foreach ($this->cmdline_arg as $arg => $val) {			if ($arg == "__options") continue;			if (!isset ($args[$arg])) {				$this->help_and_die ("Bad option: --{$arg}");			}		}	}	// ------------------	// SYSTEM FUNCTIONS	// ==================	// parms: 0 - tag (like OPTIMIZER_2_6_2_RC4_20060104)	//        1 - (optional) component name (like 'optimizer')	// returns: version (like 2.6.2)	function tag2version ($tag, $name=null)	{	  if (isset ($name))	    {	      // don't take into account '-ts' suffix in name, if any	      $name = preg_replace ('/-ts$/', '', $name);	      // strip the component name from the beginning of the tag, if any	      $tag = preg_replace ("/^$name/i", '', $tag);	    }	  if (preg_match ('/\w?_(\d+)_(\d+)_(\d+[a-z]?|[a-zA-Z0-9]+?)_?((ALPHA|BETA)\d*?)?_?RC(\d+)_/', $tag, $match)) 	    {	      $version = "{$match[1]}.{$match[2]}.{$match[3]}";	    } 	  else 	    {	      $version = $tag;	    }	  // it still could be something like 2.1.2RC7, so stripping out RC part	  return (preg_replace ('/RC.*$/', '', $version));	  //$version = preg_replace ('/_/', '.', $version);	  //return ($version);	} // end of tag2version()	function my_uname()	{		$uname = array();		$uname["sysname"]   = $this->cmd2str("uname -s 2>/dev/null");		$uname["machine"]   = ($uname["sysname"] == "Linux" ?			$this->cmd2str("uname -m 2>/dev/null") : $this->cmd2str("uname -p 2>/dev/null"));		$uname["release"]   = $this->cmd2str("uname -r 2>/dev/null");		$uname["nodename"]  = $this->cmd2str("uname -n 2>/dev/null");		if ($uname["sysname"]=="AIX") {			$major = $this->cmd2str("uname -v 2>/dev/null");			$uname["release"] = $major.'.'.$uname["release"];		}		foreach ($uname as $name => $val) {			if($val == "") {				$uname[$name] = "unknown";			}		}		return $uname;	}	// GUESS_DOMAINNAME	function guess_domainname()	{		$cmd = $this->search_cmd_in_path ("domainname", true);		if ($cmd) {			return str_replace ("(none)", "", $this->cmd2str ("{$cmd} 2>/dev/null"));		}		return "";	}	// GUESS_GLIBC_VERSION	function guess_glibc_version()	{		$glibc_ver = "";		if($this->conf['uname']['sysname'] == "Linux") {		  $glibc_path = $this->cmd2str ('/bin/ls /lib{,64}/{libc,ld}-?.?.* 2>/dev/null');			if(@preg_match("/(\d)\.(\d)/", $glibc_path, $match)) {				$glibc_ver = "$match[1].$match[2]";				$this->logger->log ("Detected GLIBC version: $glibc_ver");			}		}		return $glibc_ver;	}	// GET_RELEASE_VERSION	function get_release_version()	{		$release = $this->conf['uname']['release'];		if(preg_match("/^(\d+\.\d+)/", $this->conf['uname']['release'], $match)) {			$release = $match[1];		}		$this->logger->log ("Detected release version: $release");		return $release;	}	// CHECK_SYSTEM_SUPPORTED	function check_system_supported()	{		if(!isset($this->conf['supported_systems'][$this->conf['uname']['sysname']])) {			$error = "OS type: ".$this->conf['uname']['sysname'];		}		else {			$sysconf = $this->conf['supported_systems'][$this->conf['uname']['sysname']];			if(count($sysconf) > 0) {				if(isset($sysconf["glibc"])) {					$glibc_arr = $sysconf["glibc"];					$glibc_OK = true;					foreach($glibc_arr as $glibc) {						$glibc_OK = false;						if(preg_match("/^([\>\<]?)(.*)$/", $glibc, $match)) {							$installed_glibc = $this->guess_glibc_version();							if(($match[1] == ">" && version_compare($installed_glibc, $match[2]) >= 0)									|| ($match[1] == "<" && version_compare($installed_glibc, $match[2]) <= 0)									|| $this->ver_equal($installed_glibc, $glibc)) {								// Glibc version is OK								$glibc_OK = true;								break;							}						}					}					if(!$glibc_OK) {						$error = "GLIBC version: $installed_glibc";					}				}				if(!isset($error) && isset($sysconf["release"])) {					$release_arr = $sysconf["release"];					$release_OK = true;					foreach($release_arr as $release) {						$release_OK = false;						if(preg_match("/^([\>\<]?)(.*)$/", $release, $match)) {							$installed_release = $this->get_release_version();							if(  ($match[1] == ">" && version_compare($installed_release, $match[2]) >= 0)									|| ($match[1] == "<" && version_compare($installed_release, $match[2]) <= 0)									|| $this->ver_equal($installed_release, $release)) {								// Release is OK								$release_OK = true;								break;							}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -