Clean up the add_repositories function

Raise errors if the repository templates don't exist. And make the
function a little bit preatier and easier to understand.

Fixes #18.
Merge pull request #21 from piojo/repository-fix

Clean up the add_repositories function