Updating WordPress on nearlyfreespeech.net hosts

Update Dec. 13, 2014:

These scripts are out of date. NFS has the WP-CLI installed allowing for much, much easier upgrades, backups, etc. See the repository for information.

Originally posted on Sept. 10th, 2014:

If you use NearlyFreeSpeech.net as your web host, you may have found it difficult to automate WordPress updates. I’ve made a script that does this for you. It also calls my backup and permissions fixing scripts, which I include here as well.

Beware of some notes and assumptions though:

  • Assumes WordPress is installed in /home/public/ (not a subdir of it)
  • Scripts are assumed to be in /home/private/
  • Does not check or recover from errors
cd
echo "Backing up..."
./backup.sh > /dev/null
cd /home/public
if [ -f latest.tar.gz ]
then
echo "File already exists."
else
echo "Downloading..."
wget https://wordpress.org/latest.tar.gz > /dev/null
echo "Extracting..."
tar xf latest.tar.gz --strip-components 1
#TODO check if successful
echo "Cleanup..."
rm latest.tar.gz
cd /home/private
echo "Fixing perms..."
./fixgrp.sh
echo "Complete.";
fi

Here’s my backup script. It’s super simple. Tar everything in /home/public up with a datetime as the filename. Database backups are a separate script I’m working on.

theDate=`date "+%Y-%m-%d"`
fileName=backup-$theDate.tar.bz2
if [ -f $fileName ]
then
echo "Backup file \"$fileName\" already exists. Exit.";
else
tar -cjvf $fileName /home/public
echo "Backup complete."
fi

And here’s my permissions fixing script. The WordPress tarball has the wrong group on all the files, since NFS uses the ‘web’ group. There’s probably a way to do this with tar when it extracts but this is simple enough:

chgrp -R web /home/public/*