Update create_lxc.sh

This commit is contained in:
CanbiZ 2025-07-01 13:24:52 +02:00
parent 98efb80292
commit 7a65e836cd

View File

@ -106,42 +106,23 @@ function select_storage() {
exit 221
}
# Gather valid storages from /etc/pve/storage.cfg
local -a VALID_STORAGES=()
local CURRENT_STORAGE=""
while read -r LINE; do
if [[ "$LINE" =~ ^(dir|lvm|lvmthin|zfspool|.*):[[:space:]]*(.+)$ ]]; then
CURRENT_STORAGE="${BASH_REMATCH[2]}"
elif [[ "$LINE" =~ ^[[:space:]]*content[[:space:]]*=[[:space:]]*(.+)$ ]]; then
local CONTENTS="${BASH_REMATCH[1]}"
[[ ",${CONTENTS}," =~ ,$CONTENT, ]] && VALID_STORAGES+=("$CURRENT_STORAGE")
fi
done </etc/pve/storage.cfg
if [[ "$CONTENT" == "vztmpl" && ${#VALID_STORAGES[@]} -eq 0 ]]; then
msg_error "No storage found that supports Container Templates (vztmpl). Please enable 'vztmpl' in Storage Settings."
exit 250
fi
local -a MENU
local -A STORAGE_MAP=()
local COL_WIDTH=0
while read -r TAG TYPE _ TOTAL USED FREE _; do
[[ -n "$TAG" && -n "$TYPE" ]] || continue
[[ ! " ${VALID_STORAGES[*]} " =~ " $TAG " ]] && continue
local DISPLAY="${TAG} (${TYPE})"
local USED_FMT=$(numfmt --to=iec --from-unit=K --format %.1f <<<"$USED")
local FREE_FMT=$(numfmt --to=iec --from-unit=K --format %.1f <<<"$FREE")
local INFO="Free: ${FREE_FMT}B Used: ${USED_FMT}B"
STORAGE_MAP["$DISPLAY"]="$TAG"
STORAGE_MAP["$DISPLAY"]="$TAG" # Map DISPLAY to actual TAG
MENU+=("$DISPLAY" "$INFO" "OFF")
((${#DISPLAY} > COL_WIDTH)) && COL_WIDTH=${#DISPLAY}
done < <(pvesm status -content "$CONTENT" | awk 'NR>1')
if [ ${#MENU[@]} -eq 0 ]; then
msg_error "No storage found that supports '${CONTENT}'."
msg_error "No storage found for content type '$CONTENT'."
exit 203
fi
@ -259,18 +240,12 @@ if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE" || ! zstdcat "$TEMPLAT
for attempt in {1..3}; do
msg_info "Attempt $attempt: Downloading LXC template..."
if command -v timeout >/dev/null; then
timeout --foreground 120 pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1
else
pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1
fi
if [[ $? -eq 0 ]]; then
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
if [ $attempt -eq 3 ]; then
msg_error "Failed after 3 attempts. Please check your Proxmox hosts internet access or manually run:\n pveam download $TEMPLATE_STORAGE $TEMPLATE"
exit 208
fi