Update create_lxc.sh
This commit is contained in:
parent
98efb80292
commit
7a65e836cd
@ -106,42 +106,23 @@ function select_storage() {
|
|||||||
exit 221
|
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 MENU
|
||||||
local -A STORAGE_MAP=()
|
local -A STORAGE_MAP=()
|
||||||
local COL_WIDTH=0
|
local COL_WIDTH=0
|
||||||
|
|
||||||
while read -r TAG TYPE _ TOTAL USED FREE _; do
|
while read -r TAG TYPE _ TOTAL USED FREE _; do
|
||||||
[[ -n "$TAG" && -n "$TYPE" ]] || continue
|
[[ -n "$TAG" && -n "$TYPE" ]] || continue
|
||||||
[[ ! " ${VALID_STORAGES[*]} " =~ " $TAG " ]] && continue
|
|
||||||
|
|
||||||
local DISPLAY="${TAG} (${TYPE})"
|
local DISPLAY="${TAG} (${TYPE})"
|
||||||
local USED_FMT=$(numfmt --to=iec --from-unit=K --format %.1f <<<"$USED")
|
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 FREE_FMT=$(numfmt --to=iec --from-unit=K --format %.1f <<<"$FREE")
|
||||||
local INFO="Free: ${FREE_FMT}B Used: ${USED_FMT}B"
|
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")
|
MENU+=("$DISPLAY" "$INFO" "OFF")
|
||||||
((${#DISPLAY} > COL_WIDTH)) && COL_WIDTH=${#DISPLAY}
|
((${#DISPLAY} > COL_WIDTH)) && COL_WIDTH=${#DISPLAY}
|
||||||
done < <(pvesm status -content "$CONTENT" | awk 'NR>1')
|
done < <(pvesm status -content "$CONTENT" | awk 'NR>1')
|
||||||
|
|
||||||
if [ ${#MENU[@]} -eq 0 ]; then
|
if [ ${#MENU[@]} -eq 0 ]; then
|
||||||
msg_error "No storage found that supports '${CONTENT}'."
|
msg_error "No storage found for content type '$CONTENT'."
|
||||||
exit 203
|
exit 203
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -259,18 +240,12 @@ if ! pveam list "$TEMPLATE_STORAGE" | grep -q "$TEMPLATE" || ! zstdcat "$TEMPLAT
|
|||||||
for attempt in {1..3}; do
|
for attempt in {1..3}; do
|
||||||
msg_info "Attempt $attempt: Downloading LXC template..."
|
msg_info "Attempt $attempt: Downloading LXC template..."
|
||||||
|
|
||||||
if command -v timeout >/dev/null; then
|
if timeout 120 pveam download "$TEMPLATE_STORAGE" "$TEMPLATE" >/dev/null 2>&1; 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
|
|
||||||
msg_ok "Template download successful."
|
msg_ok "Template download successful."
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ $attempt -eq 3 ]]; then
|
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 your Proxmox host’s internet access or manually run:\n pveam download $TEMPLATE_STORAGE $TEMPLATE"
|
||||||
exit 208
|
exit 208
|
||||||
fi
|
fi
|
||||||
|
Loading…
x
Reference in New Issue
Block a user