drush-ops / drush

Drush is a command-line shell and scripting interface for Drupal, a veritable Swiss Army knife designed to make life easier for those who spend their working hours hacking away at the command prompt.
https://www.drush.org
2.34k stars 1.08k forks source link

automatically add aliases from external hosts #1486

Closed guaka closed 9 years ago

guaka commented 9 years ago

Here's the code I'm using myself, it's a neat way to get a whole bunch of aliases on your dev machine. #1485 was causing trouble with this...

function my_add_aliases($aliases) {
  $d_locations = array(array('example.com', '/var/www/drupal7'),
                       array('host2.example.com', '/var/www/drupal7'),
                       array('host2.example.com', '/var/www/drupal6'),
);

  foreach ($d_locations as $host_path) {
    $host = $host_path[0];
    $path = $host_path[1];
    $dd_path = '~/.drush/';  // dot drush // THE ~ PART MIGHT NOT WORK AS IS
    $f_cache_list = 'site-list-cache-' . $host . str_replace('/', "-", $path);
    if ((time()-filectime($dd_path . $f_cache_list)) > 86400) {
      $cmd = "ssh $host ls $path/sites > " . $dd_path . $f_cache_list;
      // echo $cmd . "\n";
      drush_shell_exec($cmd);
    }
    $sites = file($dd_path . $f_cache_list);

    foreach ($sites as $k => $v) {
      $s = trim($v);
      $aliases[$s] = array(
                           'uri' => $s,
                           'root' => $path,
                           'remote-host' => $host,
                           );
    }
  }
  return $aliases;
}

$aliases = my_add_aliases($aliases);

Just wrote this quickly to scratch an itch and not sure how to properly turn this into a patch.

guaka commented 9 years ago

Feel free to add this to official drush (under GPL I guess?). I'd also be happy do it myself if I get a wee bit of guidance.

weitzman commented 9 years ago

Clever. I have long wanted a chef-like system where Drush would consult an external server for its site aliases, commands, etc. When we build that, we would probably just rsync the files into position whenever cron tells us to. That way, the Drush alias system continues to work as today.