0

To install a module available on drupal.org, I do drush dl modulename && drush en modulename. However, when I have module available as an archive file on my local disk instead (.zip or .tar.gz), how can I still use drush to install it?

The archive file could come from downloading a sandbox project snapshot, from a self-developed "custom made" module or similar.

I know I could unpack the module into sites/all/modules/, then enable it with drush en modulename. But I'm looking for nice scriptable commands to do both these steps with drush. (Bit silly, but I like to keep a drush workflow.)

  • 1
    Yes, it's been answered here – Patrick Ryan Mar 12 '15 at 21:17
  • Edited to make clear I want to install from a local archive file, not via git. Still, your link helped. – tanius Mar 13 '15 at 23:12
1

First, you don't need to to type drush dl modulename && drush en modulename instead you can type drush en -y modulename and Drush is intelligent enough to know that you do not have the module and needs to be download it.

Second, if you have a Sandbox you can enable the module drush en -y modulename as long you have the module on your site/all/modules. If is a sandbox project from Drupal.org you probably would need to download it via git.

Just like the sandbox project as long you have it locally you can enable it via drush.

If you wish to download the module via drush you can find the answer at Is it possible to download sandbox projects with Drush?

| improve this answer | |
1

You can use drush make to unpack a module named your_module from an archive file, as follows:

  1. Create a modulename.make file containing:

    core = 7.x
    api = 2
    ; Install from local module archive file.
    projects[your_module][type] = "module"
    projects[your_module][download][type] = "file"
    projects[your_module][download][url] = "file:///dir/your_module.tar.gz"
    
  2. While in the Drupal root directory of your site, execute the Makefile and enable your module:

    drush make --no-core -y your_module.make && drush en -y your_module
    

Alternatively, you can script this into one set of commands, using a temporary file instead of a separate Makefile. Again, to be executed while in the Drupal root directory:

#!/bin/bash
module="your_module"
makefile=$(mktemp)
echo "Created temp file $makefile"
cat << end-of-makefile >$makefile
  core = 7.x
  api = 2
  projects[$module][type] = "module"
  projects[$module][download][type] = "file"
  projects[$module][download][url] = "file:///dir/file.tar.gz"
end-of-makefile
drush make --no-core -y --verbose $makefile
drush en -y $module

(Bash named pipes or bash process substitution via <(echo …) cannot be used here to avoid a temp file. They create streams, which are non-seekable files that drush make fails to read from.)

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.