Enhance build-cloudinit-image.sh with improved error handling for decompression: add checks for xz installation, validate downloaded file type, and capture detailed error messages during decompression failures. Update deploy-to-proxmox.sh to restart cm4-dashboard service after enabling it, ensuring new code is loaded.
This commit is contained in:
@@ -66,8 +66,27 @@ if ! curl "${CURL_OPTS[@]}" "$URL" 2>"$CURL_ERR"; then
|
||||
fi
|
||||
|
||||
write_status "decompressing" "Decompressing image…" "" ""
|
||||
# Check we have a real xz file (not HTML error page)
|
||||
if ! command -v xz >/dev/null 2>&1; then
|
||||
write_status "error" "" "" "Decompress failed: xz not installed. Install xz-utils (apt install xz-utils)"
|
||||
exit 1
|
||||
fi
|
||||
if [[ ! -s "$XZ_FILE" ]]; then
|
||||
write_status "error" "" "" "Decompress failed: downloaded file is empty"
|
||||
exit 1
|
||||
fi
|
||||
FILE_TYPE=$(file -b "$XZ_FILE" 2>/dev/null || true)
|
||||
if [[ "$FILE_TYPE" == *"HTML"* ]] || [[ "$FILE_TYPE" == *"text"* ]] && [[ "$FILE_TYPE" != *"XZ"* ]]; then
|
||||
write_status "error" "" "" "Decompress failed: download is not an image (got: ${FILE_TYPE:0:80})"
|
||||
exit 1
|
||||
fi
|
||||
IMG_FILE="$TEMP_DIR/image.img"
|
||||
xz -d -k -f "$XZ_FILE" || { write_status "error" "" "" "Decompress failed"; exit 1; }
|
||||
XZ_ERR="$TEMP_DIR/xz_err.txt"
|
||||
if ! xz -d -k -f "$XZ_FILE" 2>"$XZ_ERR"; then
|
||||
err_detail=$(head -c 300 "$XZ_ERR" 2>/dev/null | tr '\n' ' ' | sed 's/"/\\"/g')
|
||||
write_status "error" "" "" "Decompress failed: ${err_detail:-xz exited with error}"
|
||||
exit 1
|
||||
fi
|
||||
[[ -f "$IMG_FILE" ]] || { write_status "error" "" "" "image.img not found after decompress"; exit 1; }
|
||||
|
||||
write_status "injecting" "Mounting boot partition and injecting cloud-init…" "" ""
|
||||
|
||||
Reference in New Issue
Block a user