Last week I created a new theme for my blog, and for the first time I've put it under source control using git. (My site has been in need of some TLC for a while...)

To really bring my personal site project up to date what I would like to do is set up automated deployments using Capistrano or something similar, and get as close to a Continuous Integration workflow as I can here at home.

There's a basic problem in my way, however. This blog is hosted on a really budget package from a really terrible hosting provider, on a shared virtual box somewhere. One of the hallmarks of this kind of hosting package is that you can't get SSH access to your server, because it's a security risk for the provider. (I bought the package back in 2007, when I was just learning to code, and manually FTP-ing files was the only way I knew to get them online.) No SSH means no Capistrano. Sad face.

I know that if I really cared about having command line access to my web server I'd switch hosting providers. But that's a pain and takes ages, so I decided to see if I could get something approximate to a Capistrano deploy script with my current, locked-down, solution.

It turns out that I can*, because although SSH access is prevented, it is possible to get a command-line FTP connection going. So I put together the following bash script to save me messing around with my FTP client.

# Move to local copy of Master files, check out master branch from github
cd /path/to/my/local/theme/
git checkout master
git pull

# Copy master files to a deploy directory and clean up (remove git files)
cd ../
rm -r -f THEME_NAME.deploy/.git*

# Get timestamp
NOW=$(date +"%Y%m%d-%k%M%S")

# NCFTP connect to host, upload .deploy package, 
# move current theme into backup, rename deploy package for live
cd path/to/themes/on/server
mput -R THEME_NAME.deploy

# Cleanup
rm -r -f THEME_NAME.deploy

It works like this:

The script pulls the latest version of  the :master branch from my public github account, creates a deployment package and strips out the files I don't need. Then it FTPs the deployment package up to the web server. Once that's done I move the current wordpress theme into a backup folder (so I can roll things back if they break) and finally change the name of the deployment package to the correct theme name.

Obviously Capistrano uses symlinking rather than actual directory renaming, but this is a reasonable facsimile using pretty standard FTP commands. (I'm actually using the NCFTP library rather than standard *nix FTP, because recursively uploading directories isn't possible with the standard 'mput' and I can't just tar everything up before I send it because you can't extract the tar files on the other side without SSH access!)

It's clearly a rough solution, but it does allow me to push changes from my local development version of the site up to the live one with a single terminal command, and that's pretty cool.

*sort of