Refactor .travis/install.sh.

Fixes #1439.

Probably a few more bits that can be refactored but it's a start.