build.sh: Pull repo_exists out into a helper function