build.sh: Correct check_port_free path and order of checks