install.hostmaster.inc 7.98 KB
Newer Older
1 2 3
<?php

/**
4
 * @file install the hostmaster system
5 6
 */

7
function drush_provision_hostmaster_install_validate($site = NULL) {
8 9
  // set defaults for this whole script
  // those are settings that are not prompted to the user but still overridable
10 11
  drush_set_default('version', provision_version());
  $version = drush_get_option('version');
12 13 14 15 16 17
  $aegir_root = drush_set_default('aegir_root', drush_server_home());
  drush_set_default('root', $aegir_root . '/' . 'hostmaster-' . $version);
  drush_set_default('r', drush_get_option('root'));
  drush_set_default('script_user', provision_current_user());
  drush_set_default('web_group', _provision_default_web_group());
  drush_set_default('http_service_type', 'apache');
omega8cc's avatar
omega8cc committed
18
  drush_set_default('drush_make_version', '6.x-2.3');
anarcat's avatar
anarcat committed
19
  drush_set_default('aegir_db_user', 'root');
20
  drush_set_default('client_name', 'admin');
anarcat's avatar
anarcat committed
21
  $aegir_db_user = drush_get_option('aegir_db_user');
22
  drush_set_default('makefile', dirname(__FILE__) . '/aegir.make');
23

24
  drush_print("Aegir $version automated install script");
25
  drush_print("==============================================================================");
26

27
  if (!$site || !drush_get_option('aegir_host', NULL) || !drush_get_option('aegir_db_pass', NULL) || filter_var(drush_get_option('client_email'), FILTER_VALIDATE_EMAIL)) {
28
    drush_print("Some settings have not been provided and will now be prompted.
29 30 31 32
Don't worry: you will get to review those settings after the final install");
  }
  // now we prompt the user for settings if not provided or not sane
  if (!$site) {
33
    $site = drush_prompt(dt("Aegir frontend URL"), provision_fqdn());
34
  }
35
  drush_set_option('site', $site);
36

37
  drush_set_default('aegir_host', provision_fqdn());
38
  drush_set_default('aegir_db_host', 'localhost');
39 40 41 42 43 44 45 46 47

  if (is_null(drush_get_option('aegir_db_pass', NULL))) {
    // XXX: may not be portable everywhere?
    system('stty -echo');
    drush_set_option('aegir_db_pass', drush_prompt(dt('MySQL privileged user ("!root") password', array('!root' => $aegir_db_user))));
    system('stty echo');
    print "\n"; // add a newline since the user's didn't print    
  }

48
  if (drush_get_option('aegir_host') == 'localhost') {
49 50
    $default_email = 'webmaster@example.com';
  } else {
51
    $default_email = 'webmaster@' . drush_get_option('aegir_host');
52
  }
53
  while (!filter_var(drush_get_option('client_email'), FILTER_VALIDATE_EMAIL)) {
54
   $client_email = drush_prompt(dt("Admin user e-mail"), $default_email);
55 56 57
   drush_set_option('client_email', $client_email);
  }

58
  drush_print(dt('
59 60 61 62 63 64 65 66 67
This script will operate the following changes in your system:

1. Create server-level configuration directories
2. Download drush_make
3. Create the Hostmaster frontend platform
4. Install the frontend site
5. Setup the dispatcher (a user cron job)

We are making the following assumptions:
68 69
 * you have read and are following the install instructions at:
    http://community.aegirproject.org/installing
70
 * the FQDN of this machine is valid and resolves
71
 * you are executing this script as your "aegir" user
72

73 74
The following settings will be used:
 Aegir frontend URL: !site
anarcat's avatar
anarcat committed
75
 Master server FQDN: !fqdn
76 77 78 79
 Aegir root: !home
 Aegir user: !user
 Web group: !web
 Web server: !web_server
80
 Aegir DB host: !db_host
81 82 83 84 85
 Aegir DB user: !db_user
 Aegir DB password: !db_pass
 Drush make version: !drush_make
 Aegir version: !version
 Aegir platform path: !root
anarcat's avatar
anarcat committed
86
 Aegir makefile: !makefile
87
 Admin email: !email
88
', array('!site' => $site,
89 90 91 92 93
         '!fqdn' => drush_get_option('aegir_host'),
         '!home' => drush_get_option('aegir_root'),
         '!user' => drush_get_option('script_user'),
         '!web' => drush_get_option('web_group'),
         '!web_server' => drush_get_option('http_service_type'),
94
         '!db_host' => drush_get_option('aegir_db_host'),
95
         '!db_user' => drush_get_option('aegir_db_user'),
anarcat's avatar
anarcat committed
96
         '!db_pass' => is_null(drush_get_option('aegir_db_pass', NULL, 'process')) ? '<previously set>' : '<prompted>',
97 98 99
         '!drush_make' => drush_get_option('drush_make_version'),
         '!version' => drush_get_option('version'),
         '!root' => drush_get_option(array('r', 'root')),
anarcat's avatar
anarcat committed
100
         '!makefile' => drush_get_option('makefile'),
101
         '!email' => drush_get_option('client_email'),
102
         )));
103

104 105
  if (!drush_confirm(dt('Do you really want to proceed with the install'))) {
    return drush_set_error('PROVISION_CANCEL_INSTALL', dt('Installation aborted by user'));
106
  }
107

108 109 110
  return TRUE;
}

111 112 113
/**
 * Drush command to install hostmaster.
 */
114
function drush_provision_hostmaster_install($site = NULL) {
115
  $version = drush_get_option('version');
116
  $site = drush_get_option('site', provision_fqdn());
117 118
  $aegir_root = drush_get_option('aegir_root');
  $platform = drush_get_option(array('r', 'root'));
119

120 121
  $aegir_db_user = drush_get_option('aegir_db_user');
  $aegir_db_pass = drush_get_option('aegir_db_pass');
122
  
123
  $server = '@server_master';
124
  $master_context = array(
125
    'context_type' => 'server',
126
    // files
anarcat's avatar
anarcat committed
127
    'remote_host' => drush_get_option('aegir_host'),
128
    'aegir_root' => $aegir_root,
129
    'script_user' => drush_get_option('script_user'),
130
   // apache or nginx or..
131 132
    'http_service_type' => drush_get_option('http_service_type'),
    'web_group' => drush_get_option('web_group'),
133
    'master_url' => "http://" . $site,
134 135
  );

136
  $master_db = sprintf("mysql://%s:%s@%s", urlencode($aegir_db_user), urlencode($aegir_db_pass), drush_get_option('aegir_db_host'));
137 138 139 140 141 142 143
  if (drush_get_option('aegir_host') == drush_get_option('aegir_db_host')) {
    $master_context['db_service_type'] = 'mysql';
    $master_context['master_db'] = $master_db;
    $dbserver = $server;
  } else {
    $dbserver = '@server_' . drush_get_option('aegir_db_host');
    $dbserver_context = array(
144
      'remote_host' => drush_get_option('aegir_db_host'),
145 146 147 148 149 150 151 152
      'context_type' => 'server',
      'db_service_type' => 'mysql',
      'master_db' => $master_db,
    );
    drush_backend_invoke_args("provision-save", array($dbserver), $dbserver_context);
    provision_backend_invoke($dbserver, 'provision-verify');
  }
  drush_backend_invoke_args("provision-save", array($server), $master_context);
153
  provision_backend_invoke($server, 'provision-verify');
154

155 156 157 158 159
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }

160 161 162 163
  if (drush_get_option('backend-only')) {
    return;
  }

164
  if (!function_exists('drush_make_drush_command')) {
165
    drush_backend_invoke('dl', array('drush_make-' . drush_get_option('drush_make_version'), 'destination' => $aegir_root . '/.drush/'));
166 167
  }

168 169 170 171 172
  $platform_name = '@platform_hostmaster';
  drush_backend_invoke_args("provision-save", array($platform_name), array(
    'context_type' => 'platform',
    'server' => $server,
    'web_server' => $server,
173
    'root' => $platform,
anarcat's avatar
anarcat committed
174
    'makefile' => drush_get_option('makefile'),
175
  ));
176 177 178 179 180 181
  // propagate working-copy args downward
  $options = array();
  if (drush_get_option('working-copy')) {
    $options['working-copy'] = 1;
  }
  provision_backend_invoke($platform_name, 'provision-verify', array(), $options);
182

183 184 185 186 187
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }

188 189 190 191
  $site_name = '@hostmaster';
  drush_backend_invoke_args("provision-save", array($site_name), array(
    'context_type' => 'site',
    'platform' => $platform_name,
192
    'db_server' => $dbserver,
193
    'uri' => $site,
194
    'client_name' => drush_get_option('client_name'),
195 196
    'profile' => 'hostmaster',
  ));
197
  $data = provision_backend_invoke($site_name, 'provision-install', array(), array('client_email' => drush_get_option('client_email')));
198
  provision_backend_invoke($site_name, 'provision-verify');
199

200 201 202 203 204 205
  // exit if an error has occured. 
  if (drush_get_error()) {
    return false;
  }


mig5's avatar
mig5 committed
206
  drush_print(dt("Initializing the hosting system"));
207
  provision_backend_invoke($site_name, 'hosting-setup');
208

209
  drush_print("************************************************************************\n\n\n");
210
  drush_print(dt("Aegir is now installed. You can visit it at @link", array('@link' => $data['context']['login_link'])));
211
  drush_print("************************************************************************");
212 213
}