From 4c330e5a99567e7ce44353a9bba111c915752f1e Mon Sep 17 00:00:00 2001 From: Tim Almdal Date: Sat, 10 Jan 2009 20:47:38 +0000 Subject: Continuing baby steps to a batch installer. At this point you can run the installer and it will parse the command line arguments. currently the following arguments are accepted -h(database host) -u(database user) -p(database password) -d(database name) -t(table prefex) or -f(a response file). The order of processing, defaults are set. if the response file is provided, the contained values are merged and finally any command line parameters are merged. --- index.php | 6 +- installer/helpers/installer.php | 230 +++++++++++++++++++++++++++++++++++++ installer/helpers/system_check.php | 180 ----------------------------- installer/install.php | 69 +++++++++++ 4 files changed, 302 insertions(+), 183 deletions(-) create mode 100644 installer/helpers/installer.php delete mode 100644 installer/helpers/system_check.php create mode 100644 installer/install.php diff --git a/index.php b/index.php index b1f9eccb..ac285645 100644 --- a/index.php +++ b/index.php @@ -46,9 +46,9 @@ define('THEMEPATH', strtr(realpath('themes') . '/', DIRECTORY_SEPARATOR, '/')); define('SYSPATH', strtr(realpath('kohana') . '/', DIRECTORY_SEPARATOR, '/')); if (!file_exists('var')) { - include DOCROOT . "installer/helpers/system_check.php"; - if (system_check::failed()) { - system_check::display_requirements(); + include DOCROOT . "installer/helpers/installer.php"; + if (installer::failed()) { + installer::display_requirements(); die; } } diff --git a/installer/helpers/installer.php b/installer/helpers/installer.php new file mode 100644 index 00000000..2c7e39ff --- /dev/null +++ b/installer/helpers/installer.php @@ -0,0 +1,230 @@ + true, + "text" => sprintf("Gallery3 requires PHP 5.2 or newer, current version: %s.", PHP_VERSION)); + $failed = true; + } else { + self::$messages["PHP Version"] = array("error" => false, + "text" => PHP_VERSION); + } + + + if (!(is_dir(SYSPATH) AND is_file(SYSPATH.'core/Bootstrap'.EXT))) { + self::$messages["Kohana Directory"] = array("error" => true, + "text" => "The configured Kohana directory does not exist or does not contain the required files."); + } else { + self::$messages["Kohana Directory"] = array("error" => false, + "text" => SYSPATH); + } + + if (!(is_dir(APPPATH) AND is_file(APPPATH.'config/config'.EXT))) { + self::$messages["Application Directory"] = array("error" => true, + "text" => "The configured Gallery3 application directory does not exist or does not contain the required files."); + $failed = true; + } else { + self::$messages["Application Directory"] = array("error" => false, + "text" => APPPATH); + } + + if (!(is_dir(MODPATH))) { + self::$messages["Modules Directory"] = array("error" => true, + "text" => "The configured Gallery3 modules directory does not exist or does not contain the required files."); + $failed = true; + } else { + self::$messages["Modules Directory"] = array("error" => false, + "text" => MODPATH); + } + + if (!(is_dir(THEMEPATH))) { + self::$messages["Theme Directory"] = array("error" => true, + "text" => "The configured Gallery3 themes directory does not exist or does not contain the required files."); + $failed = true; + } else { + self::$messages["Themes Directory"] = array("error" => false, + "text" => THEMEPATH); + } + + if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) { + self::$messages["PCRE UTF-8"] = array("error" => true, + "text" => "Perl-Compatible Regular Expressions has not been compiled with UTF-8 support.", + "html" => "PCRE has not been compiled with UTF-8 support."); + $failed = true; + } else if (!@preg_match("/^\pL$/u", utf8_encode("\xF1"))) { + self::$messages["PCRE UTF-8"] = array("error" => true, + "text" => "Perl-Compatible Regular Expressions has not been compiled with Unicode support.", + "html" => "PCRE has not been compiled with Unicode property support."); + $failed = true; + } else { + self::$messages["PCRE UTF-8"] = array("error" => false, + "text" => "Pass"); + } + + if (!(class_exists("ReflectionClass"))) { + self::$messages["Reflection Enabled"] = array("error" => true, + "text" => "PHP relection is either not loaded or not compiled in.", + "html" => "PHP relection is either not loaded or not compiled in."); + $failed = true; + } else { + self::$messages["Reflection Enabled"] = array("error" => false, + "text" => "Pass"); + } + + if (!(function_exists("filter_list"))) { + self::$messages["Filters Enabled"] = array("error" => true, + "text" => "The filter extension is either not loaded or not compiled in.", + "html" => "The filter extension is either not loaded or not compiled in."); + $failed = true; + } else { + self::$messages["Filters Enabled"] = array("error" => false, + "text" => "Pass"); + } + + if (!(extension_loaded("iconv"))) { + self::$messages["Iconv Loaded"] = array("error" => true, + "text" => "The iconv extension is not loaded.", + "html" => "The iconv extension is not loaded."); + $failed = true; + } else { + self::$messages["Iconv Enabled"] = array("error" => false, + "text" => "Pass"); + } + + if (extension_loaded("mbstring") && + (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) { + self::$messages["Mbstring Overloaded"] = array("error" => true, + "text" => "The mbstring extension is overloading PHP's native string functions.", + "html" => "The mbstring extension is overloading PHP's native string functions."); + $failed = true; + } else { + self::$messages["MbString Overloaded"] = array("error" => false, + "text" => "Pass"); + } + + if (!(isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["PHP_SELF"]))) { + self::$messages["URI Determination"] = array("error" => true, + "text" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available.", + "html" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available."); + $failed = true; + } else { + self::$messages["URI Determination"] = array("error" => false, + "text" => "Pass"); + } + + $short_tags = ini_get("short_open_tag"); + if (empty($short_tags)) { + self::$messages["Short Tags"] = array("error" => true, + "text" => "Gallery3 requires that PHP short tags be enabled.", + "html" => "Gallery3 requires that PHP short tags be enabled"); + $failed = true; + } else { + self::$messages["Short Tags"] = array("error" => false, + "text" => "Pass"); + } + return $failed; + } + + public static function display_requirements() { + if (PHP_SAPI == 'cli') { + print self::_render("installer/views/installer.txt"); + } else { + print self::_render("installer/views/installer.html"); + } + } + +/* -h Database host (default: localhost) + * -u Database user (default: root) + * -p Database user password (default: ) + * -d Database name (default: gallery3) + * -t Table prefix (default: ) + * -f Response file (default: not used) + * The response file is a php file that contains the following syntax; + * $config[key] = value; + * Where key is one of "host", "user", "password", "dbname", "prefix". Values specified + * on the command line will override values contained in this file + */ + public function parse_cli_parms($argv) { + for ($i=0; $i < count($argv); $i++) { + switch (strtolower($argv[$i])) { + case "-d": + $arguments["dbname"] = $argv[++$i]; + break; + case "-h": + $arguments["host"] = $argv[++$i]; + break; + case "-u": + $arguments["user"] = $argv[++$i]; + break; + case "-p": + $arguments["password"] = $argv[++$i]; + break; + case "-t": + $arguments["prefix"] = $argv[++$i]; + break; + case "-f": + $arguments["file"] = $argv[++$i]; + break; + } + } + + $config = array("host" => "localhost", "user" => "root", "password" => "", + "dbname" => "gallery3", "prefix" => ""); + + if (!empty($arguments["file"])) { + if (file_exists($arguments["file"])) { + include $arguments["file"]; + } + unset($arguments["file"]); + } + self::$config = array_merge($config, $arguments); + + var_dump(self::$config); + } + + private static function _render($view) { + if ($view == '') + return; + + // Buffering on + ob_start(); + + try + { + // Views are straight HTML pages with embedded PHP, so importing them + // this way insures that $this can be accessed as if the user was in + // the controller, which gives the easiest access to libraries in views + include realpath($view . EXT); + } + catch (Exception $e) + { + // Display the exception using its internal __toString method + echo $e; + } + + // Fetch the output and close the buffer + return ob_get_clean(); + } +} \ No newline at end of file diff --git a/installer/helpers/system_check.php b/installer/helpers/system_check.php deleted file mode 100644 index b0bd7e12..00000000 --- a/installer/helpers/system_check.php +++ /dev/null @@ -1,180 +0,0 @@ - true, - "text" => sprintf("Gallery3 requires PHP 5.2 or newer, current version: %s.", PHP_VERSION)); - $failed = true; - } else { - self::$messages["PHP Version"] = array("error" => false, - "text" => PHP_VERSION); - } - - - if (!(is_dir(SYSPATH) AND is_file(SYSPATH.'core/Bootstrap'.EXT))) { - self::$messages["Kohana Directory"] = array("error" => true, - "text" => "The configured Kohana directory does not exist or does not contain the required files."); - } else { - self::$messages["Kohana Directory"] = array("error" => false, - "text" => SYSPATH); - } - - if (!(is_dir(APPPATH) AND is_file(APPPATH.'config/config'.EXT))) { - self::$messages["Application Directory"] = array("error" => true, - "text" => "The configured Gallery3 application directory does not exist or does not contain the required files."); - $failed = true; - } else { - self::$messages["Application Directory"] = array("error" => false, - "text" => APPPATH); - } - - if (!(is_dir(MODPATH))) { - self::$messages["Modules Directory"] = array("error" => true, - "text" => "The configured Gallery3 modules directory does not exist or does not contain the required files."); - $failed = true; - } else { - self::$messages["Modules Directory"] = array("error" => false, - "text" => MODPATH); - } - - if (!(is_dir(THEMEPATH))) { - self::$messages["Theme Directory"] = array("error" => true, - "text" => "The configured Gallery3 themes directory does not exist or does not contain the required files."); - $failed = true; - } else { - self::$messages["Themes Directory"] = array("error" => false, - "text" => THEMEPATH); - } - - if (!@preg_match("/^.$/u", utf8_encode("\xF1"))) { - self::$messages["PCRE UTF-8"] = array("error" => true, - "text" => "Perl-Compatible Regular Expressions has not been compiled with UTF-8 support.", - "html" => "PCRE has not been compiled with UTF-8 support."); - $failed = true; - } else if (!@preg_match("/^\pL$/u", utf8_encode("\xF1"))) { - self::$messages["PCRE UTF-8"] = array("error" => true, - "text" => "Perl-Compatible Regular Expressions has not been compiled with Unicode support.", - "html" => "PCRE has not been compiled with Unicode property support."); - $failed = true; - } else { - self::$messages["PCRE UTF-8"] = array("error" => false, - "text" => "Pass"); - } - - if (!(class_exists("ReflectionClass"))) { - self::$messages["Reflection Enabled"] = array("error" => true, - "text" => "PHP relection is either not loaded or not compiled in.", - "html" => "PHP relection is either not loaded or not compiled in."); - $failed = true; - } else { - self::$messages["Reflection Enabled"] = array("error" => false, - "text" => "Pass"); - } - - if (!(function_exists("filter_list"))) { - self::$messages["Filters Enabled"] = array("error" => true, - "text" => "The filter extension is either not loaded or not compiled in.", - "html" => "The filter extension is either not loaded or not compiled in."); - $failed = true; - } else { - self::$messages["Filters Enabled"] = array("error" => false, - "text" => "Pass"); - } - - if (!(extension_loaded("iconv"))) { - self::$messages["Iconv Loaded"] = array("error" => true, - "text" => "The iconv extension is not loaded.", - "html" => "The iconv extension is not loaded."); - $failed = true; - } else { - self::$messages["Iconv Enabled"] = array("error" => false, - "text" => "Pass"); - } - - if (extension_loaded("mbstring") && - (ini_get("mbstring.func_overload") & MB_OVERLOAD_STRING)) { - self::$messages["Mbstring Overloaded"] = array("error" => true, - "text" => "The mbstring extension is overloading PHP's native string functions.", - "html" => "The mbstring extension is overloading PHP's native string functions."); - $failed = true; - } else { - self::$messages["MbString Overloaded"] = array("error" => false, - "text" => "Pass"); - } - - if (!(isset($_SERVER["REQUEST_URI"]) || isset($_SERVER["PHP_SELF"]))) { - self::$messages["URI Determination"] = array("error" => true, - "text" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available.", - "html" => "Neither \$_SERVER['REQUEST_URI'] or \$_SERVER['PHP_SELF'] is available."); - $failed = true; - } else { - self::$messages["URI Determination"] = array("error" => false, - "text" => "Pass"); - } - - $short_tags = ini_get("short_open_tag"); - if (empty($short_tags)) { - self::$messages["Short Tags"] = array("error" => true, - "text" => "Gallery3 requires that PHP short tags be enabled.", - "html" => "Gallery3 requires that PHP short tags be enabled"); - $failed = true; - } else { - self::$messages["Short Tags"] = array("error" => false, - "text" => "Pass"); - } - return $failed; - } - - public static function display_requirements() { - if (PHP_SAPI == 'cli') { - print self::_render("installer/views/installer.txt"); - } else { - print self::_render("installer/views/installer.html"); - } - } - - private static function _render($view) { - if ($view == '') - return; - - // Buffering on - ob_start(); - - try - { - // Views are straight HTML pages with embedded PHP, so importing them - // this way insures that $this can be accessed as if the user was in - // the controller, which gives the easiest access to libraries in views - include realpath($view . EXT); - } - catch (Exception $e) - { - // Display the exception using its internal __toString method - echo $e; - } - - // Fetch the output and close the buffer - return ob_get_clean(); - } -} \ No newline at end of file diff --git a/installer/install.php b/installer/install.php new file mode 100644 index 00000000..edb571a5 --- /dev/null +++ b/installer/install.php @@ -0,0 +1,69 @@ +