Short shell script for speeding up getting Drupal modules

15 Jan 2008
Posted by joshb

What follows is a short shell script I use for making it easier to get modules from the Drupal repository. It is best to use this script only with sources where you have a great deal of confidence in the source of the file you're downloading. Of course nothing substitutes for using good practices when it comes to deciding whether to install a program and its possible implications.

Read on for the code itself. It is a very simple script that makes it easy to copy the location of a file from a website and then download and uncompress the file. It could be much fancier but it does the trick.

#!/bin/shif [ $# -ne 1 ]; then         echo 1>&2 Usage: dget URL         exit 127ficurl $1 | tar xzv

To use this script on Mac OS X copy it into a text file. You then need to set permissions to make it executable. The easiest way to do this is:

chmod a+x dget

I'll write more about it tomorrow but this script comes in handy when you need to download more than 100 modules. There certainly are some other ways of using CVS and other tools but if one wants to look at the web page for modules and read the notes on each one this is an easy way to get around some extra typing.

0
Your rating: None

Comments

another idea

what about:

#!/bin/shset -eDOWN="$1"GROUP="yourwwwuser:yourwwwgroup"if [ -z "$1" ]; then  echo "usage: drupdown file"  exitfiwget $DOWNtar -zxf $(basename $DOWN)chown -R $GROUP $(echo $(basename $DOWN) | sed 's/-.*.gz//')rm $(basename $DOWN)echoecho "extracted in $(echo $(basename $DOWN) | sed 's/-.*.gz//')"echo
daniel g. siegel (not verified) | Jan 16th, 2008 at 3:33 am

or CVS?

To get a module from CVS is pretty easy once you understand how... Eg:

cvs -z4 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib co -d example -r DRUPAL-5--1-0 contributions/modules/example

The hardest thing I find about using CVS in this case is knowing the revision number to use, but once you now that then its much easier in the future to updgrade. Say you checkout DRUPAL-5 which is a dev branch then you can easily do cvs up -dP to checkout the latest version of that module without having to worry about getting the paths, etc again.

Nicholas Thompson (not verified) | Jan 16th, 2008 at 4:26 am

I use wget for downloading

I use wget for downloading from a shell. It's a great tool with features such as continuing a stopped transfer, read download urls from a file, recursive download, etc.

yaph (not verified) | Jan 16th, 2008 at 5:10 am

I prefer cvs and so I have

I prefer cvs and so I have something similar:

# !/bin/bash# dcvs# does a cvs checkout of the given contributed module/themeif [ $# -ne 3 ]then         echo 1>&2 Usage: dcvs modules/MODULE_NAME VERSION DIRECTORY_TO_PUT_IN         echo 1>&2 or___: dcvs themes/THEME_NAME VERSION DIRECTORY_TO_PUT_IN         exit 127ficvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d $3 -r $2 contributions/$1
dalin (not verified) | Jan 16th, 2008 at 5:32 am

What about drush?

I you haven't looked at it yet I highly reccomend it. Among other things it has a package manager that makes installing a module as easy as typing

drush pm install cck views panels

It looks up the latest stable version, and (it the -dev drush) can use your choice of cvs, wget or curl to download the package. It can also update any/all modules from the command line (again using the d.org update system backend). More features are on the way too!

http://drupal.org/project/drush

Grugnog (not verified) | Jan 16th, 2008 at 9:08 am

Drush is certainly on my list to check out

I just heard about Drush last week and it's on my list. Awesome to hear it has the package manager. I'll be moving it up the list of things to check out! (or given that I already have it checked out... ok no CVS humor)...

joshb | Jan 16th, 2008 at 11:20 am

see drush module

drush module does this, and about 50 more. please help make it better. it is the command line for drupal.

moshe weitzman (not verified) | Jan 16th, 2008 at 10:35 am

Delete directories

My understanding is that we should be deleting old directories first when upgrading modules.

I want a script that:

* iterates over all *.tar.gz files

** greps out the directory name

** deletes (or maybe backs up) the directory, if it exists

** untars the file

** deletes the tar file

Then I can just download all the modules I want to install or update, run the one script, and then do the update.php when appropriate.

here's a start:

for i in `ls *.tar.gz`; do  tar -zxf $idone
Ron Helwig (not verified) | Jan 16th, 2008 at 10:59 am

DRUpal SHell

Have you folks heard of drush? It includes a "package manager" for Drupal from the command line. The one disadvantage is that it needs a running Drupal site, but it's still the way to go I think.

benjamin, Agaric Design Collective

Benjamin Melançon (not verified) | Jan 16th, 2008 at 1:55 pm

Is there any way to rsync the module from drupal server?

I want to keep a local respository of drupal's module.
Can i rsync it from drupal's server?
So no need to download whole files? Just the updated files?

Best regards.

pipit (not verified) | Jan 16th, 2008 at 7:33 pm

CVS is what you want

CVS is what you want if you want to checkout files and then be able to update them as newer versions are released. CVS has many more capabilities but it can do what you're looking for rsync capability. There's a really pretty good handbook section on CVS at http://drupal.org/handbook/cvs.

joshb | Jan 16th, 2008 at 9:19 pm

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail]. Example: [amazon 1590597559 thumbnail]
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • You may insert videos with [video:URL]
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul><p> <img> <table> <tr> <td><strong><em><sup><div><fn><h1><h2><h3><h4><blockquote><img style="">
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically. (Better URL filter.)

More information about formatting options

 
 
 

Live from twitter...

  • @emaildiva Yes I've got it on a few sites that aren't yet public and it's a really well put together theme.
  • @emaildiva In looking for good Drupal themes might check out this recent post on Acquia Marina. Lots it can do. http://bit.ly/1rYxLH
  • @dancourse best Drupal book is relative to what you're trying to do....
  • It's funny that we can name boys with their father's names but for some reason Sarah Jr. doesn't get real consideration??