Installing configuration files in an automated way

Recently when I installed Snow Leopard I got smarter about configuring my command line tools. What I mean by this is that I actually went through and configured Zsh and Vim (among other things). However, these days I use a lot of different computers; from my laptop to virtual machines to servers. I didn’t want to have to manually reconfigure my development environment every time I was using a new computer. So, I wrote a script to do it!

First thing I did was create a Git repository with my configuration files. I don’t have any sensitive information in there, so I threw it up on GitHub.

Then, I proceeded to make an install script that is much more complicated than I would like. Basically, I had certain requirements:

  1. Before overwriting existing files, back them up. I chose to back them up to a ‘trash’ folder (on Mac OS I use the system trash folder. On Linux I create ~/trash). This is outsourced to a trash script in the bin directory.
  2. The installer script should only touch/remove files it is replacing. Therefore, I needed to recursively move the files over and didn’t just blindly copy directories over.
  3. Be able to have specific configurations for Linux or Mac operating systems. I specify this by appending either [linux] or [mac] to the file name.
  4. The .gitconfig file should properly set the excludesfile setting for Git. Git won’t expand the path if it has a ~ in it. So, when actually copying over the configuration files, I run them through sed and replace all instances of [[HOME]] with whatever my home directory is. This is applied to all my configuration files, just in case any one of them needs this functionallity, but currently .gitconfig is the only file that uses it.
  5. Maintain the permisions of the files. A simple chmod did the trick.

The one last thing I did was that I wanted to be able to have different colored prompts for different computers. But since my installer.rb script blindly moves the files over, I had to store the color information elsewhere. The script works like so:

Now, on each computer/virtual machine/server I use I can checkout my config-files repository and run the install script. And Violà! I have the set up I am used to, instantly!