diff --git a/misc/create_lxc.sh b/misc/create_lxc.sh index 02fad359..62fa9848 100644 --- a/misc/create_lxc.sh +++ b/misc/create_lxc.sh @@ -273,24 +273,28 @@ fi TEMPLATE="${TEMPLATES[-1]}" TEMPLATE_PATH="$(pvesm path $TEMPLATE_STORAGE:vztmpl/$TEMPLATE 2>/dev/null || echo "/var/lib/vz/template/cache/$TEMPLATE")" -# Check if template exists and is valid -if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE" || ! (zstdcat "$TEMPLATE_PATH" | tar -tf - >/dev/null 2>&1); then - msg_warn "Template $TEMPLATE not found or appears to be corrupted. Re-downloading." +TEMPLATE_VALID=1 +if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE"; then + TEMPLATE_VALID=0 +elif [ ! -s "$TEMPLATE_PATH" ]; then + TEMPLATE_VALID=0 +elif ! tar --use-compress-program=zstdcat -tf "$TEMPLATE_PATH" >/dev/null 2>&1; then + TEMPLATE_VALID=0 +fi +if [ "$TEMPLATE_VALID" -eq 0 ]; then + msg_warn "Template $TEMPLATE not found or appears to be corrupted. Re-downloading." [[ -f "$TEMPLATE_PATH" ]] && rm -f "$TEMPLATE_PATH" for attempt in {1..3}; do msg_info "Attempt $attempt: Downloading LXC template..." - if timeout 120 pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1; then msg_ok "Template download successful." break fi - if [ $attempt -eq 3 ]; then - msg_error "Failed after 3 attempts. Please check your Proxmox host’s internet access or manually run:\n pveam download $TEMPLATE_STORAGE $TEMPLATE" + msg_error "Failed after 3 attempts. Please check network access or manually run:\n pveam download $TEMPLATE_STORAGE $TEMPLATE" exit 208 fi - sleep $((attempt * 5)) done fi