build.sh: Use functions to make the logical flow more obvious

Also log important actions to stdout so you can monitor what's
happening.