fetch local templates
This commit is contained in:
parent
b342474da8
commit
3fd51d7a40
@ -258,34 +258,38 @@ fi
|
|||||||
# Update LXC template list
|
# Update LXC template list
|
||||||
TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}"
|
TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}"
|
||||||
|
|
||||||
msg_info "Updating LXC Template List"
|
msg_info "Searching for online LXC template for '$TEMPLATE_SEARCH'..."
|
||||||
if ! pveam update >/dev/null 2>&1; then
|
mapfile -t TEMPLATES < <(
|
||||||
TEMPLATE_FALLBACK=$(pveam list "$TEMPLATE_STORAGE" | awk "/$TEMPLATE_SEARCH/ {print \$2}" | sort -t - -k 2 -V | tail -n1)
|
pveam update >/dev/null 2>&1 &&
|
||||||
if [[ -z "$TEMPLATE_FALLBACK" ]]; then
|
pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V
|
||||||
msg_error "Failed to update LXC template list and no local template matching '$TEMPLATE_SEARCH' found."
|
)
|
||||||
exit 201
|
|
||||||
fi
|
|
||||||
msg_info "Skipping template update – using local fallback: $TEMPLATE_FALLBACK"
|
|
||||||
else
|
|
||||||
msg_ok "LXC Template List Updated"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# Get LXC template string
|
|
||||||
TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}"
|
|
||||||
mapfile -t TEMPLATES < <(pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V)
|
|
||||||
|
|
||||||
|
# If nothing found online, search local templates
|
||||||
if [ ${#TEMPLATES[@]} -eq 0 ]; then
|
if [ ${#TEMPLATES[@]} -eq 0 ]; then
|
||||||
msg_error "No matching LXC template found for '${TEMPLATE_SEARCH}'. Make sure your host can reach the Proxmox template repository."
|
msg_info "Online search failed or no template found. Checking for local fallbacks..."
|
||||||
exit 207
|
mapfile -t TEMPLATES < <(
|
||||||
|
pveam list "$TEMPLATE_STORAGE" | awk "/$TEMPLATE_SEARCH/ {print \$2}" | sort -t - -k 2 -V
|
||||||
|
)
|
||||||
|
|
||||||
|
if [ ${#TEMPLATES[@]} -eq 0 ]; then
|
||||||
|
msg_error "No online or local LXC template found for '${TEMPLATE_SEARCH}'. Please check network or install a template manually."
|
||||||
|
exit 207
|
||||||
|
fi
|
||||||
|
msg_ok "Found local fallback template."
|
||||||
|
else
|
||||||
|
msg_ok "Found online template."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Use the newest available template (last in sorted list)
|
||||||
TEMPLATE="${TEMPLATES[-1]}"
|
TEMPLATE="${TEMPLATES[-1]}"
|
||||||
TEMPLATE_PATH="$(pvesm path $TEMPLATE_STORAGE:vztmpl/$TEMPLATE 2>/dev/null || echo "/var/lib/vz/template/cache/$TEMPLATE")"
|
TEMPLATE_PATH="$(pvesm path $TEMPLATE_STORAGE:vztmpl/$TEMPLATE 2>/dev/null || echo "/var/lib/vz/template/cache/$TEMPLATE")"
|
||||||
|
|
||||||
msg_debug "TEMPLATE_SEARCH=$TEMPLATE_SEARCH"
|
msg_debug "TEMPLATE_SEARCH=$TEMPLATE_SEARCH"
|
||||||
msg_debug "TEMPLATES=(${TEMPLATES[*]})"
|
msg_debug "TEMPLATES=(${TEMPLATES[*]})"
|
||||||
msg_debug "Selected TEMPLATE=$TEMPLATE"
|
msg_debug "Selected TEMPLATE=$TEMPLATE"
|
||||||
msg_debug "TEMPLATE_PATH=$TEMPLATE_PATH"
|
msg_debug "TEMPLATE_PATH=$TEMPLATE_PATH"
|
||||||
|
|
||||||
|
# Validate that template file exists and is not corrupted
|
||||||
TEMPLATE_VALID=1
|
TEMPLATE_VALID=1
|
||||||
if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE"; then
|
if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE"; then
|
||||||
TEMPLATE_VALID=0
|
TEMPLATE_VALID=0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user