Thursday, May 30, 2013

Lazy mans Drupal quasi install profile using drush

This is one better than a standard drush make file because it actually enables and disables modules and themes according to the original site.

I might be missing something but I can find anything about drush doing this automatically- but it sure seems like there ought to be a way to use drush to spin up a site with a predetermined set of modules and then enable or disable certain modules for you - and base it all on an existing drupal instance.

After all, drush can do the following:

create a make file that will download all modules:  drush make-generate  
list modules that are enabled:    drush pm-list --status=enabled
enable modules: drush pm-enable module_name1 module_name2

It seems to me all of that should be bundled together for folks who don't want to make an install profile but want a certain list of modules installed and then a set of those modules enabled and/or a set of default modules disabled. All of these things can be done with drush but it isn't automated like it should be ( as far as I know at any rate.)  Or maybe making install profiles isn't as hard as I think it is... I dunno

Here is what I found that seems to work for me. 

1. Set up a site that has all of the modules you want and then enable or disable modules as needed. 
2. Make a drush make file.

drush make-generate > mysite.make

3. Create a list of enabled modules

drush pm-list --status=enabled --pipe > mysite-enabled.list

4. Create a list of disabled modules

drush pm-list --status=disabled --pipe > mysite-disabled.list

5. Copy all three files (mysite.make, mysite-enabled.list, and mysite-disabled.list) into the directory of the new site.

6. In the new site directory do:

drush make mysite.make

and let it do it's thing. 

7. Create the database for your site in the normal manner either with drush or myphpadmin or however you are used to. I haven't tested it but I think you can do drush sql-create with a bunch of options to create the database- this means you could in theory do everything from the command line and/or create a shell script to do all of this. 

8. Go to the new site with a web browser- you can use any profile you want but I usually use the default profile for Drupal 7. After the site is finished installing you can look at the modules page and see all of your modules. But wait! They aren't enabled!!! I have 338 modules to enable and 4 modules to disable! I'll be clicking all damn day! 

No, you won't have to click all of them by hand, just do this:

drush pm-enable $(cat mysite-enabled.list)

Answer 'y' when it asks if you are sure.

Then disabled the rest:

drush pm-disabled $(cat mysite-disabled.list)

That's it! 

There has to be a better/easier way to do this but I couldn't find one after a few hours of goggling

I tested this with Drupal 7.22 and Drush 5.9. If anyone knows of a better, lazier, slicker way of doing this please please let me know. 




No comments:

Post a Comment