From 71a10d3493122b699f70e322e07a462f65da5d80 Mon Sep 17 00:00:00 2001 From: Adrian Rossouw <adrian@developmentseed.org> Date: Tue, 3 Feb 2009 00:34:11 +0000 Subject: [PATCH] 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. --- db_server/install.provision.inc | 2 +- db_server/provision.mysql.inc | 4 +- ...mysql.module => provision_mysql.drush.inc} | 22 +- db_server/restore.provision.inc | 6 +- db_server/verify.provision.inc | 4 +- platform/backup.provision.inc | 4 +- platform/drupal_verify.php | 2 +- platform/install.provision.inc | 7 +- ...upal.module => provision_drupal.drush.inc} | 67 +++--- platform/provision_drupal_settings.tpl.php | 3 +- platform/restore.provision.inc | 12 +- platform/verify.provision.inc | 18 +- provision.drush.inc | 187 +++++++++++++-- provision.inc | 90 ++++--- provision.module | 227 ------------------ provision.path.inc | 50 ++-- web_server/provision_apache.drush.inc | 78 ++++++ web_server/verify.provision.inc | 2 +- 18 files changed, 405 insertions(+), 380 deletions(-) rename db_server/{provision_mysql.module => provision_mysql.drush.inc} (85%) rename platform/{provision_drupal.module => provision_drupal.drush.inc} (82%) delete mode 100644 provision.module create mode 100644 web_server/provision_apache.drush.inc diff --git a/db_server/install.provision.inc b/db_server/install.provision.inc index 7c43d7cd2..5ac18a50a 100644 --- a/db_server/install.provision.inc +++ b/db_server/install.provision.inc @@ -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']; diff --git a/db_server/provision.mysql.inc b/db_server/provision.mysql.inc index b18bb5b6e..f006ed853 100644 --- a/db_server/provision.mysql.inc +++ b/db_server/provision.mysql.inc @@ -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; } } diff --git a/db_server/provision_mysql.module b/db_server/provision_mysql.drush.inc similarity index 85% rename from db_server/provision_mysql.module rename to db_server/provision_mysql.drush.inc index efe773ba5..ec49abea8 100644 --- a/db_server/provision_mysql.module +++ b/db_server/provision_mysql.drush.inc @@ -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")); } } } diff --git a/db_server/restore.provision.inc b/db_server/restore.provision.inc index 148425175..0f0cfaa34 100644 --- a/db_server/restore.provision.inc +++ b/db_server/restore.provision.inc @@ -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']); } diff --git a/db_server/verify.provision.inc b/db_server/verify.provision.inc index 5c807308b..df4cb0c0d 100644 --- a/db_server/verify.provision.inc +++ b/db_server/verify.provision.inc @@ -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.')); } } } diff --git a/platform/backup.provision.inc b/platform/backup.provision.inc index 165c1337a..a4eaa93f2 100644 --- a/platform/backup.provision.inc +++ b/platform/backup.provision.inc @@ -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; } diff --git a/platform/drupal_verify.php b/platform/drupal_verify.php index d55f03444..d8ec51e3f 100644 --- a/platform/drupal_verify.php +++ b/platform/drupal_verify.php @@ -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); diff --git a/platform/install.provision.inc b/platform/install.provision.inc index 2405467ba..8df351b21 100644 --- a/platform/install.provision.inc +++ b/platform/install.provision.inc @@ -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); } diff --git a/platform/provision_drupal.module b/platform/provision_drupal.drush.inc similarity index 82% rename from platform/provision_drupal.module rename to platform/provision_drupal.drush.inc index b26c46f11..b358645b1 100644 --- a/platform/provision_drupal.module +++ b/platform/provision_drupal.drush.inc @@ -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))); } } + + diff --git a/platform/provision_drupal_settings.tpl.php b/platform/provision_drupal_settings.tpl.php index e629f2647..bb918a821 100644 --- a/platform/provision_drupal_settings.tpl.php +++ b/platform/provision_drupal_settings.tpl.php @@ -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'); diff --git a/platform/restore.provision.inc b/platform/restore.provision.inc index cca733934..c88c57e17 100644 --- a/platform/restore.provision.inc +++ b/platform/restore.provision.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); diff --git a/platform/verify.provision.inc b/platform/verify.provision.inc index 463a63c45..2343596f8 100644 --- a/platform/verify.provision.inc +++ b/platform/verify.provision.inc @@ -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']); } } diff --git a/provision.drush.inc b/provision.drush.inc index 697e66f19..8d7b472b3 100644 --- a/provision.drush.inc +++ b/provision.drush.inc @@ -38,6 +38,77 @@ * @defgroup provisiondrush Command line interface for Provision. * @{ */ +include_once('provision.inc'); +include_once('provision.path.inc'); +provision_init(); +/** + * 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', $GLOBALS['base_url'])); + define('PROVISION_WEB_DISABLE_URL', PROVISION_MASTER_URL .'/provision/disabled'); + define('PROVISION_WEB_MAINTENENCE_URL', PROVISION_MASTER_URL .'/provision/maintenance'); + + // Database + define('PROVISION_MASTER_DB', + provision_get_option('master_db', $GLOBALS['db_url'])); + $db = parse_url(PROVISION_MASTER_DB); + define('PROVISION_DB_USER', $db['user']); + define('PROVISION_DB_PASSWD', $db['pass']); + define('PROVISION_DB_HOST', $db['host']); + + // Drupal does not support multiple types of connections in the same session + preg_match("$^([a-z]*)://$", $GLOBALS['db_url'], $matches); + define('PROVISION_DB_TYPE', $matches[1]); +} + /** * Implementation of hook_drush_command(). @@ -47,58 +118,61 @@ function provision_drush_command() { $items['provision install'] = array( 'callback' => 'provision_command', 'callback arguments' => array('install'), - 'arguments' => array('domain.com' => t('The domain of the site to install.')), - 'description' => t('Provision a new site using the provided data.') + 'arguments' => array('domain.com' => dt('The domain of the site to install.')), + 'description' => dt('Provision a new site using the provided data.'), + 'bootstrap' => DRUPAL_BOOTSTRAP_CONFIGURATION ); $items['provision import'] = array( 'callback' => 'provision_command', 'callback arguments' => array('import'), - 'arguments' => array('domain.com' => t('The domain of the site to import.')), - 'description' => t('Turn an already running site into a provisioned site.') + 'arguments' => array('domain.com' => dt('The domain of the site to import.')), + 'description' => dt('Turn an already running site into a provisioned site.'), + 'bootstrap' => DRUPAL_BOOTSTRAP_CONFIGURATION ); $items['provision update'] = array( 'callback' => 'provision_command', 'callback arguments' => array('update'), - 'arguments' => array('domain.com' => t('The domain of the site to update.')), - 'description' => t('Run any outstanding updates on the site.') + 'arguments' => array('domain.com' => dt('The domain of the site to update.')), + 'description' => dt('Run any outstanding updates on the site.') ); $items['provision backup'] = array( 'callback' => 'provision_command', 'callback arguments' => array('backup'), - 'arguments' => array('domain.com' => t('The domain of the site to back up.')), - 'optional arguments' => array('backup-file' => t('The file to save the backup to. This will be a gzipped tarball.')), - 'description' => t('Generate a back up for the site.') + 'arguments' => array('domain.com' => dt('The domain of the site to back up.')), + 'optional arguments' => array('backup-file' => dt('The file to save the backup to. This will be a gzipped tarball.')), + 'description' => dt('Generate a back up for the site.') ); $items['provision enable'] = array( 'callback' => 'provision_command', 'callback arguments' => array('enable'), - 'arguments' => array('domain.com' => t('The domain of the site to enable (only if enabled).')), + 'arguments' => array('domain.com' => dt('The domain of the site to enable (only if enabled).')), 'description' => 'Enable a disabled site.' ); $items['provision disable'] = array( 'callback' => 'provision_command', 'callback arguments' => array('disable'), - 'arguments' => array('domain.com' => t('The domain of the site to disable (only if disabled).')), + 'arguments' => array('domain.com' => dt('The domain of the site to disable (only if disabled).')), 'description' => 'Disable a site.' ); $items['provision verify'] = array( 'callback' => 'provision_command', 'callback arguments' => array('verify'), - 'arguments' => array('domain.com' => t('The domain of the site to verify).')), - 'description' => 'Verify that the provisioning framework is correctly installed.' + 'arguments' => array('domain.com' => dt('The domain of the site to verify).')), + 'description' => 'Verify that the provisioning framework is correctly installed.', + 'bootstrap' => DRUPAL_BOOTSTRAP_CONFIGURATION, ); $items['provision restore'] = array( 'callback' => 'provision_command', 'callback arguments' => array('restore'), 'description' => 'Restore the site to a previous backup. This will also generate a backup of the site as it was.', - 'arguments' => array('domain.com' => t('The domain of the site to be restored'), - 'site_backup.tar.gz' => t('The backup to restore the site to.')) + 'arguments' => array('domain.com' => dt('The domain of the site to be restored'), + 'site_backup.tar.gz' => dt('The backup to restore the site to.')) ); $items['provision delete'] = array( @@ -111,7 +185,7 @@ function provision_drush_command() { 'callback' => 'provision_command', 'callback arguments' => array('cron'), 'description' => 'Run cron process for site.', - 'arguments' => array('domain.com' => t('The domain of the site to be processed')) + 'arguments' => array('domain.com' => dt('The domain of the site to be processed')) ); if (!function_exists('hosting_setup')) { @@ -139,8 +213,8 @@ function _provision_setup() { $drush_path = sprintf("%s/%s/drush.php", PROVISION_DOCROOT_PATH, drupal_get_path('module', 'drush')); $success &= provision_path('symlink', $drush_path, PROVISION_DOCROOT_PATH . '/drush.php', - t('Created symlink for drush.php file'), - t('Could not create symlink for drush.php'), + dt('Created symlink for drush.php file'), + dt('Could not create symlink for drush.php'), PROVISION_FRAMEWORK_ERROR); $success &= _provision_generate_config(); @@ -166,3 +240,80 @@ function _provision_setup_cmd() { } } + +/** + * Generate a provision.settings.php file to configure provision + */ +function _provision_generate_config() { + provision_log('notice', dt("Generating drushrc.php file")); + provision_path("chmod", PROVISION_DOCROOT_PATH . '/drushrc.php', 0600, + dt('Changed permissions of drushrc.php to @confirm'), + dt('Could not change permissions of drushrc.php to @confirm')); + + provision_save_platform_data(); + provision_path("chmod", PROVISION_DOCROOT_PATH . '/drushrc.php', 0400, + dt('Changed permissions of drushrc.php to @confirm'), + dt('Could not change permissions of drushrc.php to @confirm')); + return TRUE; +} + + +/** + * Load additional modules just for this process + * + * Load additional modules specified by --load_module_name + */ +function provision_load_from_args() { + if (!function_exists('drush_verify_cli')) { + return null; + } + global $args; + $reset = FALSE; + foreach ($args['options'] as $arg => $value) { + if (preg_match("/^load-([a-z\-]*)$/", $arg, $matches)) { + $module = str_replace("-", "_", $matches[1]); + // find file : can only search under provision path + $files = file_scan_directory(dirname(__FILE__), "$module.module", array('.', '..', 'CVS'), 0, TRUE, 'name'); + if (isset($files[$module])) { + provision_log("notice", dt("Loading @module on request", array("@module" => $module))); + $loaded[$module]['name'] = $module; + $loaded[$module]['filename'] = $files[$module]->filename; + include_once($loaded[$module]['filename']); + } + $reset = TRUE; + } + } + $existing = array(); + $list = module_list(TRUE, FALSE); + foreach ($list as $module) { + $existing[$module]['name'] = $module; + $existing[$module]['filename'] = drupal_get_filename('module', $module); + drupal_load('module', $module); + } + $loaded = array_merge($existing, (array) $loaded); + foreach ($loaded as $name => $info) { + $files = file_scan_directory(dirname($info['filename']), ".drush.inc$"); + foreach ($files as $filename => $info2) { + include_once($filename); + } + + } + module_list(TRUE, FALSE, TRUE, $loaded); + // Force to regenerate the stored list of hook implementations. + module_implements('', TRUE, TRUE); +} + +function _provision_default_restart_cmd() { + # try to detect the apache restart command + $command = '/usr/sbin/apachectl'; # a proper default for most of the world + foreach (array('/usr/local/sbin/apachectl', # freebsd + '/usr/sbin/apache2ctl', # debian + apache2 + $command) as $test) { + if (is_executable($test)) { + $command = $test; + } + } + + return "sudo $command graceful"; +} + diff --git a/provision.inc b/provision.inc index 61fe3dbb5..07fb8012e 100644 --- a/provision.inc +++ b/provision.inc @@ -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; +} diff --git a/provision.module b/provision.module deleted file mode 100644 index a1b5b3001..000000000 --- a/provision.module +++ /dev/null @@ -1,227 +0,0 @@ -<?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 - define('PROVISION_MASTER_DB', - provision_get_option('master_db', $GLOBALS['db_url'])); - $db = parse_url(PROVISION_MASTER_DB); - define('PROVISION_DB_USER', $db['user']); - define('PROVISION_DB_PASSWD', $db['pass']); - define('PROVISION_DB_HOST', $db['host']); - - // Drupal does not support multiple types of connections in the same session - preg_match("$^([a-z]*)://$", $GLOBALS['db_url'], $matches); - define('PROVISION_DB_TYPE', $matches[1]); -} - - - -/** - * Load additional modules just for this process - * - * Load additional modules specified by --load_module_name - */ -function provision_load_from_args() { - if (!function_exists('drush_verify_cli')) { - return null; - } - global $args; - $reset = FALSE; - foreach ($args['options'] as $arg => $value) { - if (preg_match("/^load-([a-z\-]*)$/", $arg, $matches)) { - $module = str_replace("-", "_", $matches[1]); - // find file : can only search under provision path - $files = file_scan_directory(dirname(__FILE__), "$module.module", array('.', '..', 'CVS'), 0, TRUE, 'name'); - if (isset($files[$module])) { - provision_log("notice", t("Loading @module on request", array("@module" => $module))); - $loaded[$module]['name'] = $module; - $loaded[$module]['filename'] = $files[$module]->filename; - include_once($loaded[$module]['filename']); - } - $reset = TRUE; - } - } - $existing = array(); - $list = module_list(TRUE, FALSE); - foreach ($list as $module) { - $existing[$module]['name'] = $module; - $existing[$module]['filename'] = drupal_get_filename('module', $module); - drupal_load('module', $module); - } - $loaded = array_merge($existing, (array) $loaded); - foreach ($loaded as $name => $info) { - $files = file_scan_directory(dirname($info['filename']), ".drush.inc$"); - foreach ($files as $filename => $info2) { - include_once($filename); - } - - } - module_list(TRUE, FALSE, TRUE, $loaded); - // Force to regenerate the stored list of hook implementations. - module_implements('', TRUE, TRUE); -} -function _provision_default_restart_cmd() { - # try to detect the apache restart command - $command = '/usr/sbin/apachectl'; # a proper default for most of the world - foreach (array('/usr/local/sbin/apachectl', # freebsd - '/usr/sbin/apache2ctl', # debian + apache2 - $command) as $test) { - if (is_executable($test)) { - $command = $test; - } - } - - return "sudo $command graceful"; -} - -/** - * Generate a provision.settings.php file to configure provision - */ -function _provision_generate_config() { - provision_log('notice', t("Generating drushrc.php file")); - provision_path("chmod", PROVISION_DOCROOT_PATH . '/drushrc.php', 0600, - t('Changed permissions of drushrc.php to @confirm'), - t('Could not change permissions of drushrc.php to @confirm')); - - provision_save_platform_data(); - provision_path("chmod", PROVISION_DOCROOT_PATH . '/drushrc.php', 0400, - t('Changed permissions of drushrc.php to @confirm'), - t('Could not change permissions of drushrc.php to @confirm')); - return TRUE; -} - -/** - * @defgroup provisionui Configure provisioning framework. - * @{ - */ - -/** - * Implementation of hook_menu(). - */ -function provision_menu() { - $items['provision'] = array( - 'title' => 'Configure your platform', - 'description' => 'Configure your platform.', - 'page callback' => 'provision_front', - 'type' => MENU_CALLBACK, - 'access callback' => TRUE, - ); - - $items['provision/disabled'] = array( - 'title' => 'Site disabled', - 'description' => 'Page showed when a site is disabled.', - 'page callback' => 'provision_disabled_site', - 'type' => MENU_CALLBACK, - 'access callback' => 'user_access', - 'access arguments' => array('access content'), - ); - $items['provision/maintenance'] = array( - 'title' => 'Site is undergoing maintenance.', - 'description' => 'Page shown when a site is being restored or moved etc.', - 'page callback' => 'provision_site_maintenance', - 'type' => MENU_CALLBACK, - 'access arguments' => array('access content'), - ); - $items['provision/notfound'] = array( - 'title' => 'Site not found.', - 'description' => 'The site you have requested is not available.', - 'page callback' => 'provision_site_notfound', - 'type' => MENU_CALLBACK, - 'access arguments' => array('access content'), - ); - return $items; -} - -function provision_front() { - if (variable_get('provision_setup', FALSE)) { - drupal_goto('provision/notfound'); - } - #return _provision_requirements("provision_setup"); -} - -function provision_disabled_site() { - drupal_set_breadcrumb(array()); - return "<p>This site was disabled by the site administrators.</p>"; -} - -function provision_site_maintenance() { - drupal_set_breadcrumb(array()); - return "<p>This site is being worked on presently. Check back later.</p>"; -} - -function provision_site_notfound() { - drupal_set_breadcrumb(array()); - return "<p>The site you have requested does not exist.</p>"; -} - -/** - * @} End of "defgroup provisionui" - */ - - diff --git a/provision.path.inc b/provision.path.inc index 12d90e66e..69953e4ac 100644 --- a/provision.path.inc +++ b/provision.path.inc @@ -90,21 +90,21 @@ function provision_path($op, $path, $confirm = TRUE, $succeed_message = NULL, $f $status = ($value == $confirm); if ($status) { if (!is_null($succeed_message)) { - provision_log("message", t($succeed_message, $tokens)); + provision_log("message", dt($succeed_message, $tokens)); } } else { if ($error_codes) { // Trigger a sysem halting error if (!is_null($fail_message)) { - provision_log("error", t($fail_message, $tokens)); + provision_log("error", dt($fail_message, $tokens)); } provision_set_error($error_codes); } else { // Trigger a warning if (!is_null($fail_message)) { - provision_log("warning", t($fail_message, $tokens)); + provision_log("warning", dt($fail_message, $tokens)); } } } @@ -161,7 +161,7 @@ function provision_path_unlink($path) { function provision_path_chmod($path, &$perms, &$reason) { if (!chmod($path, $perms)) { - $reason = t('chmod to @perm failed on @path', array('@perm' => sprintf('%o', $perms), '@path' => $path)); + $reason = dt('chmod to @perm failed on @path', array('@perm' => sprintf('%o', $perms), '@path' => $path)); return false; } clearstatcache(); // this needs to be called, otherwise we get the old info @@ -172,11 +172,11 @@ function provision_path_chmod($path, &$perms, &$reason) { function provision_path_chown($path, &$owner, &$reason) { if ($owner = provision_posix_username($owner)) { if (!chown($path, $owner)) { - $reason = t("chown to @owner failed on @path", array('@owner' => $owner, '@path' => $path)) ; + $reason = dt("chown to @owner failed on @path", array('@owner' => $owner, '@path' => $path)) ; } } else { - $reason = t("the user does not exist"); + $reason = dt("the user does not exist"); } clearstatcache(); // this needs to be called, otherwise we get the old info @@ -190,15 +190,15 @@ function provision_path_chgrp($path, &$group, &$reason) { return $group; } else { - $reason = t("chgrp to @group failed on @path", array('@group' => $group, '@path' => $path)); + $reason = dt("chgrp to @group failed on @path", array('@group' => $group, '@path' => $path)); } } else { - $reason = t("@user is not in @group group", array("@user" => PROVISION_SCRIPT_USER, "@group" => $group)); + $reason = dt("@user is not in @group group", array("@user" => PROVISION_SCRIPT_USER, "@group" => $group)); } } else { - $reason = t("the group does not exist"); + $reason = dt("the group does not exist"); } clearstatcache(); // this needs to be called, otherwise we get the old info @@ -239,16 +239,16 @@ function provision_path_extract($path, &$target, &$reason) { return TRUE; } else { - $reason = t("The file could not be extracted"); + $reason = dt("The file could not be extracted"); } } else { - $reason = t("The target directory could not be written to"); + $reason = dt("The target directory could not be written to"); return false; } } else { - $reason = t("Backup file could not be opened"); + $reason = dt("Backup file could not be opened"); return false; } @@ -256,11 +256,11 @@ function provision_path_extract($path, &$target, &$reason) { function provision_path_symlink($path, &$target, &$reason) { if (file_exists($target) && !is_link($target)) { - $reason = t("A file already exists at @path"); + $reason = dt("A file already exists at @path"); return FALSE; } if (is_link($target) && (readlink($target) != $path)) { - $reason = t("A symlink already exists at target, but it is pointing to @link", array("@link" => readlink($target))); + $reason = dt("A symlink already exists at target, but it is pointing to @link", array("@link" => readlink($target))); return FALSE; } if (is_link($target) && (readlink($target) == $path)) { @@ -272,7 +272,7 @@ function provision_path_symlink($path, &$target, &$reason) { return TRUE; } else { - $reason = t('The symlink could not be created, an error has occured'); + $reason = dt('The symlink could not be created, an error has occured'); return FALSE; } @@ -288,31 +288,31 @@ function provision_path_symlink($path, &$target, &$reason) { */ function _provision_create_dir($path, $name, $perms) { $exists = provision_path("exists",$path, TRUE , - $name . ' ' . t("path exists."), - $name . ' ' . t("path does not exist.") + $name . ' ' . dt("path exists."), + $name . ' ' . dt("path does not exist.") ); if (!$exists) { $exists = provision_path("mkdir", $path, TRUE, - $name . ' ' . t("path has been created."), - $name . ' ' . t("path could not be created."), + $name . ' ' . dt("path has been created."), + $name . ' ' . dt("path could not be created."), PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR); } if ($exists) { provision_path("chown", $path, PROVISION_SCRIPT_USER, - $name . ' ' . t("ownership of path has been changed to @confirm."), - $name . ' ' . t("ownership of path could not be changed to @confirm."), + $name . ' ' . dt("ownership of path has been changed to @confirm."), + $name . ' ' . dt("ownership of path could not be changed to @confirm."), PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR); provision_path("chmod", $path, $perms, - $name . ' ' . t("permissions of path have been changed to @confirm."), - $name . ' ' . t("permissions of path could not be changed to @confirm."), + $name . ' ' . dt("permissions of path have been changed to @confirm."), + $name . ' ' . dt("permissions of path could not be changed to @confirm."), PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR ); $writable = provision_path("writable", $path, TRUE, - $name . ' ' . t("path is writable."), - $name . ' ' . t("path is not writable."), + $name . ' ' . dt("path is writable."), + $name . ' ' . dt("path is not writable."), PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR); } diff --git a/web_server/provision_apache.drush.inc b/web_server/provision_apache.drush.inc new file mode 100644 index 000000000..ba32c4465 --- /dev/null +++ b/web_server/provision_apache.drush.inc @@ -0,0 +1,78 @@ +<?php +// $Id$ +/** + * @file + * Apache provisioning module + * This module simply serves to generate the virtual host entry, and make sure apache gets reloaded properly. + * Because Drupal is running via the command line for the entirety of this process, it is only necessary to make + * it available online once everything has been completed. + * + * This module still requires configuration and sanity checks. Need to figure out a way to inspect the apache configuration, + * to ensure that the sites are getting loaded up correctly. + */ + +/** + * The default template provided for the virtual host configuration + */ +function _provision_apache_default_template() { + return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost.tpl.php"); +} + +/** + * The default template for disabled sites + */ +function _provision_apache_redirect_template() { + return file_get_contents(dirname(__FILE__) ."/provision_apache_vhost_redirect.tpl.php"); +} + +/** + * Delete virtual host file + */ +function _provision_apache_delete_vhost_config($url, $data) { + provision_path("unlink", PROVISION_VHOST_PATH ."/$url", TRUE, dt("Removed apache virtual host configuration")); +} + +/** + * Generate virtual host file + */ +function _provision_apache_create_vhost_config($data, $url, $template = NULL) { + if (is_null($template)) { + $template = variable_get('provision_apache_vhost_template', _provision_apache_default_template()); + } + provision_log("Notice", dt("Generate virtual host configuration file.")); + $writable = provision_path("writable", PROVISION_VHOST_PATH, TRUE , NULL, + dt("Virtual host configuration path @path is not writable."), + PROVISION_PERM_ERROR | PROVISION_FRAMEWORK_ERROR); + $data['extra_config'] = "# Extra configuration from modules:\n"; + foreach (drush_command_implements('provision_vhost_config') as $module) { + $data['extra_config'] .= "# -- $module settings --\n"; + $data['extra_config'] .= module_invoke($module, 'provision_vhost_config', $url, $data) . "\n"; + } + + if ($writable) { + $file = fopen(PROVISION_VHOST_PATH .'/'. $url, "w"); + $text = provision_render_config($template, $data); + fwrite($file, $text); + fclose($file); + } +} + +/** + * Restart Apache + */ +function _provision_apache_restart_apache($cause_error = FALSE) { + //This is required to be configurable, due to the fact that different hosts might need to do this differently. + //TODO : test for this instead of relying on a configuration setting? + $return = drush_shell_exec(escapeshellcmd(PROVISION_RESTART_CMD)); + if (!$return) { + if ($cause_error) { + provision_set_error(PROVISION_WEB_ERROR); + } + provision_log(($cause_error) ? "error" : "warning", "Web server could not be restarted. Changes might not be available until this has been done."); + } + else { + provision_log('notice', dt('Apache has been restarted')); + } + +} + diff --git a/web_server/verify.provision.inc b/web_server/verify.provision.inc index c9be2f904..ac52d6614 100644 --- a/web_server/verify.provision.inc +++ b/web_server/verify.provision.inc @@ -1,7 +1,7 @@ <?php function provision_apache_provision_verify() { - _provision_create_dir(PROVISION_VHOST_PATH, t("Virtual host configuration"), 0700); + _provision_create_dir(PROVISION_VHOST_PATH, dt("Virtual host configuration"), 0700); _provision_apache_restart_apache(TRUE); } -- GitLab