-
Notifications
You must be signed in to change notification settings - Fork 0
/
devshop.profile
265 lines (225 loc) · 8.45 KB
/
devshop.profile
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
<?php
/**
* @file devshop.profile
*
* DevShop Installation Profile
*/
/**
* Return an array of the modules to be enabled when this profile is installed.
*
* @return
* An array of modules to be enabled.
*/
function devshop_profile_modules() {
return array(
/* core */ 'block', 'color', 'filter', 'help', 'menu', 'node', 'system', 'user', 'update',
/* aegir contrib */ 'hosting', 'hosting_task', 'hosting_client', 'hosting_db_server', 'hosting_package', 'hosting_platform', 'hosting_site', 'hosting_web_server', 'hosting_server', 'hosting_clone', 'hosting_cron', 'hosting_migrate',
/* other contrib */ 'install_profile_api' /* needs >= 2.1 */, 'jquery_ui', 'modalframe', 'admin_menu',
/* DEVSHOP DEPENDENCIES */
'ctools',
/* DEVSHOP */
'devshop_hosting', 'devshop_projects', 'devshop_log', 'devshop_pull', 'devshop_live',
/* NICEITIES */
'hosting_drush_aliases', 'hosting_filemanager', 'hosting_logs', 'hosting_queue_runner', 'hosting_solr',
);
}
/**
* Return a description of the profile for the initial installation screen.
*
* @return
* An array with keys 'name' and 'description' describing this profile.
*/
function devshop_profile_details() {
return array(
'name' => 'DevShop',
'description' => 'The DevShop front-end.'
);
}
/**
* Implements hook_profile_tasks
*/
function devshop_profile_tasks(&$task, $url) {
// Install dependencies
install_include(devshop_profile_modules());
// add support for nginx
if (d()->platform->server->http_service_type === 'nginx') {
drupal_install_modules(array('hosting_nginx'));
}
// Bootstrap and create all the initial nodes
devshop_bootstrap();
// Finalize and setup themes, menus, optional modules etc
devshop_task_finalize();
}
function devshop_bootstrap() {
/* Default node types and default node */
$types = node_types_rebuild();
variable_set('install_profile', 'devshop');
// Initialize the hosting defines
hosting_init();
/* Default client */
$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;
/* Default server */
$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();
/* Make it compatible with more than apache and nginx */
$master_server = d()->platform->server;
hosting_services_add($node, 'http', $master_server->http_service_type, array(
'restart_cmd' => $master_server->http_restart_cmd,
'port' => 80,
'available' => 1,
));
/* examine the db server associated with the hostmaster site */
$db_server = d()->db_server;
$master_db = parse_url($db_server->master_db);
/* if it's not the same server as the master server, create a new node
* for it */
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' => urldecode($master_db['pass']),
'port' => 3306,
'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->status = 1;
node_save($node);
$package_id = $node->nid;
// @TODO: We need to still call these nodes "hostmaster" because the aliases are still @hostmaster and @platform_hostmaster
$node = new stdClass();
$node->uid = 1;
$node->type = 'platform';
$node->title = 'hostmaster';
$node->publish_path = d()->root;
$node->web_server = variable_get('hosting_default_web_server', 2);
$node->status = 1;
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->schema_version = drupal_get_installed_schema_version('system');
$instance->package_id = $package_id;
$instance->status = 0;
hosting_package_instance_save($instance);
// Create the hostmaster profile node
$node = new stdClass();
$node->uid = 1;
$node->title = 'devshop';
$node->type = 'package';
$node->package_type = 'profile';
$node->short_name = 'devshop';
$node->status = 1;
node_save($node);
$profile_id = $node->nid;
// Create the main Aegir site node
$node = new stdClass();
$node->uid = 1;
$node->type = 'site';
$node->title = d()->uri;
$node->platform = $platform_id;
$node->client = $client_id;
$node->db_server = $db_node->nid;
$node->profile = $profile_id;
$node->import = true;
$node->hosting_name = 'hostmaster';
$node->status = 1;
node_save($node);
// Set the frontpage
variable_set('site_frontpage', 'devshop');
// Set the sitename
variable_set('site_name', 'DevShop');
// do not allow user registration: the signup form will do that
variable_set('user_register', 0);
// This is saved because the config generation script is running via drush, and does not have access to this value
variable_set('install_url' , $GLOBALS['base_url']);
}
function devshop_task_finalize() {
drupal_set_message(st('Configuring menu items'));
install_include(array('menu'));
$menu_name = variable_get('menu_primary_links_source', 'primary-links');
// @TODO - seriously need to simplify this, but in our own code i think, not install profile api
$items = install_menu_get_items('hosting/projects');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['weight'] = 3;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
$items = install_menu_get_items('hosting/servers');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['weight'] = 2;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
$items = install_menu_get_items('user');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
$items = install_menu_get_items('logout');
$item = db_fetch_array(db_query("SELECT * FROM {menu_links} WHERE mlid = %d", $items[0]['mlid']));
$item['menu_name'] = $menu_name;
$item['customized'] = 1;
$item['weight'] = 1;
$item['options'] = unserialize($item['options']);
install_menu_update_menu_item($item);
menu_rebuild();
$theme = 'eldir';
drupal_set_message(st('Configuring Eldir theme'));
install_disable_theme('garland');
install_default_theme('eldir');
system_theme_data();
db_query("DELETE FROM {cache}");
drupal_set_message(st('Configuring default blocks'));
install_add_block('devshop_hosting', 'devshop_tasks', $theme, 1, 5, 'header', 1);
// @TODO: CREATE DEVSHOP ROLES!
drupal_set_message(st('Configuring roles'));
install_remove_permissions(install_get_rid('anonymous user'), array('access content', 'access all views'));
install_remove_permissions(install_get_rid('authenticated user'), array('access content', 'access all views'));
install_add_permissions(install_get_rid('anonymous user'), array('access disabled sites'));
install_add_permissions(install_get_rid('authenticated user'), array('access disabled sites'));
//install_add_role('aegir client');
node_access_rebuild();
}