Skip to main content
Drush Rush - Scripting Drupal Installation

Drush Rush - Scripting Drupal Installation

I've been using Drupal for several years now and love the CMS. It seems that every day I find something else about Drupal or a specific custom module or add-on that makes it better and better.

I've known about Drush, the command-line utility for Drupal, for awhile now but only recently starting using it and digging through the docs to see what it's actually capable of. Today was the day I unlocked the golden door to consistent and simplified installations — the site-install or si command with shell scripts.

The reason I started looking into this is that at my job, we use Puppet to control our system builds so they are predictable. Our Drupal skeleton worked, but someone still had to open the new site in a browser and run the Drupal installation manually. Ugh! There had to be a better way! That's when I started researching Drush installations.

I'm not a shell script guru by any means, but with what I do know and some help from the Drush documentation, I was able to throw together a working script that simulates closely what our Puppet manifest does when creating a new Drupal site in less than an hour.

Feel free to use and extend the following shell script (written for OS X Yosemite‎). Just substitute the variable values with values for your system.

#!/bin/sh
#
# This is a basic shell script to install a previously downloaded tarball
# of Drupal core to create an entirely new site. The settings variable is set
# because I have a pre-configured "default.settings.php" file with
# configuration variables pre-set with values that I use most often for new 
# Drupal sites which is stored in a known location on my file system. The
# default.settings.php file is removed from the extracted Drupal core archive
# and replaced with my customized file BEFORE the Drush installation runs.
#
# Drupal core source file.
source=/Users/ronald/Downloads/drupal-7.34.tar.gz

# Target directory for the installation
target=/Users/ronald/sites/dev/drupaltest.com/htdocs

# Pre-edited 'default.settings.php' file location
settings=/Users/ronald/drupal/config/default.settings.php

# Database configuration string.
db_settings=mysql://dbuser:dbpass@dbhost:3306/dbname

# Drupal super user to create (UID 1)
user=admin

# Drupal super user password
pass=xxxxxx

# The site name
sitename="Drush Install Test"

# The site email address
sitemail=support@somedomain.com

# First - untar the archive file into the target directory.
/usr/bin/tar -xf $source -C $target --strip-components=1

# Second - Remove the file sites/default/default.settings.php from the
#          the extracted files.
rm "$target/sites/default/default.settings.php"

# Third - Copy the edited version of 'default.settings.php' into the
#         sites/default folder so Drush will have that file available 
#         to copy to settings.php when the installation runs.
#
cp $settings "$target/sites/default/default.settings.php"

# Fourth - Change to the $target directory and use Drush to install the 
#          Drupal site in that directory.
#
cd $target; drush si standard --db-url=$db_settings --account-name=$user --account-pass=$pass --clean-url=1 --site-name=$sitename --site-mail=$sitemail --locale=en -y

NOTICE: The above script is provided as-is with no warranty. I am not responsible for system damage or data loss. Use the above script at your own risk.

Tags

Add new comment

Plain text

  • No HTML tags allowed.
  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.