diff --git a/install.sh b/install.sh index 0dc02b9..c9a6e89 100755 --- a/install.sh +++ b/install.sh @@ -101,23 +101,30 @@ download() { local tmpfile tmpfile="$(mktemp)" + local http_code if [[ "${DOWNLOADER}" == curl* ]]; then - curl -sSL "${src_url}" -o "${tmpfile}" + http_code=$(curl -sSL -o "${tmpfile}" -w "%{http_code}" "${src_url}") else - wget -q -O "${tmpfile}" "${src_url}" + wget -q -O "${tmpfile}" "${src_url}" || { + rm -f "${tmpfile}" + error "Failed to download from ${src_url}" + return 1 + } + # wget doesn't expose the HTTP code; assume success if no error + http_code="200" fi - # Check that the downloaded content is non-empty and not an HTML error page - if [[ ! -s "${tmpfile}" ]]; then + # Check HTTP status code (curl: exact; wget: best-effort via content) + if [[ "${DOWNLOADER}" == curl* ]] && [[ "${http_code}" != "200" ]]; then rm -f "${tmpfile}" - error "Downloaded empty file from ${src_url}" + error "Server returned HTTP ${http_code} for ${src_url}" return 1 fi - # Gitea returns HTML on 404; detect by checking first bytes - if head -c 100 "${tmpfile}" | grep -qi "