travis-ci: refactor and add .travis-functions.sh

This commit squashes a lot changes because we don't want to pollute
history with this meta CI stuff.

I've written a long pamphlet into the commit message mainly to be clear about my personal focus. I can remove it from if you don't like it.