Simplify template detection - check local first
Directly check pveam list local for existing Debian 12 template before attempting download. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
+19
-30
@@ -92,45 +92,34 @@ else
|
|||||||
NET_CONFIG="name=eth0,bridge=$BRIDGE,ip=dhcp"
|
NET_CONFIG="name=eth0,bridge=$BRIDGE,ip=dhcp"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Download Debian template if not exists
|
# Find container template
|
||||||
header "Checking Container Template"
|
header "Checking Container Template"
|
||||||
|
|
||||||
msg "Updating template list..."
|
# Check for existing local Debian 12 template first
|
||||||
|
msg "Checking for local templates..."
|
||||||
|
TEMPLATE=$(pveam list local 2>/dev/null | grep "debian-12" | head -1 | awk '{print $1}')
|
||||||
|
|
||||||
|
if [ -n "$TEMPLATE" ]; then
|
||||||
|
msg "Found local template: $TEMPLATE"
|
||||||
|
else
|
||||||
|
# Need to download
|
||||||
|
msg "No local Debian 12 template found. Downloading..."
|
||||||
pveam update
|
pveam update
|
||||||
|
|
||||||
# Check for existing local templates first
|
# Get the template name from available list
|
||||||
msg "Checking for existing templates..."
|
TEMPLATE_NAME=$(pveam available --section system | grep "debian-12-standard" | awk '{print $2}' | head -1)
|
||||||
EXISTING=$(pveam list $TEMPLATE_STORAGE 2>/dev/null | grep "debian-12" | head -1 | awk '{print $1}')
|
|
||||||
|
|
||||||
if [ -n "$EXISTING" ]; then
|
if [ -z "$TEMPLATE_NAME" ]; then
|
||||||
TEMPLATE="$EXISTING"
|
error "Could not find Debian 12 template to download"
|
||||||
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
|
|
||||||
warn "Could not auto-detect Debian 12 template."
|
|
||||||
echo ""
|
|
||||||
echo "Available system templates:"
|
|
||||||
pveam available --section system
|
|
||||||
echo ""
|
|
||||||
read -p "Enter template name to use: " TEMPLATE
|
|
||||||
|
|
||||||
if [ -z "$TEMPLATE" ]; then
|
|
||||||
error "No template specified. Exiting."
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
msg "Downloading $TEMPLATE..."
|
msg "Downloading $TEMPLATE_NAME..."
|
||||||
pveam download $TEMPLATE_STORAGE $TEMPLATE || error "Failed to download template"
|
pveam download local "$TEMPLATE_NAME"
|
||||||
TEMPLATE="$TEMPLATE_STORAGE:vztmpl/$TEMPLATE"
|
TEMPLATE="local:vztmpl/$TEMPLATE_NAME"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
msg "Will use template: $TEMPLATE"
|
||||||
|
|
||||||
# Create container
|
# Create container
|
||||||
header "Creating LXC Container"
|
header "Creating LXC Container"
|
||||||
msg "Creating container $CTID ($HOSTNAME)..."
|
msg "Creating container $CTID ($HOSTNAME)..."
|
||||||
|
|||||||
Reference in New Issue
Block a user