install.sh: fix download() to check HTTP status instead of content — template files contain <!DOCTYPE>

- Replace fragile head -c 100 | grep content check with curl -w
  '%{http_code}' for accurate HTTP status detection
- The old check incorrectly rejected legitimate HTML template files
  (base.html starts with <!DOCTYPE html>)
- wget fallback uses its exit code instead (no content scanning)
This commit is contained in:
Claus Lohmar 2026-04-23 21:02:21 +00:00
parent a942afc52c
commit 90babd1df3

View file

@ -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 "<html\|<!DOCTYPE"; then
# Check that the downloaded content is non-empty
if [[ ! -s "${tmpfile}" ]]; then
rm -f "${tmpfile}"
error "File not found at ${src_url}"
error "Downloaded empty file from ${src_url}"
return 1
fi