You are here

script to update drupal core

this site runs on drupal. and drupal every so often will release a bug fix or security update. that means i will need to update my drupal core. i have been doing this for years using the script below. its fast, quick and automated. doesnt take more than a minute even.

it doesnt use drush, because the hosting provider has locked php down so, without further ado, the bash script!

#!/bin/sh

# updates drupal
# http://ftp.drupal.org/files/projects/$drupal_ver.tar.gz

#############################################
# user settings
webdir=~/www
#
#############################################

url=$1
targz=`echo $url | cut -d/ -f6`
drupal_ver=`echo $targz |cut -d. -f1,2`

if [ $# -eq 0 ]
then
        echo "  Usage: `basename $0` http://url/to/drupal.upgrade.tar.gz"
        exit 1
fi

if ! [ -d $webdir ]
then
        echo " ERROR! $webdir not found!"
        exit 69
fi

#lastest drupal vesion
cd ~/tmp
getfile.sh $url
tar -zxvf $targz

#pre-installation - prepare installation source
cp -r $webdir/sites/* ~/tmp/$drupal_ver/sites/.
cp $webdir/y_key* $drupal_ver/.
cp $webdir/google*.html $drupal_ver/.

#move directories for later deletion
cd $webdir
for directory in includes misc modules profiles scripts sites themes
do
  mv $directory $directory.bak
done

#the install
mv -f ~/tmp/$drupal_ver/* $webdir
mv ~/tmp/$drupal_ver/.htaccess $webdir/.

#clean up
cd $webdir
for directory in includes misc modules profiles scripts sites themes
do
  rm -rf $directory.bak
done

rm -rf ~/tmp/$targz