mirror of
https://github.com/community-scripts/ProxmoxVE.git
synced 2026-04-23 10:50:41 +00:00
core: allow empty tags & improve template search (#11020)
This commit is contained in:
committed by
GitHub
parent
0c9653c7cb
commit
88557d53f4
+29
-20
@@ -3442,8 +3442,13 @@ build_container() {
|
|||||||
export DEV_MODE_DRYRUN="${DEV_MODE_DRYRUN:-false}"
|
export DEV_MODE_DRYRUN="${DEV_MODE_DRYRUN:-false}"
|
||||||
|
|
||||||
# Build PCT_OPTIONS as multi-line string
|
# Build PCT_OPTIONS as multi-line string
|
||||||
PCT_OPTIONS_STRING=" -hostname $HN
|
PCT_OPTIONS_STRING=" -hostname $HN"
|
||||||
|
|
||||||
|
# Only add -tags if TAGS is not empty
|
||||||
|
if [ -n "$TAGS" ]; then
|
||||||
|
PCT_OPTIONS_STRING="$PCT_OPTIONS_STRING
|
||||||
-tags $TAGS"
|
-tags $TAGS"
|
||||||
|
fi
|
||||||
|
|
||||||
# Only add -features if FEATURES is not empty
|
# Only add -features if FEATURES is not empty
|
||||||
if [ -n "$FEATURES" ]; then
|
if [ -n "$FEATURES" ]; then
|
||||||
@@ -4473,37 +4478,41 @@ create_lxc_container() {
|
|||||||
|
|
||||||
msg_info "Searching for template '$TEMPLATE_SEARCH'"
|
msg_info "Searching for template '$TEMPLATE_SEARCH'"
|
||||||
|
|
||||||
|
# Step 1: Check local templates first (instant)
|
||||||
mapfile -t LOCAL_TEMPLATES < <(
|
mapfile -t LOCAL_TEMPLATES < <(
|
||||||
pveam list "$TEMPLATE_STORAGE" 2>/dev/null |
|
pveam list "$TEMPLATE_STORAGE" 2>/dev/null |
|
||||||
awk -v search="${TEMPLATE_SEARCH}" -v pattern="${TEMPLATE_PATTERN}" '$1 ~ search && $1 ~ pattern {print $1}' |
|
awk -v search="${TEMPLATE_SEARCH}" -v pattern="${TEMPLATE_PATTERN}" '$1 ~ search && $1 ~ pattern {print $1}' |
|
||||||
sed 's|.*/||' | sort -t - -k 2 -V
|
sed 's|.*/||' | sort -t - -k 2 -V
|
||||||
)
|
)
|
||||||
|
|
||||||
pveam update >/dev/null 2>&1 || msg_warn "Could not update template catalog (pveam update failed)."
|
# Step 2: If local template found, use it immediately (skip pveam update)
|
||||||
|
|
||||||
msg_ok "Template search completed"
|
|
||||||
|
|
||||||
set +u
|
|
||||||
mapfile -t ONLINE_TEMPLATES < <(pveam available -section system 2>/dev/null | grep -E '\.(tar\.zst|tar\.xz|tar\.gz)$' | awk '{print $2}' | grep -E "^${TEMPLATE_SEARCH}.*${TEMPLATE_PATTERN}" | sort -t - -k 2 -V 2>/dev/null || true)
|
|
||||||
set -u
|
|
||||||
|
|
||||||
ONLINE_TEMPLATE=""
|
|
||||||
[[ ${#ONLINE_TEMPLATES[@]} -gt 0 ]] && ONLINE_TEMPLATE="${ONLINE_TEMPLATES[-1]}"
|
|
||||||
|
|
||||||
if [[ ${#ONLINE_TEMPLATES[@]} -gt 0 ]]; then
|
|
||||||
count=0
|
|
||||||
for idx in "${!ONLINE_TEMPLATES[@]}"; do
|
|
||||||
((count++))
|
|
||||||
[[ $count -ge 3 ]] && break
|
|
||||||
done
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ${#LOCAL_TEMPLATES[@]} -gt 0 ]]; then
|
if [[ ${#LOCAL_TEMPLATES[@]} -gt 0 ]]; then
|
||||||
TEMPLATE="${LOCAL_TEMPLATES[-1]}"
|
TEMPLATE="${LOCAL_TEMPLATES[-1]}"
|
||||||
TEMPLATE_SOURCE="local"
|
TEMPLATE_SOURCE="local"
|
||||||
|
msg_ok "Template search completed"
|
||||||
else
|
else
|
||||||
|
# Step 3: No local template - need to check online (this may be slow)
|
||||||
|
msg_info "No local template found, checking online catalog..."
|
||||||
|
|
||||||
|
# Update catalog with timeout to prevent long hangs
|
||||||
|
if command -v timeout &>/dev/null; then
|
||||||
|
if ! timeout 30 pveam update >/dev/null 2>&1; then
|
||||||
|
msg_warn "Template catalog update timed out (possible network/DNS issue). Run 'pveam update' manually to diagnose."
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
pveam update >/dev/null 2>&1 || msg_warn "Could not update template catalog (pveam update failed)"
|
||||||
|
fi
|
||||||
|
|
||||||
|
set +u
|
||||||
|
mapfile -t ONLINE_TEMPLATES < <(pveam available -section system 2>/dev/null | grep -E '\.(tar\.zst|tar\.xz|tar\.gz)$' | awk '{print $2}' | grep -E "^${TEMPLATE_SEARCH}.*${TEMPLATE_PATTERN}" | sort -t - -k 2 -V 2>/dev/null || true)
|
||||||
|
set -u
|
||||||
|
|
||||||
|
ONLINE_TEMPLATE=""
|
||||||
|
[[ ${#ONLINE_TEMPLATES[@]} -gt 0 ]] && ONLINE_TEMPLATE="${ONLINE_TEMPLATES[-1]}"
|
||||||
|
|
||||||
TEMPLATE="$ONLINE_TEMPLATE"
|
TEMPLATE="$ONLINE_TEMPLATE"
|
||||||
TEMPLATE_SOURCE="online"
|
TEMPLATE_SOURCE="online"
|
||||||
|
msg_ok "Template search completed"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# If still no template, try to find alternatives
|
# If still no template, try to find alternatives
|
||||||
|
|||||||
Reference in New Issue
Block a user