Improve Proxmox template detection

- Check for existing local templates first
- Show available templates for debugging
- Allow manual template entry as fallback
- Fix template path handling

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-01-17 12:03:42 -07:00
parent ee97d35bfe
commit 7a5a4a3499
+27 -12
View File
@@ -98,30 +98,45 @@ header "Checking Container Template"
msg "Updating template list..."
pveam update
# Find the latest Debian 12 template
TEMPLATE=$(pveam available --section system | grep "debian-12-standard" | tail -1 | awk '{print $2}')
# Check for existing local templates first
msg "Checking for existing templates..."
EXISTING=$(pveam list $TEMPLATE_STORAGE 2>/dev/null | grep "debian-12" | head -1 | awk '{print $1}')
if [ -n "$EXISTING" ]; then
TEMPLATE="$EXISTING"
msg "Found existing template: $TEMPLATE"
else
# Find available Debian 12 template
msg "Available Debian templates:"
pveam available --section system | grep -i debian
echo ""
TEMPLATE=$(pveam available --section system | grep -i "debian-12" | head -1 | awk '{print $2}')
if [ -z "$TEMPLATE" ]; then
error "Could not find Debian 12 template. Available templates:"
warn "Could not auto-detect Debian 12 template."
echo ""
echo "Available system templates:"
pveam available --section system
exit 1
echo ""
read -p "Enter template name to use: " TEMPLATE
if [ -z "$TEMPLATE" ]; then
error "No template specified. Exiting."
fi
fi
msg "Using template: $TEMPLATE"
TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE"
if [ ! -f "$TEMPLATE_PATH" ]; then
msg "Downloading $TEMPLATE..."
pveam download $TEMPLATE_STORAGE $TEMPLATE
else
msg "Template already exists"
pveam download $TEMPLATE_STORAGE $TEMPLATE || error "Failed to download template"
TEMPLATE="$TEMPLATE_STORAGE:vztmpl/$TEMPLATE"
fi
# Create container
header "Creating LXC Container"
msg "Creating container $CTID ($HOSTNAME)..."
msg "Using template: $TEMPLATE"
pct create $CTID "$TEMPLATE_STORAGE:vztmpl/$TEMPLATE" \
pct create $CTID "$TEMPLATE" \
--hostname $HOSTNAME \
--memory $MEMORY \
--cores $CORES \