Pulling logic from .travis.yml into scripts.

Fixes #1009.