Tuesday, May 24, 2011

Batch module replace in Drupal

Every so often I update a Drupal site and need to update a bunch of modules/themes at the same time. Fortunately, the naming convention of modules/themes is consistent so I can update many with one little script.
First, scp all the module/theme gz files to the location you want to store them. Next, cd into that directory. Last, run this script:

for thm in $(ls *.gz)
do
        thmnew=$(ls ${thm}|cut -d'-' -f1)
        tar -cf ${thmnew}_old.tar ${thmnew}
        mv ${thmnew}_old.tar /usr/local/src/drupal/tmp/themesupgraded/
        mv ${thmnew} /usr/local/src/drupal/tmp/themesupgraded/
        tar -zxvf ${thm}
        mv ${thm} /usr/local/src/drupal/tmp/themesupgraded/
done