not sure how useful this is to you but,

heres the script I used to do it
https://gist.github.com/1056f8401918ee54c310

I actually use that script in a bootstrap template too if you can believe it..
could work in a bash_block too

I guess if you're actually interested in this I can contribute some more work.