diff --git a/misc/build.func b/misc/build.func index 040de56c..28635185 100644 --- a/misc/build.func +++ b/misc/build.func @@ -3052,9 +3052,78 @@ create_lxc_container() { TEMPLATE_BASE=$(awk -v s="$TEMPLATE_STORAGE" '$1==s {f=1} f && /path/ {print $2; exit}' /etc/pve/storage.cfg) [[ -n "$TEMPLATE_BASE" ]] && TEMPLATE_PATH="$TEMPLATE_BASE/template/cache/$TEMPLATE" fi + [[ -n "$TEMPLATE_PATH" ]] || { - msg_error "Unable to resolve template path for $TEMPLATE_STORAGE. Check storage type and permissions." - exit 220 + if [[ -z "$TEMPLATE" ]]; then + msg_error "Template ${PCT_OSTYPE} ${PCT_OSVERSION} not available" + + # Get available versions + mapfile -t AVAILABLE_VERSIONS < <( + pveam available -section system 2>/dev/null | + grep "^${PCT_OSTYPE}-" | + sed -E 's/.*'"${PCT_OSTYPE}"'-([0-9]+\.[0-9]+).*/\1/' | + sort -V -u + ) + + if [[ ${#AVAILABLE_VERSIONS[@]} -gt 0 ]]; then + msg_info "Available versions:" + for i in "${!AVAILABLE_VERSIONS[@]}"; do + echo " [$((i + 1))] ${AVAILABLE_VERSIONS[$i]}" + done + + echo "" + read -p "Select version [1-${#AVAILABLE_VERSIONS[@]}] or Enter to exit: " choice + + if [[ "$choice" =~ ^[0-9]+$ ]] && [[ "$choice" -ge 1 ]] && [[ "$choice" -le ${#AVAILABLE_VERSIONS[@]} ]]; then + export var_version="${AVAILABLE_VERSIONS[$((choice - 1))]}" + export PCT_OSVERSION="$var_version" + msg_ok "Switched to ${PCT_OSTYPE} ${var_version}" + + # Retry template search with new version + TEMPLATE_SEARCH="${PCT_OSTYPE}-${PCT_OSVERSION:-}" + mapfile -t LOCAL_TEMPLATES < <( + pveam list "$TEMPLATE_STORAGE" 2>/dev/null | + awk -v s="$TEMPLATE_SEARCH" -v p="$TEMPLATE_PATTERN" '$1 ~ s && $1 ~ p {print $1}' | + sed 's|.*/||' | sort -t - -k 2 -V + ) + mapfile -t ONLINE_TEMPLATES < <( + pveam available -section system 2>/dev/null | + sed -n "s/.*\($TEMPLATE_SEARCH.*$TEMPLATE_PATTERN.*\)/\1/p" | + sort -t - -k 2 -V + ) + ONLINE_TEMPLATE="" + [[ ${#ONLINE_TEMPLATES[@]} -gt 0 ]] && ONLINE_TEMPLATE="${ONLINE_TEMPLATES[-1]}" + + if [[ ${#LOCAL_TEMPLATES[@]} -gt 0 ]]; then + TEMPLATE="${LOCAL_TEMPLATES[-1]}" + TEMPLATE_SOURCE="local" + else + TEMPLATE="$ONLINE_TEMPLATE" + TEMPLATE_SOURCE="online" + fi + + TEMPLATE_PATH="$(pvesm path $TEMPLATE_STORAGE:vztmpl/$TEMPLATE 2>/dev/null || true)" + if [[ -z "$TEMPLATE_PATH" ]]; then + TEMPLATE_BASE=$(awk -v s="$TEMPLATE_STORAGE" '$1==s {f=1} f && /path/ {print $2; exit}' /etc/pve/storage.cfg) + [[ -n "$TEMPLATE_BASE" ]] && TEMPLATE_PATH="$TEMPLATE_BASE/template/cache/$TEMPLATE" + fi + + [[ -n "$TEMPLATE_PATH" ]] || { + msg_error "Template still not found after version change" + exit 220 + } + else + msg_info "Installation cancelled" + exit 0 + fi + else + msg_error "No ${PCT_OSTYPE} templates available" + exit 220 + fi + else + msg_error "Unable to resolve template path for $TEMPLATE_STORAGE" + exit 220 + fi } msg_ok "Template ${BL}$TEMPLATE${CL} [$TEMPLATE_SOURCE]" diff --git a/misc/tools.func b/misc/tools.func index c7699dd4..9cd272a6 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -1803,7 +1803,6 @@ function setup_gs() { msg_ok "Installed Ghostscript $LATEST_VERSION_DOTTED" } - # ------------------------------------------------------------------------------ # Sets up Hardware Acceleration on debian or ubuntu. # @@ -1815,7 +1814,7 @@ function setup_gs() { # Notes: # - Some things are fetched from intel repositories due to not being in debian repositories. # ------------------------------------------------------------------------------ -function setup_hwaccel () { +function setup_hwaccel() { msg_info "Setting Up Hardware Acceleration" if ! command -v lspci &>/dev/null; then @@ -1845,45 +1844,45 @@ function setup_hwaccel () { local in_ct="${CTTYPE:-0}" case "$gpu_vendor" in - Intel) - msg_info "Detected Intel GPU — configuring Intel hardware acceleration" + Intel) + msg_info "Detected Intel GPU — configuring Intel hardware acceleration" - if [[ "$os_id" == "ubuntu" ]]; then - $STD apt -y install intel-opencl-icd || msg_error "Failed to install intel-opencl-icd" - else - fetch_and_deploy_gh_release "intel-igc-core-2" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-core-2_*_amd64.deb" - fetch_and_deploy_gh_release "intel-igc-opencl-2" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-opencl-2_*_amd64.deb" - fetch_and_deploy_gh_release "intel-libgdgmm12" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" - fetch_and_deploy_gh_release "intel-opencl-icd" "intel/compute-runtime" "binary" "latest" "" "intel-opencl-icd_*_amd64.deb" - fi + if [[ "$os_id" == "ubuntu" ]]; then + $STD apt -y install intel-opencl-icd || msg_error "Failed to install intel-opencl-icd" + else + fetch_and_deploy_gh_release "intel-igc-core-2" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-core-2_*_amd64.deb" + fetch_and_deploy_gh_release "intel-igc-opencl-2" "intel/intel-graphics-compiler" "binary" "latest" "" "intel-igc-opencl-2_*_amd64.deb" + fetch_and_deploy_gh_release "intel-libgdgmm12" "intel/compute-runtime" "binary" "latest" "" "libigdgmm12_*_amd64.deb" + fetch_and_deploy_gh_release "intel-opencl-icd" "intel/compute-runtime" "binary" "latest" "" "intel-opencl-icd_*_amd64.deb" + fi - $STD apt -y install va-driver-all ocl-icd-libopencl1 vainfo intel-gpu-tools || msg_error "Failed to install GPU dependencies" - ;; - AMD) - msg_info "Detected AMD GPU — configuring Mesa-based hardware acceleration" + $STD apt -y install va-driver-all ocl-icd-libopencl1 vainfo intel-gpu-tools || msg_error "Failed to install GPU dependencies" + ;; + AMD) + msg_info "Detected AMD GPU — configuring Mesa-based hardware acceleration" - $STD apt -y install mesa-va-drivers mesa-vdpau-drivers mesa-opencl-icd vainfo clinfo || msg_error "Failed to install AMD GPU dependencies" + $STD apt -y install mesa-va-drivers mesa-vdpau-drivers mesa-opencl-icd vainfo clinfo || msg_error "Failed to install AMD GPU dependencies" - # For AMD CPUs without discrete GPU (APUs) - if [[ "$cpu_vendor" == "AuthenticAMD" && "$gpu_vendor" != "AMD" ]]; then - msg_info "Detected AMD CPU (APU) — enabling VAAPI via Mesa" - $STD apt -y install libdrm-amdgpu1 firmware-amd-graphics || true - fi - ;; - NVIDIA) - msg_info "Detected NVIDIA GPU — skipping automatic configuration (manual driver setup required)" - msg_info "→ Please install proprietary drivers manually via: apt install nvidia-driver" - ;; - *) - # If no discrete GPU, but AMD CPU (e.g., Ryzen APU) - if [[ "$cpu_vendor" == "AuthenticAMD" ]]; then - msg_info "Detected AMD CPU without discrete GPU — installing Mesa OpenCL stack" - $STD apt -y install mesa-opencl-icd ocl-icd-libopencl1 clinfo || msg_error "Failed to install Mesa OpenCL stack" - else - msg_error "No supported GPU vendor detected" - return 1 - fi - ;; + # For AMD CPUs without discrete GPU (APUs) + if [[ "$cpu_vendor" == "AuthenticAMD" && "$gpu_vendor" != "AMD" ]]; then + msg_info "Detected AMD CPU (APU) — enabling VAAPI via Mesa" + $STD apt -y install libdrm-amdgpu1 firmware-amd-graphics || true + fi + ;; + NVIDIA) + msg_info "Detected NVIDIA GPU — skipping automatic configuration (manual driver setup required)" + msg_info "→ Please install proprietary drivers manually via: apt install nvidia-driver" + ;; + *) + # If no discrete GPU, but AMD CPU (e.g., Ryzen APU) + if [[ "$cpu_vendor" == "AuthenticAMD" ]]; then + msg_info "Detected AMD CPU without discrete GPU — installing Mesa OpenCL stack" + $STD apt -y install mesa-opencl-icd ocl-icd-libopencl1 clinfo || msg_error "Failed to install Mesa OpenCL stack" + else + msg_error "No supported GPU vendor detected" + return 1 + fi + ;; esac if [[ "$in_ct" == "0" ]]; then @@ -2414,7 +2413,7 @@ function setup_mysql() { SUITE="bookworm" ;; *) - SUITE="bookworm" # Fallback to bookworm for unknown Debian versions + SUITE="bookworm" # Fallback to bookworm for unknown Debian versions ;; esac else @@ -2424,7 +2423,7 @@ function setup_mysql() { # Stop existing MySQL if running $STD systemctl stop mysql 2>/dev/null || true - + # Only purge if MySQL is actually installed if dpkg -l 2>/dev/null | grep -q "^ii.*mysql-server"; then $STD apt purge -y mysql-server* mysql-client* mysql-common 2>/dev/null || true