MDL-32572 fix notice when changing internal auth_db passwords
[moodle.git] / admin / cli / install_database.php
blob2524c4101eb3fbe814c34e2352d7863bf236a1a8
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
5 // Moodle is free software: you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation, either version 3 of the License, or
8 // (at your option) any later version.
9 //
10 // Moodle is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with Moodle. If not, see <http://www.gnu.org/licenses/>.
18 /**
19 * This installs Moodle into empty database, config.php must already exist.
21 * This script is intended for advanced usage such as in Debian packages.
22 * - sudo to www-data (apache account) before
23 * - not compatible with Windows platform
25 * @package core
26 * @subpackage cli
27 * @copyright 2010 Petr Skoda (http://skodak.org)
28 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
31 define('CLI_SCRIPT', true);
33 // extra execution prevention - we can not just require config.php here
34 if (isset($_SERVER['REMOTE_ADDR'])) {
35 exit(1);
38 $help =
39 "Advanced command line Moodle database installer.
40 Please note you must execute this script with the same uid as apache.
42 Site defaults may be changed via local/defaults.php.
44 Options:
45 --lang=CODE Installation and default site language. Default is en.
46 --adminuser=USERNAME Username for the moodle admin account. Default is admin.
47 --adminpass=PASSWORD Password for the moodle admin account.
48 --agree-license Indicates agreement with software license.
49 --fullname=STRING Name of the site
50 --shortname=STRING Name of the site
51 -h, --help Print out this help
53 Example:
54 \$sudo -u www-data /usr/bin/php admin/cli/install_database.php --lang=cs --adminpass=soMePass123 --agree-license
57 // Check that PHP is of a sufficient version
58 if (version_compare(phpversion(), "5.3.2") < 0) {
59 $phpversion = phpversion();
60 // do NOT localise - lang strings would not work here and we CAN NOT move it after installib
61 fwrite(STDERR, "Moodle 2.1 or later requires at least PHP 5.3.2 (currently using version $phpversion).\n");
62 fwrite(STDERR, "Please upgrade your server software or install older Moodle version.\n");
63 exit(1);
66 // Nothing to do if config.php does not exist
67 $configfile = dirname(dirname(dirname(__FILE__))).'/config.php';
68 if (!file_exists($configfile)) {
69 fwrite(STDERR, 'config.php does not exist, can not continue'); // do not localize
70 fwrite(STDERR, "\n");
71 exit(1);
74 // Include necessary libs
75 require($configfile);
77 require_once($CFG->libdir.'/clilib.php');
78 require_once($CFG->libdir.'/installlib.php');
79 require_once($CFG->libdir.'/adminlib.php');
80 require_once($CFG->libdir.'/componentlib.class.php');
82 // make sure no tables are installed yet
83 if ($DB->get_tables() ) {
84 cli_error(get_string('clitablesexist', 'install'));
87 $CFG->early_install_lang = true;
88 get_string_manager(true);
90 raise_memory_limit(MEMORY_EXTRA);
92 // now get cli options
93 list($options, $unrecognized) = cli_get_params(
94 array(
95 'lang' => 'en',
96 'adminuser' => 'admin',
97 'adminpass' => '',
98 'fullname' => '',
99 'shortname' => '',
100 'agree-license' => false,
101 'help' => false
103 array(
104 'h' => 'help'
109 if ($options['help']) {
110 echo $help;
111 die;
114 if (!$options['agree-license']) {
115 cli_error('You have to agree to the license. --help prints out the help'); // TODO: localize
118 if ($options['adminpass'] === true or $options['adminpass'] === '') {
119 cli_error('You have to specify admin password. --help prints out the help'); // TODO: localize
122 $options['lang'] = clean_param($options['lang'], PARAM_SAFEDIR);
123 if (!file_exists($CFG->dirroot.'/install/lang/'.$options['lang'])) {
124 $options['lang'] = 'en';
126 $CFG->lang = $options['lang'];
128 // download required lang packs
129 if ($CFG->lang !== 'en') {
130 make_upload_directory('lang');
131 $installer = new lang_installer($CFG->lang);
132 $results = $installer->run();
133 foreach ($results as $langcode => $langstatus) {
134 if ($langstatus === lang_installer::RESULT_DOWNLOADERROR) {
135 $a = new stdClass();
136 $a->url = $installer->lang_pack_url($langcode);
137 $a->dest = $CFG->dataroot.'/lang';
138 cli_problem(get_string('remotedownloaderror', 'error', $a));
143 // switch the string_manager instance to stop using install/lang/
144 $CFG->early_install_lang = false;
145 get_string_manager(true);
147 require("$CFG->dirroot/version.php");
149 // Test environment first.
150 require_once($CFG->libdir . '/environmentlib.php');
151 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
152 if (!$envstatus) {
153 $errors = environment_get_errors($environment_results);
154 cli_heading(get_string('environment', 'admin'));
155 foreach ($errors as $error) {
156 list($info, $report) = $error;
157 echo "!! $info !!\n$report\n\n";
159 exit(1);
162 // Test plugin dependencies.
163 require_once($CFG->libdir . '/pluginlib.php');
164 if (!plugin_manager::instance()->all_plugins_ok($version)) {
165 cli_error(get_string('pluginschecktodo', 'admin'));
168 install_cli_database($options, true);
170 echo get_string('cliinstallfinished', 'install')."\n";
171 exit(0); // 0 means success