Move long commands and multiline text into heredocs

Uses `sort` to perform version comparisons.
Move client setup to before_script