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:
+27
-12
@@ -98,30 +98,45 @@ header "Checking Container Template"
|
|||||||
msg "Updating template list..."
|
msg "Updating template list..."
|
||||||
pveam update
|
pveam update
|
||||||
|
|
||||||
# Find the latest Debian 12 template
|
# Check for existing local templates first
|
||||||
TEMPLATE=$(pveam available --section system | grep "debian-12-standard" | tail -1 | awk '{print $2}')
|
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
|
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
|
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
|
fi
|
||||||
|
|
||||||
msg "Using template: $TEMPLATE"
|
|
||||||
TEMPLATE_PATH="/var/lib/vz/template/cache/$TEMPLATE"
|
|
||||||
|
|
||||||
if [ ! -f "$TEMPLATE_PATH" ]; then
|
|
||||||
msg "Downloading $TEMPLATE..."
|
msg "Downloading $TEMPLATE..."
|
||||||
pveam download $TEMPLATE_STORAGE $TEMPLATE
|
pveam download $TEMPLATE_STORAGE $TEMPLATE || error "Failed to download template"
|
||||||
else
|
TEMPLATE="$TEMPLATE_STORAGE:vztmpl/$TEMPLATE"
|
||||||
msg "Template already exists"
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Create container
|
# Create container
|
||||||
header "Creating LXC Container"
|
header "Creating LXC Container"
|
||||||
msg "Creating container $CTID ($HOSTNAME)..."
|
msg "Creating container $CTID ($HOSTNAME)..."
|
||||||
|
msg "Using template: $TEMPLATE"
|
||||||
|
|
||||||
pct create $CTID "$TEMPLATE_STORAGE:vztmpl/$TEMPLATE" \
|
pct create $CTID "$TEMPLATE" \
|
||||||
--hostname $HOSTNAME \
|
--hostname $HOSTNAME \
|
||||||
--memory $MEMORY \
|
--memory $MEMORY \
|
||||||
--cores $CORES \
|
--cores $CORES \
|
||||||
|
|||||||
Reference in New Issue
Block a user