better msg's

This commit is contained in:
CanbiZ 2025-08-19 13:39:25 +02:00
parent 2587aa4145
commit b9c7b658e5

View File

@ -205,39 +205,35 @@ if qm status "$CTID" &>/dev/null || pct status "$CTID" &>/dev/null; then
fi fi
# This checks for the presence of valid Container Storage and Template Storage locations # This checks for the presence of valid Container Storage and Template Storage locations
msg_info "Validating Storage" msg_info "Validating storage"
if ! check_storage_support "rootdir"; then if ! check_storage_support "rootdir"; then
msg_error "No valid storage found for 'rootdir' (Container)." msg_error "No valid storage found for 'rootdir' [Container]"
msg_debug "check_storage_support('rootdir') → success"
exit 1 exit 1
fi fi
if ! check_storage_support "vztmpl"; then if ! check_storage_support "vztmpl"; then
msg_error "No valid storage found for 'vztmpl' (Template)." msg_error "No valid storage found for 'vztmpl' [Template]"
msg_debug "check_storage_support('vztmpl') → success"
exit 1 exit 1
fi fi
msg_ok "Valid Storage Found"
msg_info "Checking template storage"
while true; do while true; do
if select_storage template; then if select_storage template; then
TEMPLATE_STORAGE="$STORAGE_RESULT" TEMPLATE_STORAGE="$STORAGE_RESULT"
TEMPLATE_STORAGE_INFO="$STORAGE_INFO" TEMPLATE_STORAGE_INFO="$STORAGE_INFO"
msg_debug "TEMPLATE_STORAGE=$TEMPLATE_STORAGE" msg_ok "Storage ${BL}$TEMPLATE_STORAGE${CL} ($TEMPLATE_STORAGE_INFO) [Template]"
msg_debug "TEMPLATE_STORAGE_INFO=$TEMPLATE_STORAGE_INFO"
break break
fi fi
done done
msg_info "Checking container storage"
while true; do while true; do
if select_storage container; then if select_storage container; then
CONTAINER_STORAGE="$STORAGE_RESULT" CONTAINER_STORAGE="$STORAGE_RESULT"
CONTAINER_STORAGE_INFO="$STORAGE_INFO" CONTAINER_STORAGE_INFO="$STORAGE_INFO"
msg_debug "CONTAINER_STORAGE=$CONTAINER_STORAGE" msg_ok "Storage ${BL}$CONTAINER_STORAGE${CL} ($CONTAINER_STORAGE_INFO) [Container]"
msg_debug "CONTAINER_STORAGE_INFO=$CONTAINER_STORAGE_INFO"
break break
fi fi
done done
msg_ok "Validated Storage | Container: ${BL}$CONTAINER_STORAGE${CL} ($CONTAINER_STORAGE_INFO)"
# Check free space on selected container storage # Check free space on selected container storage
STORAGE_FREE=$(pvesm status | awk -v s="$CONTAINER_STORAGE" '$1 == s { print $6 }') STORAGE_FREE=$(pvesm status | awk -v s="$CONTAINER_STORAGE" '$1 == s { print $6 }')
@ -246,11 +242,11 @@ if [ "$STORAGE_FREE" -lt "$REQUIRED_KB" ]; then
msg_error "Not enough space on '$CONTAINER_STORAGE'. Needed: ${PCT_DISK_SIZE:-8}G." msg_error "Not enough space on '$CONTAINER_STORAGE'. Needed: ${PCT_DISK_SIZE:-8}G."
exit 214 exit 214
fi fi
# Check Cluster Quorum if in Cluster # Check Cluster Quorum if in Cluster
if [ -f /etc/pve/corosync.conf ]; then if [ -f /etc/pve/corosync.conf ]; then
msg_info "Checking Proxmox cluster quorum status" msg_info "Checking cluster quorum"
if ! pvecm status | awk -F':' '/^Quorate/ { exit ($2 ~ /Yes/) ? 0 : 1 }'; then if ! pvecm status | awk -F':' '/^Quorate/ { exit ($2 ~ /Yes/) ? 0 : 1 }'; then
printf "\e[?25h"
msg_error "Cluster is not quorate. Start all nodes or configure quorum device (QDevice)." msg_error "Cluster is not quorate. Start all nodes or configure quorum device (QDevice)."
exit 210 exit 210
fi fi
@ -261,31 +257,28 @@ fi
TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}" TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}"
# 1. Check local templates first # 1. Check local templates first
msg_info "Checking for local template for '$TEMPLATE_SEARCH'..." msg_info "Searching for template '$TEMPLATE_SEARCH'"
mapfile -t TEMPLATES < <( mapfile -t TEMPLATES < <(
pveam list "$TEMPLATE_STORAGE" | awk -v s="$TEMPLATE_SEARCH" '$1 ~ s {print $1}' | sed 's/.*\///' | sort -t - -k 2 -V pveam list "$TEMPLATE_STORAGE" | awk -v s="$TEMPLATE_SEARCH" '$1 ~ s {print $1}' |
sed 's/.*\///' | sort -t - -k 2 -V
) )
if [ ${#TEMPLATES[@]} -gt 0 ]; then if [ ${#TEMPLATES[@]} -gt 0 ]; then
msg_ok "Found local template." TEMPLATE_SOURCE="local"
else else
# 2. If no local match, try online msg_info "No local template found, checking online repository"
msg_info "No local template found. Searching online..." pveam update >/dev/null 2>&1
mapfile -t TEMPLATES < <( mapfile -t TEMPLATES < <(
pveam update >/dev/null 2>&1 && pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" |
pveam available -section system | sed -n "s/.*\($TEMPLATE_SEARCH.*\)/\1/p" | sort -t - -k 2 -V sort -t - -k 2 -V
) )
TEMPLATE_SOURCE="online"
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 online template."
fi fi
# 3. Use the newest 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_ok "Template ${BL}$TEMPLATE${CL} [$TEMPLATE_SOURCE]"
msg_debug "TEMPLATE_SEARCH=$TEMPLATE_SEARCH" msg_debug "TEMPLATE_SEARCH=$TEMPLATE_SEARCH"
msg_debug "TEMPLATES=(${TEMPLATES[*]})" msg_debug "TEMPLATES=(${TEMPLATES[*]})"