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/sh
if [ $# -ne 1 ]; then
echo 1>&2 Usage: dget URL
exit 127
fi
curl $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.
12 Comments
another idea
what about:
#!/bin/sh
set -e
DOWN="$1"
GROUP="yourwwwuser:yourwwwgroup"
if [ -z "$1" ]; then
echo "usage: drupdown file"
exit
fi
wget $DOWN
tar -zxf $(basename $DOWN)
chown -R $GROUP $(echo $(basename $DOWN) | sed 's/-.*.gz//')
rm $(basename $DOWN)
echo
echo "extracted in $(echo $(basename $DOWN) | sed 's/-.*.gz//')"
echo
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 docvs up -dP
to checkout the latest version of that module without having to worry about getting the paths, etc again.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.
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/theme
if [ $# -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 127
fi
cvs -z6 -d:pserver:anonymous:anonymous@cvs.drupal.org:/cvs/drupal-contrib checkout -d $3 -r $2 contributions/$1
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
see drush module
drush module does this, and about 50 more. please help make it better. it is the command line for drupal.
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 $i
done
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)...
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
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.
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.
Shell script with drush commands
Go to www.drupalmashup.interestsphere.com for the ability to automatically generate shell scripts to download a list of drupal modules via drush