📄 install.inc
字号:
} } if(!$release_OK) { $error = "OS release: $installed_release"; } } if(!isset($error) && isset($sysconf["machine"])) { $machine_arr = $sysconf["machine"]; $machine_OK = true; foreach($machine_arr as $machine) { $machine_OK = false; if($machine == $this->conf['uname']['machine']) { // Processor type is OK $machine_OK = true; break; } } if(!$machine_OK) { $error = "processor type: ".$this->conf['uname']['machine']; } } } } if(isset($error)) { $this->yesnobox("The installation detected that this package is not compatible with your\nsystem configuration.\n". "It seems that you have an unsupported $error\n". "Do you still wish to continue the installation?\n". "For list of supported configurations, please refer to the Zend Product\ncompatibility table.", true, true); } } // ------------------ // BASIC FUNCTIONS // ================== // CLRSCR function clrscr() { $this->run_command("clear"); } // WELCOME_BOX function welcome_box($msg="", $addtext="") { if(!isset($this->conf['dialog'])) { // Clear screen before showing the "welcome" message $this->clrscr(); } if($msg == ""){ $msg = "Welcome to the ".$this->conf['product']." ".$this->conf['version']." Installation!\n\n"; // by default, we assume there is Installation Guide if ($this->conf['install_guide'] == 1) { $msg .= "For more information regarding this procedure, please see the\n"; $msg .= $this->conf['product']." Installation Guide.\n"; } if(!empty($addtext)){ $msg .= "\n$addtext"; } } $this->msgbox($msg); } // BYE_BYE function bye_bye($url="", $msg="", $need_restart=true, $know_port=false) { $this->save_answers_file(); $this->clrscr(); print "\n\n\n\n\n\n\n"; print "******************************************************************************\n"; print "\n"; if(!empty($msg)){ print "{$msg}\n"; } if(!$this->conf['license_installed']){ print " [7;1mYou must [0m[37;44;1mINSTALL the license[0m[7;1m files from ". "Zend.com to your installation directory[0m\n"; print "\n"; } if($need_restart){ if(isset($this->conf['php_type']) && $this->conf['php_type'] == "fastcgi"){ print " [7;1mYou must [0m[37;44;1mRESTART your FastCGI[0m[7;1m for the ". "modifications to take effect[0m\n"; print "\n"; } else{ print " [7;1mYou must [0m[37;44;1mRESTART your ".$this->conf['webserver']."[0m[7;1m for the ". "modifications to take effect[0m\n"; print "\n"; } } if(!empty($url)) { print " You can access the ".$this->conf['product']."'s User Interface using the URL:\n"; print " $url\n"; print "\n"; if(!$know_port && !preg_match("@:\d+/@", $url)){ $url_with_port = preg_replace("@://([^/]*)/@", "://\\1:<port-number>/", $url); print " If your Web server is running on port different from the default\n"; print " port 80, you should access the ".$this->conf['product']." as\n"; print " $url_with_port\n"; print "\n"; } } print "\n"; print "******************************************************************************\n\n\n\n\n\n"; $this->logger->log ('Bye bye ... :)'); } // RUN_COMMAND function run_command($cmd, $err_msg="", $need_logging=true) { $tmpfile = tempnam ($this->conf['tmp_dir'], "cmd"); if ($tmpfile) { $fp = popen("$cmd 2> {$tmpfile}", "w"); } else { $fp = popen("$cmd 2> /dev/null", "w"); } if(empty($fp)){ $this->on_error ("Can't execute command: $cmd" . (strlen($err_msg) > 0 ? "\nERROR: $err_msg" : '')); } $status = $this->safe_pclose($fp); if ($need_logging) { $this->logger->log ("Executing: \"$cmd\" (status: $status)"); if ($status != 0 && $tmpfile) { $error = @trim($this->file2str ($tmpfile)); if (@strlen ($error) > 0) { $this->logger->log ("Error was: {$error}"); } @unlink ($tmpfile); } } return $status; } // NICE_PATH function nice_path($path) /* removes all multiple slashes */ { /* remove multiple slashes from the path */ $path = preg_replace("/\/\/\/*/", "/", $path); /* multiple '/' */ $path = preg_replace("/^\.\//", "", $path); /* first './' from the path */ $path = preg_replace("/\/\.\//", "/", $path); /* '/./' from the path */ $path = preg_replace("/^[^\/]+\/\.\.\/?/", "", $path); /* dir/.. from the beginning */ $path = preg_replace("/\/[^\/]+\/\.\.\/?/", "/", $path); /* /dir/.. from the path */ $path = preg_replace("/([^\/])\/+$/", "\\1", $path); /* last / from the end of path */ return $path; } // ADD_DASHES function add_dashes($msg) { $dashes_len = 0; /* define dashes line under the menu title */ $tmp_len = 0; for($i=0; $i<strlen($msg); $i++){ if($msg[$i] == "\n" || $msg[$i] == "\r"){ if($tmp_len > $dashes_len){ $dashes_len = $tmp_len; $tmp_len = 0; } } else{ $tmp_len ++; } } if($dashes_len == 0){ $dashes_len = $tmp_len; } if($dashes_len > $this->conf['wrap_size']){ $dashes_len = $this->conf['wrap_size']; } $dashes = str_repeat("-", $dashes_len); return "$msg\n$dashes"; } // MY_DU function my_du($filename) { $total_size = 0; if($this->my_dir_exists($filename)) { $dir = $this->my_opendir($filename); while($file = readdir($dir)){ if($file == "." || $file == ".."){ continue; } $total_size += $this->my_du($this->make_path($filename, $file)); } closedir($dir); } else if($this->my_file_exists($filename)) { $total_size = filesize($filename); } return $total_size; } // SIZE_HUMAN function size_human($size) { if($size > 1048576) { return round($size/1048576, 1)."MB"; } else if($size > 1024) { return round($size/1024, 1)."KB"; } else return round($size, 1)." bytes"; } // EXPAND_TILDE function expand_tilde($path) /* converts tilde to a real path */ { if(preg_match("/^~(.*)$/", $path, $match1)) { if(preg_match("/^([\w]+)(.*)$/", $match1[1], $match2)) { $pwd = $this->run_silently("posix_getpwnam", $match2[1]); if(!empty($pwd)) { $path = $this->make_path($pwd["dir"], $match2[2]); } } else { $path = $this->make_path(getenv("HOME"), $match1[1]); } } return $path; } // IS_EMAIL_VALID function is_email_valid($email) { return preg_match("/^(.+)\@(.+)\.(.+)$/", $email); } // IS_IP_VALID function is_ip_valid($ip) { if (preg_match ('/^\d+\.\d+\.\d+\.\d+$/', $ip) && @ip2long ($ip) !== -1) { return true; } return false; } // GET_BUILD_INFO function get_build_info() { return $this->conf['build_info']; } // INI_ARRAY_REBUILD function ini_array_rebuild($ini_arr,$translation_arr) { if (!is_array($ini_arr) or !is_array($translation_arr)) return array(); if (empty($ini_arr) or empty($translation_arr)) return array(); $result=array(); foreach ($ini_arr as $directive=>$value) { foreach ($translation_arr as $prefix=>$translated_prefix) { $prefix_length=strlen($prefix); if (strncmp($prefix,$directive,$prefix_length)==0) { $translated_directive=$translated_prefix.substr($directive,$prefix_length); $result[$translated_directive]=$value; } } } return $result; } // VER_EQUAL function ver_equal($version1, $version2, $from=0) { $ver_arr1 = preg_split("/[\.\_]/", $version1); $ver_arr2 = preg_split("/[\.\_]/", $version2); if(count($ver_arr1) != count($ver_arr2)){ return false; } for($i = 0; $i < count($ver_arr1); $i++){ if(($ver_arr1[$i]!=$ver_arr2[$i]) && ($ver_arr1[$i]!='x') && ($ver_arr2[$i]!='x')){ return false; } if(($ver_arr1[$i]!=$ver_arr2[$i]) && ($ver_arr1[$i]=='x') && ($from != 0) && ($ver_arr2[$i] < $from)){ return false; } } return true; } // ARRAY2STRING function array2string($array, $index=-1) { $str = ""; foreach ($array as $num => $data){ if($index==-1){ $str .= $data.$this->conf['nl']; } else{ $str .= $data[$index].$this->conf['nl']; } } return $str; } // ARRAY2PHP_SUPPORT_STRING function array2php_support_string($array, $index=-1, $from_index=-1) { $str = ""; foreach ($array as $num => $data){ if($index==-1){ $str .= $data.$this->conf['nl']; } else{ if($from_index != -1 && $data[$from_index] != 0){ $sub_str=substr($data[$index],0 ,(strlen($data[$index])-1) ); $str .= $sub_str.$data[$from_index]." and above".$this->conf['nl']; }else{ $str .= $data[$index].$this->conf['nl']; } } } return $str; } // WARN function warn($msg) { $this->infobox($msg); } // ON_ABORT function on_abort($msg = "", $dont_ask=false) /* die with error message */ { if(!$this->conf['interactive']) { $dont_ask = true; } if(!$dont_ask && !$this->yesnobox("Do you really wish to abort the installation?", true)) { return; } $this->logger->log ("ABORT: $msg"); $this->save_config(); $this->php_ini_restore(); if(strlen($msg) > 0) { $msg = "\n$msg"; } $this->msgbox($this->conf['product']." installation was aborted.$msg"); $this->cleanup(); die(-1); } // DEFAULT_ABORT function default_abort() { $this->on_abort("The installation was NOT completed successfully.", true); } // CLEANUP function cleanup() { $this->logger->log ('Cleaning up ...'); /* Save installation log */ if (isset($this->conf['prefix'])) { $this->my_mkdir_long ($this->conf['prefix'].'/logs'); //$this->logger->store ($this->conf['prefix'].'/logs'); $this->my_copy ($this->logger->logfile_name, $this->conf['prefix'] . '/logs'); } $this->my_delete($this->conf['tmp_dir']); } // SAVE_ANSWERS_FILE function save_answers_file() { $answers_file = $this->get_cmdline_arg("save-answers"); $save_file = ''; if ($answers_file) { foreach ($this->conf as $key => $val) { if (is_numeric ($val) || is_string ($val) && strlen ($val) < 20) { $save_file .= "{$key}={$val}\n"; } } $this->str2file ($save_file, $answers_file); } } // SAVE_CONFIG function save_config() { if(!empty($this->conf['saved_config'])) { $this->str2file(serialize($this->conf['saved_config']), "install.sav"); } } // RESTORE_CONFIG function restore_config() { if($this->my_file_exists("install.sav")) { $this->conf['saved_config'] = unserialize($this->file2str("install.sav")); } else $this->conf['saved_config'] = array(); } // SEARCH_DIR function search_dir($dirs_array) { foreach ($dirs_array as $dir){ /* searches for an existent directory in an array of paths */ if($this->my_dir_exists($dir)){ return $dir; } } return ""; } // SEARCH_FILE function search_file($dirs_array, $files_arr) { foreach ($dirs_array as $dir){ /* searches for an existent directory and file in an array of paths */ if($this->my_dir_exists($dir)){ foreach($files_arr as $file){ if($this->my_file_exists($this->make_path($dir, $file))){ return $this->make_path($dir, $file); } } } } return ""; } // SELECT_DIR function select_dir($msg, $default="", $create=false) { while(true){ $dir = $this->choose_dir($msg, $default); $dir = $this->nice_path($dir); if(!$this->my_dir_exists($dir)){ if($this->my_file_exists($dir)){ $this->msgbox("\"$dir\" must be a directory!"); } else{ if ($create) { if ($this->yesnobox ("Directory: \"$dir\" doesn't exist!\nWould you like this directory to be created?")) { $this->my_mkdir_long ($dir); break; } } else $this->msgbox("Directory: \"$dir\" doesn't exist!"); } } else{ break; } } return $dir; } // SELECT_FILE_NOSTRIP function select_file_nostrip($msg, $default="", $accept_empty=false) { while(true) { $file = $this->inputbox($msg, $default, $accept_empty); if ((empty($file) || $file == -1) && $accept_empty) { return null; } $file = $this->nice_path($file); if(!$this->my_file_exists($file)){ if($this->my_dir_exists($file)){ $this->msgbox("\"$file\" must be a file!"); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -