View source
<?php
function hostmaster_install() {
variable_set('install_profile', 'hostmaster');
if (d()->platform->server->http_service_type === 'nginx') {
module_enable(array(
'hosting_nginx',
));
}
hostmaster_bootstrap();
hostmaster_task_finalize();
}
function hostmaster_bootstrap() {
$types = node_types_rebuild();
hosting_init();
$node = new stdClass();
$node->uid = 1;
$node->type = 'client';
$node->title = drush_get_option('client_name', 'admin');
$node->status = 1;
node_save($node);
variable_set('hosting_default_client', $node->nid);
variable_set('hosting_admin_client', $node->nid);
$client_id = $node->nid;
$node = new stdClass();
$node->uid = 1;
$node->type = 'server';
$node->title = php_uname('n');
$node->status = 1;
$node->hosting_name = 'server_master';
$node->services = array();
$master_server = d()->platform->server;
hosting_services_add($node, 'http', $master_server->http_service_type, array(
'restart_cmd' => $master_server->http_restart_cmd,
'port' => $master_server->http_port,
'available' => 1,
));
$db_server = d()->db_server;
$master_db = parse_url($db_server->master_db);
if ($db_server->remote_host == $master_server->remote_host) {
$db_node = $node;
}
else {
$db_node = new stdClass();
$db_node->uid = 1;
$db_node->type = 'server';
$db_node->title = $master_db['host'];
$db_node->status = 1;
$db_node->hosting_name = 'server_' . $db_server->remote_host;
$db_node->services = array();
}
hosting_services_add($db_node, 'db', $db_server->db_service_type, array(
'db_type' => $master_db['scheme'],
'db_user' => urldecode($master_db['user']),
'db_passwd' => isset($master_db['pass']) ? urldecode($master_db['pass']) : '',
'port' => $db_server->db_port,
'available' => 1,
));
drupal_set_message(st('Creating master server node'));
node_save($node);
if ($db_server->remote_host != $master_server->remote_host) {
drupal_set_message(st('Creating db server node'));
node_save($db_node);
}
variable_set('hosting_default_web_server', $node->nid);
variable_set('hosting_own_web_server', $node->nid);
variable_set('hosting_default_db_server', $db_node->nid);
variable_set('hosting_own_db_server', $db_node->nid);
$node = new stdClass();
$node->uid = 1;
$node->title = 'Drupal';
$node->type = 'package';
$node->package_type = 'platform';
$node->short_name = 'drupal';
$node->old_short_name = 'drupal';
$node->description = 'Drupal code-base.';
$node->status = 1;
node_save($node);
$package_id = $node->nid;
$node = new stdClass();
$node->uid = 1;
$node->type = 'platform';
$node->title = 'hostmaster';
$node->publish_path = d()->root;
$node->makefile = '';
$node->verified = 1;
$node->web_server = variable_get('hosting_default_web_server', 2);
$node->platform_status = 1;
$node->status = 1;
$node->make_working_copy = 0;
node_save($node);
$platform_id = $node->nid;
variable_set('hosting_own_platform', $node->nid);
$instance = new stdClass();
$instance->rid = $node->nid;
$instance->version = VERSION;
$instance->filename = '';
$instance->version_code = 1;
$instance->schema_version = 0;
$instance->package_id = $package_id;
$instance->status = 0;
$instance->platform = $platform_id;
hosting_package_instance_save($instance);
$node = new stdClass();
$node->uid = 1;
$node->title = 'hostmaster';
$node->type = 'package';
$node->old_short_name = 'hostmaster';
$node->description = 'The Hostmaster profile.';
$node->package_type = 'profile';
$node->short_name = 'hostmaster';
$node->status = 1;
node_save($node);
$profile_id = $node->nid;
$instance = new stdClass();
$instance->rid = $node->nid;
$instance->version = VERSION;
$instance->filename = '';
$instance->version_code = 1;
$instance->schema_version = 0;
$instance->package_id = $profile_id;
$instance->status = 0;
$instance->platform = $platform_id;
hosting_package_instance_save($instance);
$node = new stdClass();
$node->uid = 1;
$node->type = 'site';
$node->title = d()->uri;
$node->platform = $platform_id;
$node->client = $client_id;
$node->db_name = '';
$node->db_server = $db_node->nid;
$node->profile = $profile_id;
$node->import = true;
$node->hosting_name = 'hostmaster';
$node->site_status = 1;
$node->verified = 1;
$node->status = 1;
node_save($node);
variable_set('aegir_hostmaster_site_nid', $node->nid);
$default_hosting_features = array(
'hosting_web_server' => 'web_server',
'hosting_db_server' => 'db_server',
'hosting_platform' => 'platform',
'hosting_client' => 'client',
'hosting_task' => 'task',
'hosting_server' => 'server',
'hosting_package' => 'package',
'hosting_site' => 'site',
'hosting' => 'hosting',
);
hosting_features_enable($default_hosting_features, $rebuild = TRUE, $enable = FALSE);
variable_set('site_frontpage', 'hosting/sites');
variable_set('user_register', 0);
variable_set('install_url', $GLOBALS['base_url']);
}
function hostmaster_task_finalize() {
variable_set('install_profile', 'hostmaster');
theme_enable(array(
'eldir',
));
variable_set('theme_default', 'eldir');
theme_disable(array(
'bartik',
));
drupal_set_message(st('Configuring default blocks'));
hostmaster_place_blocks('eldir');
variable_set('menu_options_client', array());
variable_set('menu_options_platform', array());
variable_set('menu_options_server', array());
variable_set('menu_options_site', array());
node_access_rebuild();
}
function hostmaster_place_blocks($theme) {
$blocks = array(
array(
'module' => 'hosting',
'delta' => 'hosting_queues',
'theme' => $theme,
'status' => 1,
'weight' => -2,
'region' => 'sidebar_first',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
array(
'module' => 'system',
'delta' => 'navigation',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'sidebar_first',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_task_list-block',
'theme' => $theme,
'status' => 1,
'weight' => -2,
'region' => 'sidebar_first',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_site_list-block_sites',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'content_bottom',
'visibility' => 1,
'pages' => 'hosting/c/platform_*',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_platform_list-block_1',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'content_bottom',
'visibility' => 1,
'pages' => 'hosting/c/server_*',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_site_list-block_profile',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'content_bottom',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_site_list-block_client',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'content_bottom',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_site_list-block_client2',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'content_bottom',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
array(
'module' => 'views',
'delta' => 'hosting_package_list-block_1',
'theme' => $theme,
'status' => 1,
'weight' => 0,
'region' => 'content_bottom',
'visibility' => 0,
'pages' => '',
'cache' => -1,
),
);
$query = db_insert('block')
->fields(array(
'module',
'delta',
'theme',
'status',
'weight',
'region',
'visibility',
'pages',
'cache',
));
foreach ($blocks as $block) {
$query
->values($block);
}
$query
->execute();
}