From cad7656d76e227c8a452dfc1f4c9b9bc92642271 Mon Sep 17 00:00:00 2001 From: Pulse Monitor Date: Thu, 28 Aug 2025 14:07:09 +0000 Subject: [PATCH] fix: support non-local storage for templates in install.sh (addresses #368) - Use selected storage instead of hardcoded 'local' for template listing - Use storage:vztmpl/template format instead of hardcoded paths - Downloads now go to the selected storage (btrfs, zfs, etc.) - Check template existence using pveam list with correct storage --- install.sh | 63 ++++++++++++++++++++++++++++++++---------------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/install.sh b/install.sh index 1f3e3016ce..168a258ea7 100755 --- a/install.sh +++ b/install.sh @@ -413,9 +413,9 @@ create_lxc_container() { # Handle OS template selection echo if [[ "$ADVANCED_MODE" == "true" ]]; then - echo "Available OS templates:" - # Use pveam to list templates properly - local TEMPLATES=$(pveam list local 2>/dev/null | tail -n +2 | awk '{print $1}' | sed 's/local:vztmpl\///' | nl -w2 -s') ') + echo "Available OS templates in storage '$storage':" + # Use pveam to list templates properly - use the selected storage, not hardcoded 'local' + local TEMPLATES=$(pveam list "$storage" 2>/dev/null | tail -n +2 | awk '{print $1}' | sed "s/${storage}:vztmpl\///" | nl -w2 -s') ') if [[ -n "$TEMPLATES" ]]; then echo "$TEMPLATES" echo @@ -428,56 +428,67 @@ create_lxc_container() { if [[ -n "$template_choice" ]]; then case "$template_choice" in d|D) - print_info "Downloading Debian 12..." - pveam download local debian-12-standard_12.7-1_amd64.tar.zst - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" + print_info "Downloading Debian 12 to storage '$storage'..." + pveam download "$storage" debian-12-standard_12.7-1_amd64.tar.zst + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" ;; u|U) - print_info "Downloading Ubuntu 22.04..." - pveam download local ubuntu-22.04-standard_22.04-1_amd64.tar.zst - TEMPLATE="/var/lib/vz/template/cache/ubuntu-22.04-standard_22.04-1_amd64.tar.zst" + print_info "Downloading Ubuntu 22.04 to storage '$storage'..." + pveam download "$storage" ubuntu-22.04-standard_22.04-1_amd64.tar.zst + TEMPLATE="${storage}:vztmpl/ubuntu-22.04-standard_22.04-1_amd64.tar.zst" ;; a|A) - print_info "Downloading Alpine Linux..." - pveam download local alpine-3.18-default_20230607_amd64.tar.xz - TEMPLATE="/var/lib/vz/template/cache/alpine-3.18-default_20230607_amd64.tar.xz" + print_info "Downloading Alpine Linux to storage '$storage'..." + pveam download "$storage" alpine-3.18-default_20230607_amd64.tar.xz + TEMPLATE="${storage}:vztmpl/alpine-3.18-default_20230607_amd64.tar.xz" ;; [0-9]*) - TEMPLATE_NAME=$(pveam list local 2>/dev/null | tail -n +2 | awk '{print $1}' | sed 's/local:vztmpl\///' | sed -n "${template_choice}p") + TEMPLATE_NAME=$(pveam list "$storage" 2>/dev/null | tail -n +2 | awk '{print $1}' | sed "s/${storage}:vztmpl\///" | sed -n "${template_choice}p") if [[ -n "$TEMPLATE_NAME" ]]; then - TEMPLATE="/var/lib/vz/template/cache/$TEMPLATE_NAME" + TEMPLATE="${storage}:vztmpl/$TEMPLATE_NAME" print_info "Using template: $TEMPLATE_NAME" else - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" print_info "Invalid selection, using Debian 12" fi ;; *) - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" ;; esac else - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" fi else - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" fi else # Quick mode - use Debian 12 - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" fi # Download template if it doesn't exist - if [[ ! -f "$TEMPLATE" ]]; then - print_info "Template not found, downloading Debian 12..." - if ! pveam download local debian-12-standard_12.7-1_amd64.tar.zst; then + # For storage:vztmpl format, we need to check if template exists using pveam + local TEMPLATE_EXISTS=false + if [[ "$TEMPLATE" =~ ^([^:]+):vztmpl/(.+)$ ]]; then + local STORAGE_NAME="${BASH_REMATCH[1]}" + local TEMPLATE_FILE="${BASH_REMATCH[2]}" + if pveam list "$STORAGE_NAME" 2>/dev/null | grep -q "$TEMPLATE_FILE"; then + TEMPLATE_EXISTS=true + fi + fi + + if [[ "$TEMPLATE_EXISTS" == "false" ]]; then + print_info "Template not found, downloading Debian 12 to storage '$storage'..." + if ! pveam download "$storage" debian-12-standard_12.7-1_amd64.tar.zst; then print_error "Failed to download template. Please check your internet connection and try again." - print_info "You can manually download with: pveam download local debian-12-standard_12.7-1_amd64.tar.zst" + print_info "You can manually download with: pveam download $storage debian-12-standard_12.7-1_amd64.tar.zst" exit 1 fi - TEMPLATE="/var/lib/vz/template/cache/debian-12-standard_12.7-1_amd64.tar.zst" - if [[ ! -f "$TEMPLATE" ]]; then - print_error "Template download succeeded but file not found at expected location" + TEMPLATE="${storage}:vztmpl/debian-12-standard_12.7-1_amd64.tar.zst" + # Verify it was downloaded + if ! pveam list "$storage" 2>/dev/null | grep -q "debian-12-standard_12.7-1_amd64.tar.zst"; then + print_error "Template download succeeded but file not found in storage" exit 1 fi fi