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:
parent
a942afc52c
commit
90babd1df3
1 changed files with 15 additions and 8 deletions
23
install.sh
23
install.sh
|
|
@ -101,23 +101,30 @@ download() {
|
||||||
local tmpfile
|
local tmpfile
|
||||||
tmpfile="$(mktemp)"
|
tmpfile="$(mktemp)"
|
||||||
|
|
||||||
|
local http_code
|
||||||
if [[ "${DOWNLOADER}" == curl* ]]; then
|
if [[ "${DOWNLOADER}" == curl* ]]; then
|
||||||
curl -sSL "${src_url}" -o "${tmpfile}"
|
http_code=$(curl -sSL -o "${tmpfile}" -w "%{http_code}" "${src_url}")
|
||||||
else
|
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
|
fi
|
||||||
|
|
||||||
# Check that the downloaded content is non-empty and not an HTML error page
|
# Check HTTP status code (curl: exact; wget: best-effort via content)
|
||||||
if [[ ! -s "${tmpfile}" ]]; then
|
if [[ "${DOWNLOADER}" == curl* ]] && [[ "${http_code}" != "200" ]]; then
|
||||||
rm -f "${tmpfile}"
|
rm -f "${tmpfile}"
|
||||||
error "Downloaded empty file from ${src_url}"
|
error "Server returned HTTP ${http_code} for ${src_url}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Gitea returns HTML on 404; detect by checking first bytes
|
# Check that the downloaded content is non-empty
|
||||||
if head -c 100 "${tmpfile}" | grep -qi "<html\|<!DOCTYPE"; then
|
if [[ ! -s "${tmpfile}" ]]; then
|
||||||
rm -f "${tmpfile}"
|
rm -f "${tmpfile}"
|
||||||
error "File not found at ${src_url}"
|
error "Downloaded empty file from ${src_url}"
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue