. -------------------------------------------------------------------------- */ /** @file * @brief */ function displayUsage() { die("\nusage: ".$_SERVER['argv'][0]." [ --host= ] --db= --user= [ --pass= ] [ --lang=xx_XX] [ --tests ] [ --force ]\n\n"); } $args = [ 'host' => 'localhost', 'pass' => '']; if ($_SERVER['argc']>1) { for ($i=1 ; $i (isset($args['lang']) ? $args['lang'] : 'en_GB')]; Toolbox::setDebugMode(Session::DEBUG_MODE, 0, 0, 1); echo "Connect to the DB...\n"; //Check if the port is in url $hostport = explode(':', $args['host']); if (count($hostport) < 2) { $link = new mysqli($hostport[0], $args['user'], $args['pass']); } else { $link = new mysqli($hostport[0], $args['user'], $args['pass'], '', $hostport[1]); } if (!$link || mysqli_connect_error()) { die("DB connection failed\n"); } $args['db'] = $link->real_escape_string($args['db']); echo "Create the DB...\n"; if (!$link->query("CREATE DATABASE IF NOT EXISTS `" . $args['db'] ."`")) { die("Can't create the DB\n"); } if (!$link->select_db($args['db'])) { die("Can't select the DB\n"); } echo "Save configuration file...\n"; if (!createMainConfig($args['host'], $args['user'], $args['pass'], $args['db'])) { die("Can't write configuration file\n"); } echo "Load default schema...\n"; createSchema($_SESSION['glpilanguage']); echo "Done\n"; /** * Create the GLPI default schema * * @since 0.90.6 * * @param $lang * * @return nothing **/ function createSchema($lang='en_GB') { global $CFG_GLPI, $DB; include_once (GLPI_CONFIG_DIR . "/config_db.php"); $DB = new DB(); if (!$DB->runFile(GLPI_ROOT ."/install/mysql/glpi-0.90.1-empty.sql")) { echo "Errors occurred inserting default database"; } // update default language Config::setConfigurationValues('core', array('language' => $lang)); $query = "UPDATE `glpi_users` SET `language` = NULL"; $DB->queryOrDie($query, "4203"); } /** * Create GLPI main configuration file * * @since 0.90.6 * * @param $dbhost * @param $user * @param $password * @param $DBname * * @return boolean * **/ function createMainConfig($host, $user, $password, $DBname) { $DB_str = "