Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/admin/cli/install.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00032 define('CLI_SCRIPT', true);
00033 
00034 // extra execution prevention - we can not just require config.php here
00035 if (isset($_SERVER['REMOTE_ADDR'])) {
00036     exit(1);
00037 }
00038 
00039 $help =
00040 "Command line Moodle installer, creates config.php and initializes database.
00041 Please note you must execute this script with the same uid as apache
00042 or use chmod/chown after installation.
00043 
00044 Site defaults may be changed via local/defaults.php.
00045 
00046 Options:
00047 --chmod=OCTAL-MODE    Permissions of new directories created within dataroot.
00048                       Default is 2777. You may want to change it to 2770
00049                       or 2750 or 750. See chmod man page for details.
00050 --lang=CODE           Installation and default site language.
00051 --wwwroot=URL         Web address for the Moodle site,
00052                       required in non-interactive mode.
00053 --dataroot=DIR        Location of the moodle data folder,
00054                       must not be web accessible. Default is moodledata
00055                       in the parent directory.
00056 --dbtype=TYPE         Database type. Default is mysqli
00057 --dbhost=HOST         Database host. Default is localhost
00058 --dbname=NAME         Database name. Default is moodle
00059 --dbuser=USERNAME     Database user. Default is root
00060 --dbpass=PASSWORD     Database password. Default is blank
00061 --dbsocket            Use database sockets. Available for some databases only.
00062 --prefix=STRING       Table prefix for above database tables. Default is mdl_
00063 --fullname=STRING     The fullname of the site
00064 --shortname=STRING    The shortname of the site
00065 --adminuser=USERNAME  Username for the moodle admin account. Default is admin
00066 --adminpass=PASSWORD  Password for the moodle admin account,
00067                       required in non-interactive mode.
00068 --non-interactive     No interactive questions, installation fails if any
00069                       problem encountered.
00070 --agree-license       Indicates agreement with software license,
00071                       required in non-interactive mode.
00072 --allow-unstable      Install even if the version is not marked as stable yet,
00073                       required in non-interactive mode.
00074 -h, --help            Print out this help
00075 
00076 Example:
00077 \$sudo -u www-data /usr/bin/php admin/cli/install.php --lang=cs
00078 "; //TODO: localize, mark as needed in install - to be translated later when everything is finished
00079 
00080 
00081 // distro specific customisation
00082 $distrolibfile = dirname(dirname(dirname(__FILE__))).'/install/distrolib.php';
00083 $distro = null;
00084 if (file_exists($distrolibfile)) {
00085     require_once($distrolibfile);
00086     if (function_exists('distro_get_config')) {
00087         $distro = distro_get_config();
00088     }
00089 }
00090 
00091 // Nothing to do if config.php exists
00092 $configfile = dirname(dirname(dirname(__FILE__))).'/config.php';
00093 if (file_exists($configfile)) {
00094     require($configfile);
00095     require_once($CFG->libdir.'/clilib.php');
00096     list($options, $unrecognized) = cli_get_params(array('help'=>false), array('h'=>'help'));
00097 
00098     if ($options['help']) {
00099         echo $help;
00100         echo "\n\n";
00101     }
00102 
00103     if ($DB->get_manager()->table_exists('config')) {
00104         cli_error(get_string('clialreadyinstalled', 'install'));
00105     } else {
00106         cli_error(get_string('clialreadyconfigured', 'install'));
00107     }
00108 }
00109 
00110 $olddir = getcwd();
00111 
00112 // change directory so that includes below work properly
00113 chdir(dirname($_SERVER['argv'][0]));
00114 
00115 // Servers should define a default timezone in php.ini, but if they don't then make sure something is defined.
00116 // This is a quick hack.  Ideally we should ask the admin for a value.  See MDL-22625 for more on this.
00117 if (function_exists('date_default_timezone_set') and function_exists('date_default_timezone_get')) {
00118     @date_default_timezone_set(@date_default_timezone_get());
00119 }
00120 
00121 // make sure PHP errors are displayed - helps with diagnosing of problems
00122 @error_reporting(E_ALL);
00123 @ini_set('display_errors', '1');
00124 // we need a lot of memory
00125 @ini_set('memory_limit', '128M');
00126 
00128 define('MOODLE_INTERNAL', true);
00129 
00130 // Check that PHP is of a sufficient version
00131 if (version_compare(phpversion(), "5.3.2") < 0) {
00132     $phpversion = phpversion();
00133     // do NOT localise - lang strings would not work here and we CAN NOT move it after installib
00134     fwrite(STDERR, "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).\n");
00135     fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
00136     exit(1);
00137 }
00138 
00139 // set up configuration
00140 $CFG = new stdClass();
00141 $CFG->lang                 = 'en';
00142 $CFG->dirroot              = dirname(dirname(dirname(__FILE__)));
00143 $CFG->libdir               = "$CFG->dirroot/lib";
00144 $CFG->wwwroot              = "http://localhost";
00145 $CFG->httpswwwroot         = $CFG->wwwroot;
00146 $CFG->docroot              = 'http://docs.moodle.org';
00147 $CFG->running_installer    = true;
00148 $CFG->early_install_lang   = true;
00149 
00150 $parts = explode('/', str_replace('\\', '/', dirname(dirname(__FILE__))));
00151 $CFG->admin                = array_pop($parts);
00152 
00153 //point pear include path to moodles lib/pear so that includes and requires will search there for files before anywhere else
00154 //the problem is that we need specific version of quickforms and hacked excel files :-(
00155 ini_set('include_path', $CFG->libdir.'/pear' . PATH_SEPARATOR . ini_get('include_path'));
00156 
00157 require_once($CFG->libdir.'/installlib.php');
00158 require_once($CFG->libdir.'/clilib.php');
00159 require_once($CFG->libdir.'/setuplib.php');
00160 require_once($CFG->libdir.'/textlib.class.php');
00161 require_once($CFG->libdir.'/weblib.php');
00162 require_once($CFG->libdir.'/dmllib.php');
00163 require_once($CFG->libdir.'/moodlelib.php');
00164 require_once($CFG->libdir.'/deprecatedlib.php');
00165 require_once($CFG->libdir.'/adminlib.php');
00166 require_once($CFG->libdir.'/componentlib.class.php');
00167 
00168 require($CFG->dirroot.'/version.php');
00169 $CFG->target_release = $release;
00170 
00171 //Database types
00172 $databases = array('mysqli' => moodle_database::get_driver_instance('mysqli', 'native'),
00173                    'pgsql'  => moodle_database::get_driver_instance('pgsql',  'native'),
00174                    'oci'    => moodle_database::get_driver_instance('oci',    'native'),
00175                    'sqlsrv' => moodle_database::get_driver_instance('sqlsrv', 'native'), // MS SQL*Server PHP driver
00176                    'mssql'  => moodle_database::get_driver_instance('mssql',  'native'), // FreeTDS driver
00177                   );
00178 foreach ($databases as $type=>$database) {
00179     if ($database->driver_installed() !== true) {
00180         unset($databases[$type]);
00181     }
00182 }
00183 if (empty($databases)) {
00184     $defaultdb = '';
00185 } else {
00186     reset($databases);
00187     $defaultdb = key($databases);
00188 }
00189 
00190 // now get cli options
00191 list($options, $unrecognized) = cli_get_params(
00192     array(
00193         'chmod'             => isset($distro->directorypermissions) ? sprintf('%04o',$distro->directorypermissions) : '2777', // let distros set dir permissions
00194         'lang'              => $CFG->lang,
00195         'wwwroot'           => '',
00196         'dataroot'          => empty($distro->dataroot) ? str_replace('\\', '/', dirname(dirname(dirname(dirname(__FILE__)))).'/moodledata'): $distro->dataroot, // initialised later after including libs or by distro
00197         'dbtype'            => empty($distro->dbtype) ? $defaultdb : $distro->dbtype, // let distro skip dbtype selection
00198         'dbhost'            => empty($distro->dbhost) ? 'localhost' : $distro->dbhost, // let distros set dbhost
00199         'dbname'            => 'moodle',
00200         'dbuser'            => empty($distro->dbuser) ? 'root' : $distro->dbuser, // let distros set dbuser
00201         'dbpass'            => '',
00202         'dbsocket'          => false,
00203         'prefix'            => 'mdl_',
00204         'fullname'          => '',
00205         'shortname'         => '',
00206         'adminuser'         => 'admin',
00207         'adminpass'         => '',
00208         'non-interactive'   => false,
00209         'agree-license'     => false,
00210         'allow-unstable'    => false,
00211         'help'              => false
00212     ),
00213     array(
00214         'h' => 'help'
00215     )
00216 );
00217 
00218 $interactive = empty($options['non-interactive']);
00219 
00220 // set up language
00221 $lang = clean_param($options['lang'], PARAM_SAFEDIR);
00222 if (file_exists($CFG->dirroot.'/install/lang/'.$lang)) {
00223     $CFG->lang = $lang;
00224 }
00225 
00226 if ($unrecognized) {
00227     $unrecognized = implode("\n  ", $unrecognized);
00228     cli_error(get_string('cliunknowoption', 'admin', $unrecognized));
00229 }
00230 
00231 if ($options['help']) {
00232     echo $help;
00233     die;
00234 }
00235 
00236 //Print header
00237 echo get_string('cliinstallheader', 'install', $CFG->target_release)."\n";
00238 
00239 //Fist select language
00240 if ($interactive) {
00241     cli_separator();
00242     $languages = get_string_manager()->get_list_of_translations();
00243     // format the langs nicely - 3 per line
00244     $c = 0;
00245     $langlist = '';
00246     foreach ($languages as $key=>$lang) {
00247         $c++;
00248         $length = iconv_strlen($lang, 'UTF-8');
00249         $padded = $lang.str_repeat(' ', 38-$length);
00250         $langlist .= $padded;
00251         if ($c % 3 == 0) {
00252             $langlist .= "\n";
00253         }
00254     }
00255     $default = $CFG->lang;
00256     cli_heading(get_string('availablelangs', 'install'));
00257     echo $langlist."\n";
00258     $prompt = get_string('clitypevaluedefault', 'admin', $CFG->lang);
00259     $error = '';
00260     do {
00261         echo $error;
00262         $input = cli_input($prompt, $default);
00263         $input = clean_param($input, PARAM_SAFEDIR);
00264 
00265         if (!file_exists($CFG->dirroot.'/install/lang/'.$input)) {
00266             $error = get_string('cliincorrectvalueretry', 'admin')."\n";
00267         } else {
00268             $error = '';
00269         }
00270     } while ($error !== '');
00271     $CFG->lang = $input;
00272 } else {
00273     // already selected and verified
00274 }
00275 
00276 // Set directorypermissions first
00277 $chmod = octdec(clean_param($options['chmod'], PARAM_INT));
00278 if ($interactive) {
00279     cli_separator();
00280     cli_heading(get_string('datarootpermission', 'install'));
00281     $prompt = get_string('clitypevaluedefault', 'admin', decoct($chmod));
00282     $error = '';
00283     do {
00284         echo $error;
00285         $input = cli_input($prompt, decoct($chmod));
00286         $input = octdec(clean_param($input, PARAM_INT));
00287         if (empty($input)) {
00288             $error = get_string('cliincorrectvalueretry', 'admin')."\n";
00289         } else {
00290             $error = '';
00291         }
00292     } while ($error !== '');
00293     $chmod = $input;
00294 
00295 } else {
00296     if (empty($chmod)) {
00297         $a = (object)array('option' => 'chmod', 'value' => decoct($chmod));
00298         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00299     }
00300 }
00301 $CFG->directorypermissions = $chmod;
00302 
00303 //We need wwwroot before we test dataroot
00304 $wwwroot = clean_param($options['wwwroot'], PARAM_URL);
00305 $wwwroot = trim($wwwroot, '/');
00306 if ($interactive) {
00307     cli_separator();
00308     cli_heading(get_string('wwwroot', 'install'));
00309     if (strpos($wwwroot, 'http') === 0) {
00310         $prompt = get_string('clitypevaluedefault', 'admin', $wwwroot);
00311     } else {
00312         $wwwroot = null;
00313         $prompt = get_string('clitypevalue', 'admin');
00314     }
00315     $error = '';
00316     do {
00317         echo $error;
00318         $input = cli_input($prompt, $wwwroot);
00319         $input = clean_param($input, PARAM_URL);
00320         $input = trim($input, '/');
00321         if (strpos($input, 'http') !== 0) {
00322             $error = get_string('cliincorrectvalueretry', 'admin')."\n";
00323         } else {
00324             $error = '';
00325         }
00326     } while ($error !== '');
00327     $wwwroot = $input;
00328 
00329 } else {
00330     if (strpos($wwwroot, 'http') !== 0) {
00331         $a = (object)array('option'=>'wwwroot', 'value'=>$wwwroot);
00332         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00333     }
00334 }
00335 $CFG->wwwroot       = $wwwroot;
00336 $CFG->httpswwwroot  = $CFG->wwwroot;
00337 
00338 
00339 //We need dataroot before lang download
00340 $CFG->dataroot = $options['dataroot'];
00341 if ($interactive) {
00342     cli_separator();
00343     $i=0;
00344     while(is_dataroot_insecure()) {
00345         $parrent = dirname($CFG->dataroot);
00346         $i++;
00347         if ($parrent == '/' or $parrent == '.' or preg_match('/^[a-z]:\\\?$/i', $parrent) or ($i > 100)) {
00348             $CFG->dataroot = ''; //can not find secure location for dataroot
00349             break;
00350         }
00351         $CFG->dataroot = dirname($parrent).'/moodledata';
00352     }
00353     cli_heading(get_string('dataroot', 'install'));
00354     $error = '';
00355     do {
00356         if ($CFG->dataroot !== '') {
00357             $prompt = get_string('clitypevaluedefault', 'admin', $CFG->dataroot);
00358         } else {
00359             $prompt = get_string('clitypevalue', 'admin');
00360         }
00361         echo $error;
00362         $CFG->dataroot = cli_input($prompt, $CFG->dataroot);
00363         if ($CFG->dataroot === '') {
00364             $error = get_string('cliincorrectvalueretry', 'admin')."\n";
00365         } else if (is_dataroot_insecure()) {
00366             $CFG->dataroot = '';
00367             $error = get_string('pathsunsecuredataroot', 'install')."\n";
00368         } else {
00369             if (install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
00370                 $error = '';
00371             } else {
00372                 $a = (object)array('dataroot' => $CFG->dataroot);
00373                 $error = get_string('pathserrcreatedataroot', 'install', $a)."\n";
00374             }
00375         }
00376 
00377     } while ($error !== '');
00378 
00379 } else {
00380     if (is_dataroot_insecure()) {
00381         cli_error(get_string('pathsunsecuredataroot', 'install'));
00382     }
00383     if (!install_init_dataroot($CFG->dataroot, $CFG->directorypermissions)) {
00384         $a = (object)array('dataroot' => $CFG->dataroot);
00385         cli_error(get_string('pathserrcreatedataroot', 'install', $a));
00386     }
00387 }
00388 $CFG->tempdir  = $CFG->dataroot.'/temp';
00389 $CFG->cachedir = $CFG->dataroot.'/cache';
00390 
00391 // download required lang packs
00392 if ($CFG->lang !== 'en') {
00393     $installer = new lang_installer($CFG->lang);
00394     $results = $installer->run();
00395     foreach ($results as $langcode => $langstatus) {
00396         if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
00397             $a       = new stdClass();
00398             $a->url  = $installer->lang_pack_url($langcode);
00399             $a->dest = $CFG->dataroot.'/lang';
00400             cli_problem(get_string('remotedownloaderror', 'error', $a));
00401         }
00402     }
00403 }
00404 
00405 // switch the string_manager instance to stop using install/lang/
00406 $CFG->early_install_lang = false;
00407 $CFG->langotherroot      = $CFG->dataroot.'/lang';
00408 $CFG->langlocalroot      = $CFG->dataroot.'/lang';
00409 get_string_manager(true);
00410 
00411 // make sure we are installing stable release or require a confirmation
00412 if (isset($maturity)) {
00413     if (($maturity < MATURITY_STABLE) and !$options['allow-unstable']) {
00414         $maturitylevel = get_string('maturity'.$maturity, 'admin');
00415 
00416         if ($interactive) {
00417             cli_separator();
00418             cli_heading(get_string('notice'));
00419             echo get_string('maturitycorewarning', 'admin', $maturitylevel) . PHP_EOL;
00420             echo get_string('morehelp') . ': ' . get_docs_url('admin/versions') . PHP_EOL;
00421             echo get_string('continue') . PHP_EOL;
00422             $prompt = get_string('cliyesnoprompt', 'admin');
00423             $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin')));
00424             if ($input == get_string('clianswerno', 'admin')) {
00425                 exit(1);
00426             }
00427         } else {
00428             cli_error(get_string('maturitycorewarning', 'admin'));
00429         }
00430     }
00431 }
00432 
00433 // ask for db type - show only drivers available
00434 if ($interactive) {
00435     $options['dbtype'] = strtolower($options['dbtype']);
00436     cli_separator();
00437     cli_heading(get_string('databasetypehead', 'install'));
00438     foreach ($databases as $type=>$database) {
00439         echo " $type \n";
00440     }
00441     if (!empty($databases[$options['dbtype']])) {
00442         $prompt = get_string('clitypevaluedefault', 'admin', $options['dbtype']);
00443     } else {
00444         $prompt = get_string('clitypevalue', 'admin');
00445     }
00446     $CFG->dbtype = cli_input($prompt, $options['dbtype'], array_keys($databases));
00447 
00448 } else {
00449     if (empty($databases[$options['dbtype']])) {
00450         $a = (object)array('option'=>'dbtype', 'value'=>$options['dbtype']);
00451         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00452     }
00453     $CFG->dbtype = $options['dbtype'];
00454 }
00455 $database = $databases[$CFG->dbtype];
00456 
00457 
00458 // ask for db host
00459 if ($interactive) {
00460     cli_separator();
00461     cli_heading(get_string('databasehost', 'install'));
00462     if ($options['dbhost'] !== '') {
00463         $prompt = get_string('clitypevaluedefault', 'admin', $options['dbhost']);
00464     } else {
00465         $prompt = get_string('clitypevalue', 'admin');
00466     }
00467     $CFG->dbhost = cli_input($prompt, $options['dbhost']);
00468 
00469 } else {
00470     $CFG->dbhost = $options['dbhost'];
00471 }
00472 
00473 // ask for db name
00474 if ($interactive) {
00475     cli_separator();
00476     cli_heading(get_string('databasename', 'install'));
00477     if ($options['dbname'] !== '') {
00478         $prompt = get_string('clitypevaluedefault', 'admin', $options['dbname']);
00479     } else {
00480         $prompt = get_string('clitypevalue', 'admin');
00481     }
00482     $CFG->dbname = cli_input($prompt, $options['dbname']);
00483 
00484 } else {
00485     $CFG->dbname = $options['dbname'];
00486 }
00487 
00488 // ask for db prefix
00489 if ($interactive) {
00490     cli_separator();
00491     cli_heading(get_string('dbprefix', 'install'));
00492     //TODO: solve somehow the prefix trouble for oci
00493     if ($options['prefix'] !== '') {
00494         $prompt = get_string('clitypevaluedefault', 'admin', $options['prefix']);
00495     } else {
00496         $prompt = get_string('clitypevalue', 'admin');
00497     }
00498     $CFG->prefix = cli_input($prompt, $options['prefix']);
00499 
00500 } else {
00501     $CFG->prefix = $options['prefix'];
00502 }
00503 
00504 // ask for db user
00505 if ($interactive) {
00506     cli_separator();
00507     cli_heading(get_string('databaseuser', 'install'));
00508     if ($options['dbuser'] !== '') {
00509         $prompt = get_string('clitypevaluedefault', 'admin', $options['dbuser']);
00510     } else {
00511         $prompt = get_string('clitypevalue', 'admin');
00512     }
00513     $CFG->dbuser = cli_input($prompt, $options['dbuser']);
00514 
00515 } else {
00516     $CFG->dbuser = $options['dbuser'];
00517 }
00518 
00519 // ask for db password
00520 if ($interactive) {
00521     cli_separator();
00522     cli_heading(get_string('databasepass', 'install'));
00523     do {
00524         if ($options['dbpass'] !== '') {
00525             $prompt = get_string('clitypevaluedefault', 'admin', $options['dbpass']);
00526         } else {
00527             $prompt = get_string('clitypevalue', 'admin');
00528         }
00529 
00530         $CFG->dbpass = cli_input($prompt, $options['dbpass']);
00531         if (function_exists('distro_pre_create_db')) { // Hook for distros needing to do something before DB creation
00532             $distro = distro_pre_create_db($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbsocket'=>$options['dbsocket']), $distro);
00533         }
00534         $hint_database = install_db_validate($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbsocket'=>$options['dbsocket']));
00535     } while ($hint_database !== '');
00536 
00537 } else {
00538     $CFG->dbpass = $options['dbpass'];
00539     $hint_database = install_db_validate($database, $CFG->dbhost, $CFG->dbuser, $CFG->dbpass, $CFG->dbname, $CFG->prefix, array('dbpersist'=>0, 'dbsocket'=>$options['dbsocket']));
00540     if ($hint_database !== '') {
00541         cli_error(get_string('dbconnectionerror', 'install'));
00542     }
00543 }
00544 
00545 // ask for fullname
00546 if ($interactive) {
00547     cli_separator();
00548     cli_heading(get_string('fullsitename', 'moodle'));
00549 
00550     if ($options['fullname'] !== '') {
00551         $prompt = get_string('clitypevaluedefault', 'admin', $options['fullname']);
00552     } else {
00553         $prompt = get_string('clitypevalue', 'admin');
00554     }
00555 
00556     do {
00557         $options['fullname'] = cli_input($prompt, $options['fullname']);
00558     } while (empty($options['fullname']));
00559 } else {
00560     if (empty($options['fullname'])) {
00561         $a = (object)array('option'=>'fullname', 'value'=>$options['fullname']);
00562         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00563     }
00564 }
00565 
00566 // ask for shortname
00567 if ($interactive) {
00568     cli_separator();
00569     cli_heading(get_string('shortsitename', 'moodle'));
00570 
00571     if ($options['shortname'] !== '') {
00572         $prompt = get_string('clitypevaluedefault', 'admin', $options['shortname']);
00573     } else {
00574         $prompt = get_string('clitypevalue', 'admin');
00575     }
00576 
00577     do {
00578         $options['shortname'] = cli_input($prompt, $options['shortname']);
00579     } while (empty($options['shortname']));
00580 } else {
00581     if (empty($options['shortname'])) {
00582         $a = (object)array('option'=>'shortname', 'value'=>$options['shortname']);
00583         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00584     }
00585 }
00586 
00587 // ask for admin user name
00588 if ($interactive) {
00589     cli_separator();
00590     cli_heading(get_string('cliadminusername', 'install'));
00591     if (!empty($options['adminuser'])) {
00592         $prompt = get_string('clitypevaluedefault', 'admin', $options['adminuser']);
00593     } else {
00594         $prompt = get_string('clitypevalue', 'admin');
00595     }
00596     do {
00597         $options['adminuser'] = cli_input($prompt, $options['adminuser']);
00598     } while (empty($options['adminuser']) or $options['adminuser'] === 'guest');
00599 } else {
00600     if (empty($options['adminuser']) or $options['adminuser'] === 'guest') {
00601         $a = (object)array('option'=>'adminuser', 'value'=>$options['adminuser']);
00602         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00603     }
00604 }
00605 
00606 // ask for admin user password
00607 if ($interactive) {
00608     cli_separator();
00609     cli_heading(get_string('cliadminpassword', 'install'));
00610     $prompt = get_string('clitypevalue', 'admin');
00611     do {
00612         $options['adminpass'] = cli_input($prompt);
00613     } while (empty($options['adminpass']) or $options['adminpass'] === 'admin');
00614 } else {
00615     if (empty($options['adminpass']) or $options['adminpass'] === 'admin') {
00616         $a = (object)array('option'=>'adminpass', 'value'=>$options['adminpass']);
00617         cli_error(get_string('cliincorrectvalueerror', 'admin', $a));
00618     }
00619 }
00620 
00621 if ($interactive) {
00622     if (!$options['agree-license']) {
00623         cli_separator();
00624         cli_heading(get_string('copyrightnotice'));
00625         echo "Moodle  - Modular Object-Oriented Dynamic Learning Environment\n";
00626         echo get_string('gpl3')."\n\n";
00627         echo get_string('doyouagree')."\n";
00628         $prompt = get_string('cliyesnoprompt', 'admin');
00629         $input = cli_input($prompt, '', array(get_string('clianswerno', 'admin'), get_string('cliansweryes', 'admin')));
00630         if ($input == get_string('clianswerno', 'admin')) {
00631             exit(1);
00632         }
00633     }
00634 } else {
00635     if (!$options['agree-license']) {
00636         cli_error(get_string('climustagreelicense', 'install'));
00637     }
00638 }
00639 
00640 // Finally we have all info needed for config.php
00641 $configphp = install_generate_configphp($database, $CFG);
00642 umask(0137);
00643 if (($fh = fopen($configfile, 'w')) !== false) {
00644     fwrite($fh, $configphp);
00645     fclose($fh);
00646 }
00647 
00648 if (!file_exists($configfile)) {
00649     cli_error('Can not create config file.');
00650 }
00651 
00652 // remember selected language
00653 $installlang = $CFG->lang;
00654 // return back to original dir before executing setup.php which changes the dir again
00655 chdir($olddir);
00656 // We have config.php, it is a real php script from now on :-)
00657 require($configfile);
00658 
00659 // use selected language
00660 $CFG->lang = $installlang;
00661 $SESSION->lang = $CFG->lang;
00662 
00663 require("$CFG->dirroot/version.php");
00664 
00665 // Test environment first.
00666 require_once($CFG->libdir . '/environmentlib.php');
00667 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
00668 if (!$envstatus) {
00669     $errors = environment_get_errors($environment_results);
00670     cli_heading(get_string('environment', 'admin'));
00671     foreach ($errors as $error) {
00672         list($info, $report) = $error;
00673         echo "!! $info !!\n$report\n\n";
00674     }
00675     exit(1);
00676 }
00677 
00678 // Test plugin dependencies.
00679 require_once($CFG->libdir . '/pluginlib.php');
00680 if (!plugin_manager::instance()->all_plugins_ok($version)) {
00681     cli_error(get_string('pluginschecktodo', 'admin'));
00682 }
00683 
00684 install_cli_database($options, $interactive);
00685 
00686 echo get_string('cliinstallfinished', 'install')."\n";
00687 exit(0); // 0 means success
 All Data Structures Namespaces Files Functions Variables Enumerations