Skip to content

Instantly share code, notes, and snippets.

@davidneedham
Last active May 4, 2016 19:23
Show Gist options
  • Save davidneedham/6301151 to your computer and use it in GitHub Desktop.
Save davidneedham/6301151 to your computer and use it in GitHub Desktop.
Drush Alias Wildcard for Enjoy Creativity server, allgoo.de.
<?php
/*
* Name: Drush Alias Wildcard
*
* Description: When working on Enjoy Creativity's server, you
* can always assume the connection information is the same,
* except for the project name. Once you set up your
* ~/.ssh/config to use the hostname for the project, this
* command will let you sync the database or files directory
* between local and dev.
*
* The following alias patterns are expected when this file is
* named ec.aliases.drushrc.php:
*
* @ec.PROJECT.local (for the site on local MAMP)
* @ec.PROJECT.dev (for the site on dev server, allgoo.de)
*
* This file allows you to use Drush aliases as you may already
* be used to, including syncing databases and files from one
* alias to another.
*
* For example, the first command syncs the files directory
* from dev to live and the second command syncs the database
* from dev to live:
*
* drush rsync @ec.example.dev:%files/ @ec.example.local:%files
* drush sql-sync @ec.example.dev @ec.example.local
*
* Assumptions:
* - You're working with a project on the Enjoy Creativity
* development server (http://its.allgoo.de).
* - The server is running the Git Dev Workflow by eosrei
* https://github.com/eosrei/git-dev-workflow.
* - This command is being run locally, not on the server.
* - You already have the project added to your ~/.ssh/config.
* - You are running MAMP, with the Drupal project the name
* of the folder (ie. /Applications/MAMP/htdocs/example).
* - You have a folder called 'drush.dbdumps' located at
* /Applications/MAMP/htdocs/.
* - This file goes within your .drush directory.
* - Your Drupal files directory is at sites/default/files.
* - All projects relevant to Enjoy Creativity are using the
* same pattern for file structure.
* - No multisites.
*
* Credits: This alias was written by David Needham of Enjoy
* Creativity. Enjoy Creativity is a nonprofit with the
* purpose of serving churches and ministries through the
* use and enrichment of open source technologies.
*
* For more info, contact via http://enjoycreativity.com.
*/
// The command you just typed in shell.
$command = $_SERVER['argv'];
// Look at every argument...
foreach ($command as $arg){
// There aren't many cases where there are '.'...
$test = explode('.',$arg);
// ... but there is only one case where there is '@ec'
if($test[0]=="@ec"){
// Set the project to be whatever comes after the '@ec.'
$project = $test[1];
}
}
// Again we assume we're running MAMP locally. You can probably
// change this to whatever your local environment is.
$local_sites = '/Applications/MAMP/htdocs/';
// This will be PROJECT.local
$aliases[$project . '.local'] = array(
// Where the local Drupal root is at.
'root' => $local_sites . $project,
'path-aliases' => array(
// Where are your local files located at?
'%files' => $local_sites . $project . '/sites/default/files',
// Where should drush dumps go?
'%dump-dir' => '/tmp',
)
);
// We can always assume that allgoo.de follows this pattern, and
// we only care about interacting with dev.
$remote_sites = '/var/www/' . $project;
// This will be PROJECT.dev
$aliases[$project . '.dev'] = array(
// Where the remote Drupal root is at.
'root' => $remote_sites . '/dev',
// If ~/.ssh/config is set up, all you need is the host.
'remote-host' => $project,
'path-aliases' => array(
// Where should drush dumps go?
'%files' => $remote_sites . '/dev/sites/default/files',
// Where are your remote files located at? For some reason my
// text editor doesn't like '/home/', so I separate it out
// and concatonate it back together. Not sure why this is,
// or if it makes a significant difference.
'%dump-dir' => '/tmp',
)
);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment