/usr/share/drush/commands/core/site_install.drush.inc is in drush 4.5-6.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 | <?php
/**
* Command validate.
*/
function drush_core_site_install_validate() {
if ($sites_subdir = drush_get_option('sites-subdir')) {
$lower = strtolower($sites_subdir);
if ($sites_subdir != $lower) {
drush_log(dt('Only lowercase sites-subdir are valid. Switching to !lower.', array('!lower' => $lower)), 'warning');
drush_set_option('sites-subdir', $lower);
}
}
}
/**
* Perform setup tasks for installation.
*/
function drush_core_pre_site_install() {
if (!$db_spec = drush_sql_read_db_spec()) {
drush_set_error(dt('Could not determine database connection parameters. Pass --db-url option.'));
return;
}
if ($sites_subdir = drush_get_option('sites-subdir')) {
// Needed so that we later bootstrap into the right site.
drush_set_option('uri', 'http://'.$sites_subdir);
}
else {
$sites_subdir = 'default';
}
$conf_path = "sites/$sites_subdir";
$files = "$conf_path/files";
$settingsfile = "$conf_path/settings.php";
if (!file_exists($files)) {
$msg[] = dt('create a @files directory', array('@files' => $files));
}
if (!file_exists($settingsfile)) {
$msg[] = dt('create a @settingsfile file', array('@settingsfile' => $settingsfile));
}
$msg[] = dt("DROP your '@db' database and then CREATE a new one.", array('@db' => $db_spec['database']));
if (!drush_confirm(dt('You are about to ') . implode(dt(' and '), $msg) . ' Do you want to continue?')) {
return drush_user_abort();
}
// Can't install without sites directory and settings.php.
if (!file_exists($conf_path)) {
if (!drush_op('mkdir', $conf_path) && !drush_get_context('DRUSH_SIMULATE')) {
drush_set_error(dt('Failed to create directory @conf_path', array('@conf_path' => $conf_path)));
return;
}
}
else {
drush_log(dt('Sites directory @subdir already exists - proceeding.', array('@subdir' => $conf_path)));
}
if (!file_exists($settingsfile)) {
if (!drush_op('copy', 'sites/default/default.settings.php', $settingsfile) && !drush_get_context('DRUSH_SIMULATE')) {
drush_set_error(dt('Failed to copy sites/default/default.settings.php to @settingsfile', array('@settingsfile' => $settingsfile)));
return;
}
elseif (drush_drupal_major_version() == 6) {
// On D6, we have to write $db_url ourselves. In D7+, the installer does it.
file_put_contents($settingsfile, "\n" . '$db_url = \'' . drush_get_option('db-url') . "';\n", FILE_APPEND);
// Instead of parsing and performing string replacement on the configuration file,
// the options are appended and override the defaults.
// Database table prefix
if (!empty($db_spec['db_prefix'])) {
if (is_array($db_spec['db_prefix'])) {
// Write db_prefix configuration as an array
$db_prefix_config = '$db_prefix = ' . var_export($db_spec['db_prefix'], TRUE) . ';';
}
else {
// Write db_prefix configuration as a string
$db_prefix_config = '$db_prefix = \'' . $db_spec['db_prefix'] . '\';';
}
file_put_contents($settingsfile, "\n" . $db_prefix_config . "\n", FILE_APPEND);
}
}
}
// Add a files dir if needed
if (!file_exists($files)) {
if (!drush_op('mkdir', $files) && !drush_get_context('DRUSH_SIMULATE')) {
drush_set_error(dt('Failed to create directory @name', array('@name' => $files)));
return;
}
}
// Now we can bootstrap up to the specified site.
drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION);
// Drop and create DB if needed.
$db_name = $db_spec['database'];
$scheme = _drush_sql_get_scheme($db_spec);
$simulate = drush_get_context('DRUSH_SIMULATE');
if ($scheme === 'sqlite') {
// With SQLite, we don't DROP DATABASEs. Each database is in a single file,
// so we just remove the file. We also don't CREATE DATABASEs; it is created
// when SQLite attempts to open a database file which doesn't exist.
if (file_exists($db_spec['database']) && !$simulate) {
if (!unlink($db_spec['database'])) {
drush_set_error(dt('Could not drop database: @name', array('@name' => $db_name)));
}
}
}
else {
drush_sql_empty_db($db_spec);
}
return TRUE;
}
/**
* Command callback.
*/
function drush_core_site_install($profile = NULL) {
$args = func_get_args();
$form_options = array();
if ($args) {
// The first argument is the profile.
$profile = array_shift($args);
// Subsequent arguments are additional form values.
foreach ($args as $arg) {
list($key, $value) = explode('=', $arg);
$form_options[$key] = $value;
}
}
drush_include_engine('drupal', 'site_install', drush_drupal_major_version());
drush_core_site_install_version($profile, $form_options);
}
|