Skip to content

Instantly share code, notes, and snippets.

@mbutsko
Forked from halcyonCorsair/mymodule.drush.inc
Created January 9, 2012 22:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbutsko/1585195 to your computer and use it in GitHub Desktop.
Save mbutsko/1585195 to your computer and use it in GitHub Desktop.
Ugly as sin module to override drupal directory creation on install...broken for migrate though
<?php
/**
* Implementation of hook_provision_drupal_create_directories().
*
* Make the directory create phase of a site install web cluster ready.
* A patch to provision is needed.
* @url http://drupal.org/files/issues/provision_drupal_create_directories.patch
*/
function mymodule_provision_drupal_create_directories(&$dirs, $url) {
$web_group = d('@server_master')->web_group;
$path = "sites/$url";
if (!is_dir($path)) {
provision_file()->mkdir($path)
->succeed('Created <code>@path</code>')
->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR');
}
provision_file()->chmod($path, $dirs[$path], false)
->succeed('Changed permissions of <code>@path</code> to @perm')
->fail('Could not change permissions <code>@path</code> to @perm');
unset($dirs[$path]);
$link = 'cache';
$path = d()->root . '/' . $link;
if (!is_link($path) && !preg_match("/hostmaster/", $path)) {
drush_set_error("cache directory $realpath is not a link");
provision_file()->symlink($dir, d()->root . '/' . $link)
->succeed('linked <code>@path</code> to <code>@target</code>')
->fail('Could not create link to <code>@path</code> from <code>@target</code>', 'DRUSH_PERM_ERROR');
}
$symlink = array(
"sites/$url/files",
"sites/$url/private",
);
foreach ($symlink as $link) {
if (isset($dirs[$link])) {
unset($dirs[$link]);
}
$dir = '/var/lib/sitedata/aegir/' . "$url/" . basename($link);
if (!is_dir($dir)) {
provision_file()->mkdir($dir)
->succeed('Created <code>@path</code>')
->fail('Could not create <code>@path</code>', 'DRUSH_PERM_ERROR');
$path = '/var/lib/sitedata/aegir/' . $url;
$perm = 0755;
provision_file()->chmod($path, $perm, FALSE)
->succeed('Changed permissions of <code>@path</code> to @perm')
->fail('Could not change permissions <code>@path</code> to @perm');
}
if (is_link($link)) {
$realpath = realpath($link);
if ($realpath == $dir) {
$group_id = filegroup($dir);
$group_info = posix_getgrgid($group_id);
if (!empty($group_info['name']) && $group_info['name'] != $web_group) {
provision_file()->chgrp($dir, $web_group, FALSE)
->succeed('Changed group ownership of <code>@path</code> to @gid')
->fail('Could not change group ownership <code>@path</code> to @gid');
}
continue;
}
else {
drush_log(t('Link <code>@link</code> does\'t point to sitedata directory <code>@dir</code>, hopefully fixing now...', array('@link' => $link, '@dir' => $dir)), 'error');
provision_file()->symlink($dir, d()->root . '/' . $link)
->succeed('linked <code>@path</code> to <code>@target</code>')
->fail('Could not create link to <code>@path</code> from <code>@target</code>', 'DRUSH_PERM_ERROR');
continue;
}
}
// If the directory already exists, then we need to move all the existing
// contents into the sitedata directory before we remove it.
$realpath = realpath($link);
if ($realpath && !is_link($realpath)) {
if (!drush_shell_exec('cd %s && tar -c * | tar -x -C %s', $realpath, $dir)) {
drush_set_error("Cannot move contents out from $realpath");
drush_set_error(print_r(drush_shell_exec_output(), true));
continue;
}
// Delete the old <platform>/sites/<site>/<directory>
if (!drush_shell_exec('rm -rf %s', $realpath)) {
drush_set_error("Cannot rm $realpath");
drush_set_error(print_r(drush_shell_exec_output(), true));
continue;
}
}
// Finally, make the symlink.
provision_file()->symlink($dir, d()->root . '/' . $link)
->succeed('linked <code>@path</code> to <code>@target</code>')
->fail('Could not create link to <code>@path</code> from <code>@target</code>', 'DRUSH_PERM_ERROR');
//provision_file()->chgrp($dir, $web_group, FALSE)
provision_file()->chgrp($dir, $web_group, TRUE)
->succeed('Changed group ownership of <code>@path</code> to @gid')
->fail('Could not change group ownership <code>@path</code> to @gid');
// Ensure correct permissions
$perm = 02770;
//provision_file()->chmod($dir, $perm, TRUE)
provision_file()->chmod($dir, $perm, FALSE)
->succeed('Changed permissions of <code>@path</code> to @perm')
->fail('Could not change permissions <code>@path</code> to @perm');
}
}
diff --git a/platform/provision_drupal.drush.inc b/platform/provision_drupal.drush.inc
index 071806e..e4baaff 100644
--- a/platform/provision_drupal.drush.inc
+++ b/platform/provision_drupal.drush.inc
@@ -237,6 +237,9 @@ function _provision_drupal_create_directories($url = NULL, $profile = NULL) {
"sites/$url/private/temp"
);
+ // Allow other commands to add or alter the directories to be created.
+ drush_command_invoke_all('provision_drupal_create_directories', $mkdir, $url);
+
foreach ($mkdir as $path => $perm) {
if (!is_dir($path)) {
provision_file()->mkdir($path)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment