A Bash Script for New projects

22nd August 2013 | Tags:

When­ever I start a new web project, the ini­tial steps are pretty much the same:

  • Cre­ate a new folder, in my case in /var/www
  • Change the own­er­ship of the new folder
  • Come up with a new host­name, e.g. myproject.local
  • Cre­ate an entry in etc/hosts
  • Cre­ate an Apache vir­tual host for it
  • Cre­ate a new database
  • Cre­ate a new Git repository
  • Intialise the Git repository
  • Cre­ate a new project in Sublime

Not par­tic­u­larly hard, but pretty repet­i­tive. And if something’s repet­i­tive, 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 pro­vided you check /​mod­ify things like the paths
  • Don’t for­get to set your MySQL /​Bit­bucket cre­den­tials at the top of the file
  • You’ll prob­a­bly need to use sudo to run this
  • The script asks for a “friendly” name, e.g. “My Awe­some Project”. It then gen­er­ates a slug, e.g. my-awesome-project. The host­name becomes my-awesome-project.local, the direc­tory gets named my-awesome-project, as does the Git repo, and the data­base ends up being called myawesomeproject. You can always mod­ify the script to alter this behaviour
  • You might want to expand the script to cre­ate a data­base user too, per­haps with a ran­dom password
  • It cre­ates a Git repos­i­tory using Bitbucket’s REST API. You may wish to alter the behav­iour — in which case con­sult the doc­u­men­ta­tion — or you might be able to add Github sup­port, which isn’t some­thing I tried.

Comments

No comments yet.

Links and images are allowed, but please note that rel="nofollow" will be automactically appended to any links.