diff --git a/create_k3s_ready_lxc.sh b/create_k3s_ready_lxc.sh index 3bd05e7..ec234cc 100644 --- a/create_k3s_ready_lxc.sh +++ b/create_k3s_ready_lxc.sh @@ -1,59 +1,129 @@ #!/usr/bin/env bash set -euo pipefail -echo "=== Proxmox LXC (K3s-ready) Creator ===" -echo +### ---------- helpers ---------- +die() { echo "❌ $*" >&2; exit 1; } +info() { echo "▶ $*"; } +ok() { echo "✅ $*"; } + +choose_from_list() { + local prompt="$1" + shift + local items=("$@") + + echo + echo "$prompt" + echo + + local i=1 + for item in "${items[@]}"; do + printf " %2d) %s\n" "$i" "$item" + ((i++)) + done + + while true; do + echo + read -rp "Enter number or exact value: " choice + + # numeric + if [[ "$choice" =~ ^[0-9]+$ ]] && (( choice >= 1 && choice <= ${#items[@]} )); then + echo "${items[choice-1]}" + return + fi + + # exact match + for item in "${items[@]}"; do + if [[ "$choice" == "$item" ]]; then + echo "$item" + return + fi + done + + echo "❌ Invalid selection. Try again." + done +} + +### ---------- banner ---------- +cat </dev/null && die "Container ID $CT_ID already exists" -### --- Container basics --- -read -rp "Container ID (e.g. 110): " CT_ID read -rp "Hostname: " HOSTNAME -read -rp "Rootfs size (GB, e.g. 16): " ROOTFS_SIZE -read -rp "Memory (MB, e.g. 4096): " MEMORY -read -rp "CPU cores (e.g. 2): " CORES +read -rp "Rootfs size (GB) [16]: " ROOTFS_SIZE +read -rp "Memory (MB) [4096]: " MEMORY +read -rp "CPU cores [2]: " CORES read -rsp "Root password: " PASSWORD echo -### --- Select LXC template --- -echo -echo "Fetching available LXC templates..." +ROOTFS_SIZE=${ROOTFS_SIZE:-16} +MEMORY=${MEMORY:-4096} +CORES=${CORES:-2} + +### ---------- templates ---------- +info "Detecting LXC templates..." mapfile -t TEMPLATES < <(pveam list local | awk '/vztmpl/ {print $1}') +[[ ${#TEMPLATES[@]} -gt 0 ]] || die "No templates found in local storage" -if [[ ${#TEMPLATES[@]} -eq 0 ]]; then - echo "❌ No templates found in local storage." - echo "Run: pveam update && pveam available && pveam download local