Commit 71a10d34 authored by Adrian Rossouw's avatar Adrian Rossouw Committed by adrian

Synched head with d6 branch. Works with drush 2.x and no longer needs to be...

Synched head with d6 branch. Works with drush 2.x and no longer needs to be enabled on a site, as it is no longer a module. Hosting has not been updated to point to the right place per server, so you have to create the symlink to the central drush.php yourself. I have not sorted out the version specific stuff yet either.
parent e6053db5
......@@ -9,7 +9,7 @@ function provision_mysql_provision_pre_install(&$data, $url = NULL) {
$data['db_host'] = ($data['db_host']) ? $data['db_host'] : PROVISION_DB_HOST;
# generate a random password for use
$data['db_passwd'] = user_password();
$data['db_passwd'] = provision_password();
$data['db_name'] = _provision_mysql_suggest_db_name($data, $url);
$data['db_user'] = $data['db_name'];
......
......@@ -22,7 +22,7 @@ function provision_db_connect() {
if (!$connection) {
provision_set_error(PROVISION_DB_ERROR);
provision_log('error', pt('Could not connect to the master database.'));
provision_log('error', dt('Could not connect to the master database.'));
}
else {
$success = @mysql_select_db('mysql', $connection);
......@@ -31,7 +31,7 @@ function provision_db_connect() {
}
else {
provision_set_error(PROVISION_DB_ERROR);
provision_log('error', pt('Could not select the mysql database.'));
provision_log('error', dt('Could not select the mysql database.'));
return FALSE;
}
}
......
......@@ -32,11 +32,11 @@ function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host)
$status = _provision_mysql_database_exists($db_name);
if ($status) {
provision_log('success', pt('Created @name database', array("@name" => $db_name)));
provision_log('success', dt('Created @name database', array("@name" => $db_name)));
}
else {
provision_set_error(PROVISION_DB_ERROR);
provision_log("error", pt("Could not create @name database", array("@name" => $db_name)));
provision_log("error", dt("Could not create @name database", array("@name" => $db_name)));
}
return $status;
//TODO : Test to confirm that the database is actually writeable. Taking this on faith for now.
......@@ -48,9 +48,9 @@ function _provision_mysql_new_site_db($db_name, $db_user, $db_passwd, $db_host)
function _provision_mysql_destroy_site_db($db_name, $db_user, $db_passwd, $db_host) {
if ( _provision_mysql_database_exists($data['db_name']) ) {
provision_log("notice", t("Dropping database @dbname", array('@dbname' => $db_name)));
provision_log("notice", dt("Dropping database @dbname", array('@dbname' => $db_name)));
if (!_provision_mysql_drop_database($db_name)) {
provision_log("warning", t("Failed to drop database @dbname", array('@dbname' => $db_name)));
provision_log("warning", dt("Failed to drop database @dbname", array('@dbname' => $db_name)));
}
}
......@@ -63,7 +63,7 @@ function _provision_mysql_destroy_site_db($db_name, $db_user, $db_passwd, $db_ho
provision_log("notice", "Revoking privileges");
_provision_mysql_flush_privileges();
if (!_provision_mysql_revoke($db_name, $db_user)) {
provision_log("warning", t("Failed to revoke user privileges"));
provision_log("warning", dt("Failed to revoke user privileges"));
}
}
......@@ -89,7 +89,7 @@ function _provision_mysql_can_create_database() {
_provision_mysql_create_database($test);
if (_provision_mysql_database_exists($test)) {
if (!_provision_mysql_drop_database($test)) {
provision_log("warning", t("Failed to drop database @dbname", array('@dbname' => $test)));
provision_log("warning", dt("Failed to drop database @dbname", array('@dbname' => $test)));
}
return TRUE;
}
......@@ -108,18 +108,18 @@ function _provision_mysql_revoke($name, $username, $host = '') {
function _provision_mysql_import_dump($dump_file, $db_name, $db_user, $db_passwd, $db_host) {
$exists = provision_path("exists", $dump_file, TRUE,
t('Found database dump at @path.'),
t('No database dump was found at @path.'),
dt('Found database dump at @path.'),
dt('No database dump was found at @path.'),
PROVISION_FRAMEWORK_ERROR);
if ($exists) {
$readable = provision_path("readable", $dump_file, TRUE, t('Database dump at @path is readable'),
t('The database dump at @path could not be read.'),
$readable = provision_path("readable", $dump_file, TRUE, dt('Database dump at @path is readable'),
dt('The database dump at @path could not be read.'),
PROVISION_PERM_ERROR);
if ($readable) {
provision_log("notice", sprintf("Importing database using command: mysql -u%s -p%s -h%s %s < %s",
$db_user, $db_passwd, $db_host, $db_name, $dump_file));
if (!provision_shell_exec("mysql -u%s -p%s -h%s %s < %s", $db_user, $db_passwd, $db_host, $db_name, $dump_file )) {
provision_log("error", t("Database import failed"));
provision_log("error", dt("Database import failed"));
}
}
}
......
......@@ -12,7 +12,7 @@ function provision_mysql_provision_pre_restore(&$data, $url = NULL) {
$data['old_db_host'] = $data['db_host'];
# generate a random password for use
$data['db_passwd'] = user_password();
$data['db_passwd'] = provision_password();
$data['db_name'] = _provision_mysql_suggest_db_name($data, $url);
$data['db_user'] = $data['db_name'];
......@@ -38,8 +38,8 @@ function provision_mysql_provision_pre_restore_rollback(&$data, $url = NULL) {
// made. Which could go on infinitely if something is really long.
function provision_mysql_provision_post_restore(&$data, $url = NULL) {
provision_path('unlink', 'sites/'. $url .'/database.sql', TRUE,
t("Removed dump file @path after restoring from it"),
t("Could not remove dump file @path"), PROVISION_PERM_ERROR);
dt("Removed dump file @path after restoring from it"),
dt("Could not remove dump file @path"), PROVISION_PERM_ERROR);
_provision_mysql_destroy_site_db($data['old_db_name'], $data['old_db_user'], $data['old_db_passwd'], $data['old_db_host']);
}
......@@ -13,10 +13,10 @@ function provision_mysql_provision_verify() {
if (PROVISION_CONTEXT_PLATFORM) {
if (!_provision_mysql_can_create_database()) {
provision_set_error(PROVISION_DB_ERROR | PROVISION_FRAMEWORK_ERROR);
provision_log('error', t('Unable to create new databases.'));
provision_log('error', dt('Unable to create new databases.'));
}
else {
provision_log("message", t('Mysql can create new databases.'));
provision_log("message", dt('Mysql can create new databases.'));
}
}
}
......
......@@ -21,8 +21,8 @@ function provision_drupal_provision_backup_validate(&$data, $url = NULL, $backup
if ($backup_file) {
if ( provision_path("exists", $backup_file, FALSE,
t("Backing site up to @path."),
t("Back up file @path already exists."),
dt("Backing site up to @path."),
dt("Back up file @path already exists."),
PROVISION_FRAMEWORK_ERROR)) {
$data['backup_file'] = $backup_file;
}
......
......@@ -2,7 +2,7 @@
// $Id$
require_once(dirname(__FILE__) . '/../provision.inc');
require_once('provision_drupal.module');
require_once('provision_drupal.drush.inc');
$url = ($argv[1]) ? $argv[1] : null;
provision_external_init($url);
......
......@@ -25,8 +25,6 @@ function provision_drupal_provision_install_validate() {
function provision_drupal_provision_pre_install(&$data, $url = NULL) {
// This is the actual drupal provisioning requirements.
_provision_drupal_create_directories($url, $data['profile']);
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file($data, $url);
}
/**
......@@ -36,6 +34,9 @@ function provision_drupal_provision_pre_install(&$data, $url = NULL) {
* weird problems such as the multiple database connections don't confuse drupal.
*/
function provision_drupal_provision_install(&$data, $url = NULL) {
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file($data, $url);
$cmd = sprintf("php %s/drupal_install.php %s %s %s %s", dirname(__FILE__), escapeshellarg($url), escapeshellarg($data['profile']), escapeshellarg($data['language']), escapeshellarg($data['client_email']));
provision_exec($cmd, $data);
}
......@@ -57,7 +58,7 @@ function provision_drupal_provision_install_rollback(&$data, $url = NULL) {
function provision_drupal_provision_post_install(&$data, $url = NULL) {
$data['installed'] = TRUE;
_provision_drupal_maintain_aliases($url, $data);
provision_path("chmod", "./sites/$url/settings.php", 0440, t("Secured settings.php with safe permissions"));
provision_path("chmod", "./sites/$url/settings.php", 0440, dt("Secured settings.php with safe permissions"));
_provision_drupal_rebuild_caches($data, $url);
}
......@@ -8,6 +8,7 @@
* and all the install api code.
*/
include_once('cvs_deploy.inc');
/**
* Initialize the platform / site
......@@ -47,7 +48,7 @@ function provision_drupal_provision_finalize(&$data, $url = NULL) {
function _provision_drupal_url_required() {
if (PROVISION_CONTEXT_PLATFORM) {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error', pt('You need to specify the URL argument for this command'));
provision_log('error', dt('You need to specify the URL argument for this command'));
}
}
......@@ -96,7 +97,7 @@ function _provision_drupal_valid_not_installed_site() {
if (PROVISION_CONTEXT_SITE) {
if (_provision_drupal_site_installed(PROVISION_ACTIVE_URL)) {
provision_set_error(PROVISION_SITE_INSTALLED);
provision_log('error', pt('This site has already been installed.'));
provision_log('error', dt('This site has already been installed.'));
}
}
}
......@@ -133,13 +134,20 @@ function _provision_drupal_default_template() {
* because the modules might provide additional information about the site.
*/
function _provision_drupal_create_settings_file(&$data, $url = NULL) {
provision_log('notice', t("Generate settings.php file"));
provision_log('notice', dt("Generate settings.php file"));
if (provision_path("exists", "sites/$url/settings.php")) {
provision_path("chmod", "sites/$url/settings.php", 0640,
t('Changed permissions of settings.php to @confirm'),
t('Could not change permissions of settings.php to @confirm'));
dt('Changed permissions of settings.php to @confirm'),
dt('Could not change permissions of settings.php to @confirm'));
}
$data['extra_config'] = "# Extra configuration from modules:\n";
foreach (drush_command_implements('provision_drupal_config') as $module) {
$data['extra_config'] .= "# -- $module settings --\n";
$data['extra_config'] .= module_invoke($module, 'provision_drupal_config', $url, $data) . "\n";
}
$fp = fopen("sites/$url/settings.php", "w");
$text = variable_get('provision_drupal_settings_template', _provision_drupal_default_template());
fwrite($fp, "<?php\n". provision_render_config($text, $data));
......@@ -147,11 +155,11 @@ function _provision_drupal_create_settings_file(&$data, $url = NULL) {
# Change the permissions of the file
provision_path("chmod", "sites/$url/settings.php", 0440,
t('Changed permissions of settings.php to @confirm'),
t('Could not change permissions of settings.php to @confirm'));
dt('Changed permissions of settings.php to @confirm'),
dt('Could not change permissions of settings.php to @confirm'));
provision_path("chgrp", "sites/$url/settings.php", PROVISION_WEB_GROUP,
t('Change group ownership of settings.php to @confirm'),
t('Could not change group ownership of settings.php to @confirm'));
dt('Change group ownership of settings.php to @confirm'),
dt('Could not change group ownership of settings.php to @confirm'));
}
/**
......@@ -179,24 +187,24 @@ function _provision_drupal_create_directories($url, $profile = NULL) {
foreach ($paths as $path => $perm) {
if (!is_dir($path)) {
provision_path("mkdir", $path, TRUE,
t("Created <code>@path</code>"),
t("Could not create <code>@path</code>"),
dt("Created <code>@path</code>"),
dt("Could not create <code>@path</code>"),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
}
provision_path("chmod", $path, $perm,
t("Changed permissions of <code>@path</code> to @confirm"),
t("Could not change permissions <code>@path</code> to @confirm"),
dt("Changed permissions of <code>@path</code> to @confirm"),
dt("Could not change permissions <code>@path</code> to @confirm"),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
}
foreach ($grps as $path) {
provision_path("chown", $path, PROVISION_SCRIPT_USER,
t("Changed ownership of <code>@path</code>"),
t("Could not change ownership <code>@path</code>"),
dt("Changed ownership of <code>@path</code>"),
dt("Could not change ownership <code>@path</code>"),
PROVISION_PERM_ERROR | PROVISION_INSTALL_ERROR );
provision_path("chgrp", $path, PROVISION_WEB_GROUP,
t("Changed group ownership of <code>@path</code>"),
t("Could not change group ownership <code>@path</code>"));
dt("Changed group ownership of <code>@path</code>"),
dt("Could not change group ownership <code>@path</code>"));
}
}
......@@ -218,7 +226,7 @@ function _provision_find_profiles() {
include_once('includes/install.inc');
if (!$dir = opendir("./profiles")) {
provision_log('error', t("Cannot find profiles directory"));
provision_log('error', dt("Cannot find profiles directory"));
return FALSE;
}
while (FALSE !== ($name = readdir($dir))) {
......@@ -239,7 +247,7 @@ function _provision_find_profiles() {
$languages['en'] = 1;
// Find languages available
$files = array_keys(file_scan_directory('./profiles/' . $name . '/translations', '\.po$', array('.', '..', 'CVS'), 0, FALSE, 'filepath'));
$files = array_keys(drush_scan_directory('./profiles/' . $name . '/translations', '\.po$', array('.', '..', 'CVS'), 0, FALSE, 'filepath'));
if (is_array($files)) {
foreach ($files as $file) {
if (preg_match('!(/|\.)([^\./]+)\.po$!', $file, $langcode)) {
......@@ -249,7 +257,7 @@ function _provision_find_profiles() {
}
$profile->info['languages'] = array_keys($languages);
$return[$name] = $profile;
provision_log('notice', t('found install profile %name', array('%name' => $name)));
provision_log('notice', dt('found install profile %name', array('%name' => $name)));
}
return $return;
......@@ -266,7 +274,7 @@ function provision_drupal_find_sites() {
}
closedir($dir);
} else {
provision_log("error", t("Cannot find sites directory"));
provision_log("error", dt("Cannot find sites directory"));
$sites = FALSE;
}
return $sites;
......@@ -292,10 +300,6 @@ function _provision_drupal_get_cvs_versions($files) {
function _provision_drupal_import_site(&$data, $url = NULL) {
if (!($data = provision_get_site_data($url))) {
$data = array(); // initialize site data to empty array
}
$cmd = sprintf("php %s/drupal_import.php %s", dirname(__FILE__), escapeshellarg($url));
if (provision_exec($cmd, $data)) {
$data['installed'] = TRUE;
......@@ -303,9 +307,6 @@ function _provision_drupal_import_site(&$data, $url = NULL) {
else {
$data['installed'] = FALSE;
}
provision_save_site_data($url, $data);
return $data;
}
/**
......@@ -339,8 +340,8 @@ function _provision_drupal_maintain_aliases($data, $url) {
unset($old_aliases[$alias]);
}
provision_path("symlink", $url, PROVISION_DOCROOT_PATH . "/sites/" . $alias,
t("Created symlink for alias @alias", array("@alias" => $alias)),
t("Could not create symlink for alias @alias", array("@alias" => $alias)));
dt("Created symlink for alias @alias", array("@alias" => $alias)),
dt("Could not create symlink for alias @alias", array("@alias" => $alias)));
}
// Delete existing aliases that are no longer present
_provision_drupal_delete_aliases(array_keys($old_aliases));
......@@ -354,7 +355,9 @@ function _provision_drupal_maintain_aliases($data, $url) {
function _provision_drupal_delete_aliases($aliases) {
foreach ($aliases as $alias) {
provision_path("unlink", PROVISION_DOCROOT_PATH . "/sites/" . $alias, TRUE,
t("Removed symlink for alias @alias", array("@alias" => $alias)),
t("Could not remove symlink for alias @alias", array("@alias" => $alias)));
dt("Removed symlink for alias @alias", array("@alias" => $alias)),
dt("Could not remove symlink for alias @alias", array("@alias" => $alias)));
}
}
......@@ -30,6 +30,8 @@
$conf['cache'] = 1;
$conf['clean_url'] = 1;
<?php print $extra_config; ?>
/**
* This was added from Drupal 5.2 onwards.
*/
......@@ -46,7 +48,6 @@
}
}
# Additional host wide configuration settings. Useful for safely specifying configuration settings.
if (file_exists('<?php print PROVISION_CONFIG_PATH . '/' ?>includes/global.inc')) {
include_once('<?php print PROVISION_CONFIG_PATH . '/' ?>includes/global.inc');
......
......@@ -28,8 +28,8 @@ function provision_drupal_provision_restore_validate(&$data, $url = null, $resto
_provision_drupal_valid_installed_site();
$exists = provision_path("exists", $restore_file, TRUE,
pt("Restoring site from @path"),
pt("Could not find backup file @path"),
dt("Restoring site from @path"),
dt("Could not find backup file @path"),
PROVISION_FRAMEWORK_ERROR);
if ($exists) {
$data['restore_file'] = $restore_file;
......@@ -43,8 +43,8 @@ function provision_drupal_provision_pre_restore(&$data, $url, $restore_file) {
provision_invoke('backup', &$data, $url);
provision_path("extract", $data['restore_file'], PROVISION_SITES_PATH ."/$url.restore",
pt('Successfully extracted the contents of @path'),
pt('Failed to extract the contents of @path'),
dt('Successfully extracted the contents of @path'),
dt('Failed to extract the contents of @path'),
PROVISION_PERM_ERROR, PROVISION_FRAMEWORK_ERROR);
}
......@@ -62,8 +62,8 @@ function provision_drupal_provision_restore(&$data, $url) {
$old = PROVISION_SITES_PATH ."/$url.restore";
$new = PROVISION_SITES_PATH ."/$url";
provision_path("switch_paths", $old, $new ,
pt('Swapping out the @path and @confirm directories was successful.'),
pt('Swapping the @path and @confirm directories has failed.'),
dt('Swapping out the @path and @confirm directories was successful.'),
dt('Swapping the @path and @confirm directories has failed.'),
PROVISION_PERM_ERROR);
// make sure it has the latest site data available
_provision_drupal_create_settings_file($data, $url);
......
......@@ -16,14 +16,14 @@ function provision_drupal_provision_verify_validate() {
*/
function provision_drupal_provision_verify(&$data, $url = null) {
if (PROVISION_CONTEXT_PLATFORM) {
_provision_create_dir(PROVISION_CONFIG_PATH, t('Provision configuration'), 0700);
_provision_create_dir(PROVISION_BACKUP_PATH, t('Web server configuration'), 0700);
provision_path("writable", "sites", TRUE, t("Drupal sites directory is writable by the provisioning script"),
t("Drupal sites directory is not writable by the provisioning script"), PROVISION_PERM_ERROR);
_provision_create_dir(PROVISION_CONFIG_PATH, dt('Provision configuration'), 0700);
_provision_create_dir(PROVISION_BACKUP_PATH, dt('Web server configuration'), 0700);
provision_path("writable", "sites", TRUE, dt("Drupal sites directory is writable by the provisioning script"),
dt("Drupal sites directory is not writable by the provisioning script"), PROVISION_PERM_ERROR);
$data['sites'] = array_keys((array) provision_drupal_find_sites()); // return list of hosted sites. used to determine whether or not to import.
$data['platform'] = array('short_name' => 'drupal', 'version' => VERSION);
provision_log('notice', t("This platform is running @short_name @version",
$data['platform'] = array('short_name' => 'drupal', 'version' => drush_drupal_version());
provision_log('notice', dt("This platform is running @short_name @version",
array('@short_name' => 'drupal', '@version' => VERSION)));
$data['profiles'] = _provision_find_profiles();
$cmd = sprintf("php %s/drupal_verify.php", dirname(__FILE__));
......@@ -34,12 +34,12 @@ function provision_drupal_provision_verify(&$data, $url = null) {
_provision_drupal_maintain_aliases($data, $url);
// Requires at least the database settings to complete.
_provision_drupal_create_settings_file($data, $url);
$cmd = sprintf("php %s/drupal_verify.php %s", dirname(__FILE__), $url);
#$cmd = sprintf("php %s/drupal_verify.php %s", dirname(__FILE__), $url);
#provision_exec($cmd, $data);
}
provision_exec($cmd, $data);
if (is_array($data['modules'])) {
// get the correct version names for everything.
$data['modules'] = _provision_drupal_get_cvs_versions($data['modules']);
#$data['modules'] = _provision_drupal_get_cvs_versions($data['modules']);
}
}
......
This diff is collapsed.
......@@ -38,20 +38,17 @@ define('PROVISION_OUTPUT', 'PROVISION_OUTPUT_START>>>%s<<<PROVISION_OUTPUT_END')
*
*/
function provision_invoke($hook, &$data, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg4 = NULL, $arg5 = NULL) {
$modules = module_list(FALSE, FALSE);
foreach ($modules as $module) {
$files = file_scan_directory(dirname($module['filename']), $hook . ".provision.inc$");
if (is_array($files)) {
foreach ($files as $filename => $info) {
include_once($filename);
}
$files = drush_scan_directory(dirname(__FILE__), $hook . ".provision.inc$");
if (is_array($files)) {
foreach ($files as $filename => $info) {
include_once($filename);
}
}
// First we build a list of functions are about to execute
$variations = array($hook . "_validate", "pre_$hook", $hook, "post_$hook");
foreach ($variations as $var_hook) {
foreach (module_implements("provision_$var_hook") as $name) {
foreach (drush_command_implements("provision_$var_hook") as $name) {
$functions[] = $name . '_provision_' . $var_hook;
}
}
......@@ -90,15 +87,16 @@ function provision_invoke($hook, &$data, $arg1 = NULL, $arg2 = NULL, $arg3 = NUL
function provision_command($hook, $arg1 = NULL, $arg2 = NULL, $arg3 = NULL, $arg4 = NULL, $arg5 = NULL) {
$data = array();
foreach (module_implements("provision_init") as $name) {
foreach (drush_command_implements("provision_init") as $name) {
$func = $name . '_provision_init';
$func($data, $arg1, $arg2, $arg3, $arg4, $arg5);
provision_log('notice', "Initializing $name");
_provision_log_messages();
}
if (!provision_get_error()) {
$success = provision_invoke($hook, $data, $arg1, $arg2, $arg3, $arg4, $arg5);
if ($success) {
foreach (module_implements('provision_finalize') as $name) {
foreach (drush_command_implements('provision_finalize') as $name) {
$func = $name . '_provision_finalize';
$func($data, $arg1, $arg2, $arg3, $arg4, $arg5);
_provision_log_messages();
......@@ -185,13 +183,8 @@ function provision_output($data = array()) {
}
else {
if ($return) {
if ($output = theme('provision_'. $data['task_type'] .'_output', $url, $return)) {
return $output;
}
else {
/** TODO : return a cleanly formatted display of all the necessary information */
print_r($return);
}
/** TODO : return a cleanly formatted display of all the necessary information */
print_r($return);
}
}
exit($error);
......@@ -389,7 +382,7 @@ function provision_load_site_data($url) {
* @param data
* The complete data structure that has been created. Only settings that have been changed will be recorded.
*/
function provision_save_site_data($url, $data) {
function provision_save_site_data($data, $url) {
global $args;
$conf_file = "sites/$url/site.php";
......@@ -398,7 +391,7 @@ function provision_save_site_data($url, $data) {
include(PROVISION_DOCROOT_PATH . '/drushrc.php'); // load drush rc
$exclude = array_merge($exclude, array_keys($options));
if (file_exists($conf_file) && !is_writable($conf_file)) {
provision_path("chmod", $conf_file, 0600, t("Made site.php file writable"));
provision_path("chmod", $conf_file, 0600, dt("Made site.php file writable"));
}
//initialize the file. this is lame, i know. but it will work.
$fp = fopen($conf_file, 'w'); //Append to the end of the config file.
......@@ -409,7 +402,7 @@ function provision_save_site_data($url, $data) {
else {
fwrite($fp, "<?php\n");
$timestamp = mktime();
fwrite($fp, "#". format_date($timestamp, 'large'));
# fwrite($fp, "#". format_date($timestamp, 'large'));
foreach ($data as $key => $value) {
if (!in_array($key, $exclude)) {
$line = "\n\$data['$key'] = ". var_export($value, TRUE) .';';
......@@ -418,7 +411,7 @@ function provision_save_site_data($url, $data) {
}
fwrite($fp, "\n");
fclose($fp);
provision_path('chmod', $conf_file, 0400, t('Protected site.php file'));
provision_path('chmod', $conf_file, 0400, dt('Protected site.php file'));
}
}
......@@ -442,7 +435,7 @@ function provision_save_platform_data() {
else {
fwrite($fp, "<?php\n");
$timestamp = mktime();
fwrite($fp, "#". format_date($timestamp, 'large'));
# fwrite($fp, "#". format_date($timestamp, 'large'));
foreach ($args['options'] as $key => $value) {
if (!in_array($key, $exclude)) {
$line = "\n\$options['$key'] = ". var_export($value, TRUE) .';';
......@@ -469,13 +462,13 @@ function provision_save_platform_data() {
*/
function provision_value_list() {
/** TODO: Complete the value list to allow the front end to more easily edit the settings. */
$values['site_url'] = t('The domain name used to access the site. This is defaulted to the value used on the command line.');
$values['db_type'] = t('The type of database server used');
$values['db_username'] = t('Username to access database for site');
$values['db_password'] = t('Password to access database for site');
$values['db_name'] = t('Database name for the site');
$values['profile'] = t('Install profile of site');
$values['task_type'] = t('What type of task has been used. Only used in conjuction with hosting front end');
$values['site_url'] = dt('The domain name used to access the site. This is defaulted to the value used on the command line.');
$values['db_type'] = dt('The type of database server used');
$values['db_username'] = dt('Username to access database for site');
$values['db_password'] = dt('Password to access database for site');
$values['db_name'] = dt('Database name for the site');
$values['profile'] = dt('Install profile of site');
$values['task_type'] = dt('What type of task has been used. Only used in conjuction with hosting front end');
return $values;
}
......@@ -520,14 +513,14 @@ function _provision_recursive_delete($path) {
}
$rm = provision_path('rmdir', $path, TRUE,
t('Deleting @path directory sucessful.', array('@path' => $path)),
t('Deleting @path directory failed.', array('@path' => $path)));
dt('Deleting @path directory sucessful.', array('@path' => $path)),
dt('Deleting @path directory failed.', array('@path' => $path)));
$ret = $ret && $rm;
}
else {
$rm = provision_path('unlink', $path, TRUE, NULL,
t('Deleting @path file failed.', array('@path' => $path)));
dt('Deleting @path file failed.', array('@path' => $path)));
$ret = $ret && $rm;
}
return $ret;
......@@ -695,7 +688,7 @@ function provision_proc_open($cmd, &$data = NULL) {
* Run an external provision script and integrate it's output
*/
function provision_exec($cmd, &$data) {
provision_log('command', t('Running: @cmd', array('@cmd' => $cmd)));
provision_log('command', dt('Running: @cmd', array('@cmd' => $cmd)));
$proc = provision_proc_open($cmd, $data);
if ($proc['output']) {
$values = provision_parse_output($proc['output']);
......@@ -711,7 +704,7 @@ function provision_exec($cmd, &$data) {
}
else {
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_log('error',t("The command could not be executed succesfully (returned: !return, code: %code)", array("!return" => $proc['output'], "%code" => $proc['code'])));
provision_log('error', dt("The command could not be executed succesfully (returned: !return, code: %code)", array("!return" => $proc['output'], "%code" => $proc['code'])));
return FALSE;
}
}
......@@ -730,7 +723,7 @@ function provision_get_option($option, $default) {
}
/**
* A wrapper for t(). The st() function is too specific for our purposes
* A wrapper for dt(). The st() function is too specific for our purposes
*/
function pt($string, $args = array()) {
if (function_exists('t')) {
......@@ -763,6 +756,7 @@ function pt($string, $args = array()) {
* Some scripts need to run with drupal as the only active database, and this allows us to do that.
*/
function provision_external_init($url, $bootstrap = TRUE) {
$url = ($url) ? $url : 'default';
$drupal_base_url = parse_url(sprintf("http://" . $url));
$_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
$_SERVER['PHP_SELF'] = $drupal_base_url['path'].'/install.php';
......@@ -771,6 +765,7 @@ function provision_external_init($url, $bootstrap = TRUE) {
$_SERVER['REQUEST_METHOD'] = NULL;
$_SERVER['SERVER_SOFTWARE'] = NULL;
define('PROVISION_DRUSH_BACKEND', true);
if ($bootstrap) {
include_once('includes/bootstrap.inc');
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
......@@ -779,9 +774,32 @@ function provision_external_init($url, $bootstrap = TRUE) {
print stream_get_contents(STDIN);
$string = ob_get_contents();
ob_end_clean();
if (trim($string)) {
return unserialize($string);
}
return TRUE;
}
function provision_password($length = 10) {
// This variable contains the list of allowable characters for the
// password. Note that the number 0 and the letter 'O' have been
// removed to avoid confusion between the two. The same is true
// of 'I', 1, and 'l'.
$allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
// Zero-based count of characters in the allowable list:
$len = strlen($allowable_characters) - 1;
// Declare the password as a blank string.
$pass = '';
// Loop the number of times specified by $length.
for ($i = 0; $i < $length; $i++) {
// Each iteration, pick a random character from the
// allowable string and append it to the password:
$pass .= $allowable_characters[mt_rand(0, $len)];
}
return $pass;
}
<?php
// $Id$
/**
* @file
* Provisioning Framework
*/
// Include the provisioning API.
include_once('provision.inc');
include_once('provision.path.inc');
include_once('provision.drush.inc');
/**
* Implementation of hook_init
*
* Provide defines for all the major paths and settings.
* These are settings that must not be modified during the running of the
* program, but are configurable.
*/
function provision_init() {
// Do not allow the program to be run as the root user. ever
$name = posix_getpwuid(posix_geteuid());
if ($name['name'] == 'root') {
provision_log('error', 'You are running the provision script as the root user. Exiting');
provision_set_error(PROVISION_FRAMEWORK_ERROR);
provision_output($url);
}
// Load requested additional modules
provision_load_from_args();
// Set up defines for platform
$docroot = provision_get_option(array("r", "root"), $_SERVER['PWD']);
$backend = provision_get_option(array('b', 'backend'), 0);
define("PROVISION_DRUSH_BACKEND", $backend);
define('PROVISION_DOMAIN', $_SERVER['HTTP_HOST']);
// Paths
$path = ($docroot) ? $docroot : $_SERVER['DOCUMENT_ROOT'];
define('PROVISION_DOCROOT_PATH', rtrim($path, '/'));
define('PROVISION_SITES_PATH', rtrim($path, '/') .'/sites');
define('PROVISION_DRUSH_PATH', './drush.php');
$parts = explode("/", rtrim($path, '/'));
array_pop($parts);
define('PROVISION_PARENT_PATH', rtrim(implode("/" , $parts), '/'));
define('PROVISION_BACKUP_PATH',
provision_get_option('backup_path', PROVISION_PARENT_PATH . '/backups'));
define('PROVISION_CONFIG_PATH',
provision_get_option('config_path', PROVISION_PARENT_PATH .'/config'));
define('PROVISION_VHOST_PATH', PROVISION_CONFIG_PATH .'/vhost.d');
// Commands
define('PROVISION_RESTART_CMD',
provision_get_option('restart_cmd', _provision_default_restart_cmd()));
// System account
$info = posix_getgrgid(posix_getgid());
define('PROVISION_WEB_GROUP',
provision_get_option('web_group', $info['name'] ));
define('PROVISION_SCRIPT_USER',
provision_get_option('script_user', get_current_user() ));
// Redirection urls
define('PROVISION_MASTER_URL',
provision_get_option('master_url', variable_get('install_url', $GLOBALS['base_url'])));
define('PROVISION_WEB_DISABLE_URL', PROVISION_MASTER_URL .'/provision/disabled');
define('PROVISION_WEB_MAINTENENCE_URL', PROVISION_MASTER_URL .'/provision/maintenance');
// Database