A Bash Script for New projects

22nd August 2013

Whenever I start a new web project, the initial steps are pretty much the same:

  • Create a new folder, in my case in /var/www
  • Change the ownership of the new folder
  • Come up with a new hostname, e.g. myproject.local
  • Create an entry in etc/hosts
  • Create an Apache virtual host for it
  • Create a new database
  • Create a new Git repository
  • Intialise the Git repository
  • Create a new project in Sublime

Not particularly hard, but pretty repetitive. And if something's repetitive, chances are it can be scripted!

So here's what I came up with:

A few notes:

  • This script is designed for a Mac, but it should work on any OS provided you check / modify things like the paths
  • Don't forget to set your MySQL / Bitbucket credentials at the top of the file
  • You'll probably need to use sudo to run this
  • The script asks for a "friendly" name, e.g. "My Awesome Project". It then generates a slug, e.g. my-awesome-project. The hostname becomes my-awesome-project.local, the directory gets named my-awesome-project, as does the Git repo, and the database ends up being called myawesomeproject. You can always modify the script to alter this behaviour
  • You might want to expand the script to create a database user too, perhaps with a random password
  • It creates a Git repository using Bitbucket's REST API. You may wish to alter the behaviour - in which case consult the documentation - or you might be able to add Github support, which isn't something I tried.