Detect failed downloads more accurately

Add curl's --fail flag to the default DOWNLOAD_COMMAND and use its
return code to detect failure or success.
Prefer parameter expansion over basename/dirname