Update create_lxc.sh

This commit is contained in:
CanbiZ 2025-08-26 12:32:08 +02:00
parent b0c3978bbf
commit 0b54c653f8

View File

@ -331,6 +331,7 @@ fi
msg_ok "Template ${BL}$TEMPLATE${CL} [$TEMPLATE_SOURCE]" msg_ok "Template ${BL}$TEMPLATE${CL} [$TEMPLATE_SOURCE]"
msg_debug "Resolved TEMPLATE_PATH=$TEMPLATE_PATH" msg_debug "Resolved TEMPLATE_PATH=$TEMPLATE_PATH"
# 5. Validation
# 5. Validation # 5. Validation
NEED_DOWNLOAD=0 NEED_DOWNLOAD=0
if [[ ! -f "$TEMPLATE_PATH" ]]; then if [[ ! -f "$TEMPLATE_PATH" ]]; then
@ -340,11 +341,19 @@ elif [[ ! -r "$TEMPLATE_PATH" ]]; then
msg_error "Template file exists but is not readable check permissions." msg_error "Template file exists but is not readable check permissions."
exit 221 exit 221
elif [[ "$(stat -c%s "$TEMPLATE_PATH")" -lt 1000000 ]]; then elif [[ "$(stat -c%s "$TEMPLATE_PATH")" -lt 1000000 ]]; then
msg_warn "Template file too small (<1MB) re-downloading." if [[ -n "$ONLINE_TEMPLATE" ]]; then
NEED_DOWNLOAD=1 msg_warn "Template file too small (<1MB) re-downloading."
elif ! zstdcat "$TEMPLATE_PATH" | tar -tf - &>/dev/null; then NEED_DOWNLOAD=1
msg_warn "Template appears corrupted re-downloading." else
NEED_DOWNLOAD=1 msg_warn "Template looks too small, but no online version exists. Keeping local file."
fi
elif ! tar -tf "$TEMPLATE_PATH" &>/dev/null; then
if [[ -n "$ONLINE_TEMPLATE" ]]; then
msg_warn "Template appears corrupted re-downloading."
NEED_DOWNLOAD=1
else
msg_warn "Template appears corrupted, but no online version exists. Keeping local file."
fi
else else
msg_ok "Template $TEMPLATE is present and valid." msg_ok "Template $TEMPLATE is present and valid."
fi fi
@ -422,10 +431,14 @@ if ! pct create "$CTID" "${TEMPLATE_STORAGE}:vztmpl/${TEMPLATE}" "${PCT_OPTIONS[
msg_warn "Template file too small or missing re-downloading." msg_warn "Template file too small or missing re-downloading."
rm -f "$TEMPLATE_PATH" rm -f "$TEMPLATE_PATH"
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" pveam download "$TEMPLATE_STORAGE" "$TEMPLATE"
elif ! zstdcat "$TEMPLATE_PATH" | tar -tf - &>/dev/null; then elif ! tar -tf "$TEMPLATE_PATH" &>/dev/null; then
msg_warn "Template appears corrupted re-downloading." if [[ -n "$ONLINE_TEMPLATE" ]]; then
rm -f "$TEMPLATE_PATH" msg_warn "Template appears corrupted re-downloading."
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" rm -f "$TEMPLATE_PATH"
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE"
else
msg_warn "Template appears corrupted, but no online version exists. Skipping re-download."
fi
fi fi
# Retry after repair # Retry after repair