Skip to content

Instantly share code, notes, and snippets.

@aaronott
Forked from anonymous/gist:4402304
Created December 28, 2012 22:06
Show Gist options
  • Save aaronott/4402398 to your computer and use it in GitHub Desktop.
Save aaronott/4402398 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Usage:
# ./download.sh allmodules.txt
#
# Assumes allmodules.txt is a newline-separated list of projects you want to
# download.
# @todo Error handling of any kind. :P I'm so optimistic. :P
# Versions to attempt to download, in order of preference.
# @todo Maybe someday parameterize this.
versions=(7 6 8)
# Files are called "allsomething.txt"; strip the extension off and make it the
# download destination directory.
# @todo Maybe someday parameterize this.
filename=$1
dir=${filename%%.*}
# If directory doesn't already exist, create it.
`mkdir -p $dir`
# Read in the contents of the file, line by line. Each one is a project name.
while read -r project
do
# Loop through each version.
for version in ${versions[@]}
do
# Attempt to download the project.
# That funny 2>&1 business at the end will ensure that the output from
# Drush can be inspected below.
output=$(drush dl --dev -y --destination=$dir --default-major=$version --package-handler=git_drupalorg $project 2>&1)
# If there is no development release for the project, let's grab the latest
# stable version release.
if [[ $output == *no*development* ]]
then
output=$(drush dl -y --destination=$dir --default-major=$version --package-handler=git_drupalorg $project 2>&1)
fi
# Unfortuantely, Drush commands return a success error code (0), even when
# they don't work. :P Only way to see if this command failed is to check
# the output of the script.
# @todo Re-work this when http://drupal.org/node/1735230 is fixed.
if [[ "$output" != *warning* ]];
then
# No problems? Move onto the next project!
break
fi
done
done < $1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment