From 756eb8e7414af6555ab2ce2b82f7acac09f8866f Mon Sep 17 00:00:00 2001 From: MacRimi Date: Sun, 27 Apr 2025 23:24:05 +0200 Subject: [PATCH] test scripts --- scripts/test/linux.sh | 90 ----- scripts/test/linux_2.sh | 95 ------ scripts/test/linux_3.sh | 82 ----- scripts/test/uupdump.sh | 83 ----- scripts/test/uupdump_2.sh | 113 ------- scripts/test/vm/create_vm.sh | 114 +++++++ scripts/test/vm/disk_selector.sh | 280 ++++++++++++++++ scripts/test/vm/guest_agent_config.sh | 49 +++ .../{linux_4.sh => vm/select_linux_iso.sh} | 73 +++-- scripts/test/vm/select_nas_iso.sh | 73 +++++ scripts/test/vm/select_windows_iso.sh | 90 +++++ scripts/test/vm/uupdump_creator.sh | 139 ++++++++ scripts/test/vm/vm_configurator.sh | 191 +++++++++++ scripts/test/vm/vm_creator.sh | 310 ++++++++++++++++++ 14 files changed, 1283 insertions(+), 499 deletions(-) delete mode 100644 scripts/test/linux.sh delete mode 100644 scripts/test/linux_2.sh delete mode 100644 scripts/test/linux_3.sh delete mode 100644 scripts/test/uupdump.sh delete mode 100644 scripts/test/uupdump_2.sh create mode 100644 scripts/test/vm/create_vm.sh create mode 100644 scripts/test/vm/disk_selector.sh create mode 100644 scripts/test/vm/guest_agent_config.sh rename scripts/test/{linux_4.sh => vm/select_linux_iso.sh} (74%) create mode 100644 scripts/test/vm/select_nas_iso.sh create mode 100644 scripts/test/vm/select_windows_iso.sh create mode 100644 scripts/test/vm/uupdump_creator.sh create mode 100644 scripts/test/vm/vm_configurator.sh create mode 100644 scripts/test/vm/vm_creator.sh diff --git a/scripts/test/linux.sh b/scripts/test/linux.sh deleted file mode 100644 index a2ed143..0000000 --- a/scripts/test/linux.sh +++ /dev/null @@ -1,90 +0,0 @@ -#!/bin/bash - -ISO_DIR="/var/lib/vz/template/iso" -mkdir -p "$ISO_DIR" - -# Comprobar dependencias necesarias -REQUIRED_PACKAGES=(curl wget whiptail) -MISSING="" -for pkg in "${REQUIRED_PACKAGES[@]}"; do - dpkg -s $pkg &>/dev/null || MISSING+="$pkg " -done -if [ -n "$MISSING" ]; then - echo "Instalando dependencias necesarias: $MISSING" - apt update && apt install -y $MISSING -fi - -# Preguntar si se desea ISO tradicional o Cloud-Init -ISO_TYPE=$(whiptail --title "Tipo de ISO Linux" \ - --menu "¿Qué tipo de imagen deseas descargar?" 15 60 4 \ - "tradicional" "ISO estándar (Desktop o Server)" \ - "cloud" "ISO Cloud-Init (uso avanzado)" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -if [ "$ISO_TYPE" = "tradicional" ]; then - # Lista de distros estándar con múltiples versiones - DISTROS=( - "ubuntu_gui|Ubuntu 22.04 LTS Desktop|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-desktop-amd64.iso" - "ubuntu_gui|Ubuntu 20.04 LTS Desktop|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso" - "ubuntu_cli|Ubuntu 22.04 LTS Server (CLI)|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-live-server-amd64.iso" - "ubuntu_cli|Ubuntu 20.04 LTS Server (CLI)|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-live-server-amd64.iso" - "debian_gui|Debian 12 Gnome (Desktop)|https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-12.5.0-amd64-DVD-1.iso" - "debian_gui|Debian 11 Gnome (Desktop)|https://cdimage.debian.org/debian-cd/11.9.0/amd64/iso-dvd/debian-11.9.0-amd64-DVD-1.iso" - "debian_cli|Debian 12 Netinst (CLI)|https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso" - "debian_cli|Debian 11 Netinst (CLI)|https://cdimage.debian.org/debian-cd/11.9.0/amd64/iso-cd/debian-11.9.0-amd64-netinst.iso" - "fedora_gui|Fedora Workstation 39 (Desktop)|https://download.fedoraproject.org/pub/fedora/linux/releases/39/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-39-1.5.iso" - "fedora_gui|Fedora Workstation 38 (Desktop)|https://download.fedoraproject.org/pub/fedora/linux/releases/38/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-38-1.6.iso" - "rocky_gui|Rocky Linux 9.3 Gnome (Desktop)|https://download.rockylinux.org/pub/rocky/9.3/isos/x86_64/Rocky-9.3-x86_64-boot.iso" - "rocky_gui|Rocky Linux 8.9 Gnome (Desktop)|https://download.rockylinux.org/pub/rocky/8.9/isos/x86_64/Rocky-8.9-x86_64-boot.iso" - "mint_gui|Linux Mint 21.3 Cinnamon (Desktop)|https://mirrors.edge.kernel.org/linuxmint/stable/21.3/linuxmint-21.3-cinnamon-64bit.iso" - "mint_gui|Linux Mint 21.2 Cinnamon (Desktop)|https://mirrors.edge.kernel.org/linuxmint/stable/21.2/linuxmint-21.2-cinnamon-64bit.iso" - "opensuse_gui|openSUSE Leap 15.5 (Desktop)|https://download.opensuse.org/distribution/leap/15.5/iso/openSUSE-Leap-15.5-DVD-x86_64.iso" - "opensuse_gui|openSUSE Leap 15.4 (Desktop)|https://download.opensuse.org/distribution/leap/15.4/iso/openSUSE-Leap-15.4-DVD-x86_64.iso" - ) -else - # Lista de distros con Cloud-Init - DISTROS=( - "ubuntu_cloud|Ubuntu 22.04 Cloud-Init|https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" - "ubuntu_cloud|Ubuntu 20.04 Cloud-Init|https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img" - "debian_cloud|Debian 12 Cloud-Init|https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2" - "debian_cloud|Debian 11 Cloud-Init|https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2" - "rocky_cloud|Rocky Linux 9 Cloud-Init|https://download.rockylinux.org/pub/rocky/9/cloud/x86_64/images/Rocky-9-GenericCloud.latest.x86_64.qcow2" - "rocky_cloud|Rocky Linux 8 Cloud-Init|https://download.rockylinux.org/pub/rocky/8/cloud/x86_64/images/Rocky-8-GenericCloud.latest.x86_64.qcow2" - "almalinux_cloud|AlmaLinux 9 Cloud-Init|https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2" - "almalinux_cloud|AlmaLinux 8 Cloud-Init|https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2" - ) -fi - -# Crear menú con whiptail -MENU_OPTIONS=() -INDEX=0 -for entry in "${DISTROS[@]}"; do - NAME=$(echo "$entry" | cut -d"|" -f2) - MENU_OPTIONS+=("$INDEX" "$NAME") - URLS[$INDEX]="$entry" - ((INDEX++)) -done - -CHOICE=$(whiptail --title "Descarga de ISO Linux" \ - --menu "Selecciona una versión para descargar:" 25 78 15 \ - "${MENU_OPTIONS[@]}" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -SELECTED="${URLS[$CHOICE]}" -NAME=$(echo "$SELECTED" | cut -d"|" -f2) -URL=$(echo "$SELECTED" | cut -d"|" -f3) -FILENAME=$(basename "$URL") - -# Descargar ISO si no existe -if [ -f "$ISO_DIR/$FILENAME" ]; then - echo "ℹ️ La imagen ya existe: $ISO_DIR/$FILENAME" -else - echo "⬇️ Descargando $NAME..." - wget -O "$ISO_DIR/$FILENAME" "$URL" -fi - -echo "✅ Imagen lista: $ISO_DIR/$FILENAME" diff --git a/scripts/test/linux_2.sh b/scripts/test/linux_2.sh deleted file mode 100644 index 21e5618..0000000 --- a/scripts/test/linux_2.sh +++ /dev/null @@ -1,95 +0,0 @@ -#!/bin/bash - -ISO_DIR="/var/lib/vz/template/iso" -mkdir -p "$ISO_DIR" - -# Comprobar dependencias necesarias -REQUIRED_PACKAGES=(curl wget whiptail) -MISSING="" -for pkg in "${REQUIRED_PACKAGES[@]}"; do - dpkg -s $pkg &>/dev/null || MISSING+="$pkg " -done -if [ -n "$MISSING" ]; then - echo "Instalando dependencias necesarias: $MISSING" - apt update && apt install -y $MISSING -fi - -# Preguntar si se desea ISO tradicional, Cloud-Init o ejecución externa -ISO_TYPE=$(whiptail --title "Tipo de instalación Linux" \ - --menu "¿Qué tipo de sistema deseas instalar?" 15 70 5 \ - "tradicional" "ISO estándar (Desktop o Server)" \ - "cloud" "Cloud-Init (requiere configuración extra)" \ - "externo" "Instalación automatizada desde repositorio externo" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -if [ "$ISO_TYPE" = "tradicional" ]; then - DISTROS=( - "ubuntu_gui|Ubuntu 22.04 LTS Desktop|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-desktop-amd64.iso" - "ubuntu_gui|Ubuntu 20.04 LTS Desktop|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso" - "ubuntu_cli|Ubuntu 22.04 LTS Server (CLI)|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-live-server-amd64.iso" - "ubuntu_cli|Ubuntu 20.04 LTS Server (CLI)|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-live-server-amd64.iso" - "debian_gui|Debian 12 Gnome (Desktop)|https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-12.5.0-amd64-DVD-1.iso" - "debian_gui|Debian 11 Gnome (Desktop)|https://cdimage.debian.org/debian-cd/11.9.0/amd64/iso-dvd/debian-11.9.0-amd64-DVD-1.iso" - "debian_cli|Debian 12 Netinst (CLI)|https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso" - "debian_cli|Debian 11 Netinst (CLI)|https://cdimage.debian.org/debian-cd/11.9.0/amd64/iso-cd/debian-11.9.0-amd64-netinst.iso" - "fedora_gui|Fedora Workstation 39 (Desktop)|https://download.fedoraproject.org/pub/fedora/linux/releases/39/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-39-1.5.iso" - "fedora_gui|Fedora Workstation 38 (Desktop)|https://download.fedoraproject.org/pub/fedora/linux/releases/38/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-38-1.6.iso" - "rocky_gui|Rocky Linux 9.3 Gnome (Desktop)|https://download.rockylinux.org/pub/rocky/9.3/isos/x86_64/Rocky-9.3-x86_64-boot.iso" - "rocky_gui|Rocky Linux 8.9 Gnome (Desktop)|https://download.rockylinux.org/pub/rocky/8.9/isos/x86_64/Rocky-8.9-x86_64-boot.iso" - "mint_gui|Linux Mint 21.3 Cinnamon (Desktop)|https://mirrors.edge.kernel.org/linuxmint/stable/21.3/linuxmint-21.3-cinnamon-64bit.iso" - "mint_gui|Linux Mint 21.2 Cinnamon (Desktop)|https://mirrors.edge.kernel.org/linuxmint/stable/21.2/linuxmint-21.2-cinnamon-64bit.iso" - "opensuse_gui|openSUSE Leap 15.5 (Desktop)|https://download.opensuse.org/distribution/leap/15.5/iso/openSUSE-Leap-15.5-DVD-x86_64.iso" - "opensuse_gui|openSUSE Leap 15.4 (Desktop)|https://download.opensuse.org/distribution/leap/15.4/iso/openSUSE-Leap-15.4-DVD-x86_64.iso" - ) -elif [ "$ISO_TYPE" = "cloud" ]; then - DISTROS=( - "ubuntu_cloud|Ubuntu 22.04 Cloud-Init|https://cloud-images.ubuntu.com/releases/22.04/release/ubuntu-22.04-server-cloudimg-amd64.img" - "ubuntu_cloud|Ubuntu 20.04 Cloud-Init|https://cloud-images.ubuntu.com/releases/20.04/release/ubuntu-20.04-server-cloudimg-amd64.img" - "debian_cloud|Debian 12 Cloud-Init|https://cloud.debian.org/images/cloud/bookworm/latest/debian-12-genericcloud-amd64.qcow2" - "debian_cloud|Debian 11 Cloud-Init|https://cloud.debian.org/images/cloud/bullseye/latest/debian-11-genericcloud-amd64.qcow2" - "rocky_cloud|Rocky Linux 9 Cloud-Init|https://download.rockylinux.org/pub/rocky/9/cloud/x86_64/images/Rocky-9-GenericCloud.latest.x86_64.qcow2" - "rocky_cloud|Rocky Linux 8 Cloud-Init|https://download.rockylinux.org/pub/rocky/8/cloud/x86_64/images/Rocky-8-GenericCloud.latest.x86_64.qcow2" - "almalinux_cloud|AlmaLinux 9 Cloud-Init|https://repo.almalinux.org/almalinux/9/cloud/x86_64/images/AlmaLinux-9-GenericCloud-latest.x86_64.qcow2" - "almalinux_cloud|AlmaLinux 8 Cloud-Init|https://repo.almalinux.org/almalinux/8/cloud/x86_64/images/AlmaLinux-8-GenericCloud-latest.x86_64.qcow2" - ) -else - # Instalaciones desde scripts externos - bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/archlinux-vm.sh)" - bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/debian-vm.sh)" - bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2204-vm.sh)" - bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2404-vm.sh)" - bash -c "$(curl -fsSL https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2410-vm.sh)" - exit 0 -fi - -MENU_OPTIONS=() -INDEX=0 -for entry in "${DISTROS[@]}"; do - NAME=$(echo "$entry" | cut -d"|" -f2) - MENU_OPTIONS+=("$INDEX" "$NAME") - URLS[$INDEX]="$entry" - ((INDEX++)) -done - -CHOICE=$(whiptail --title "Descarga de ISO Linux" \ - --menu "Selecciona una versión para descargar:" 25 78 15 \ - "${MENU_OPTIONS[@]}" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -SELECTED="${URLS[$CHOICE]}" -NAME=$(echo "$SELECTED" | cut -d"|" -f2) -URL=$(echo "$SELECTED" | cut -d"|" -f3) -FILENAME=$(basename "$URL") - -if [ -f "$ISO_DIR/$FILENAME" ]; then - echo "ℹ️ La imagen ya existe: $ISO_DIR/$FILENAME" -else - echo "⬇️ Descargando $NAME..." - wget -O "$ISO_DIR/$FILENAME" "$URL" -fi - -echo "✅ Imagen lista: $ISO_DIR/$FILENAME" diff --git a/scripts/test/linux_3.sh b/scripts/test/linux_3.sh deleted file mode 100644 index 66c30e9..0000000 --- a/scripts/test/linux_3.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -ISO_DIR="/var/lib/vz/template/iso" -mkdir -p "$ISO_DIR" - -# Comprobar dependencias necesarias -REQUIRED_PACKAGES=(curl wget whiptail) -MISSING="" -for pkg in "${REQUIRED_PACKAGES[@]}"; do - dpkg -s $pkg &>/dev/null || MISSING+="$pkg " -done -if [ -n "$MISSING" ]; then - echo "Instalando dependencias necesarias: $MISSING" - apt update && apt install -y $MISSING -fi - -# Menú combinado único con fuente de origen -DISTROS=( - "Ubuntu 22.04 LTS Desktop |Desktop |ProxMenux|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-desktop-amd64.iso" - "Ubuntu 20.04 LTS Desktop |Desktop |ProxMenux|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso" - "Ubuntu 22.04 LTS Server (CLI) |CLI |ProxMenux|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-live-server-amd64.iso" - "Ubuntu 20.04 LTS Server (CLI) |CLI |ProxMenux|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-live-server-amd64.iso" - "Debian 12 Gnome (Desktop) |Desktop |ProxMenux|https://cdimage.debian.org/debian-cd/current/amd64/iso-dvd/debian-12.5.0-amd64-DVD-1.iso" - "Debian 11 Gnome (Desktop) |Desktop |ProxMenux|https://cdimage.debian.org/debian-cd/11.9.0/amd64/iso-dvd/debian-11.9.0-amd64-DVD-1.iso" - "Debian 12 Netinst (CLI) |CLI |ProxMenux|https://cdimage.debian.org/debian-cd/current/amd64/iso-cd/debian-12.5.0-amd64-netinst.iso" - "Debian 11 Netinst (CLI) |CLI |ProxMenux|https://cdimage.debian.org/debian-cd/11.9.0/amd64/iso-cd/debian-11.9.0-amd64-netinst.iso" - "Fedora Workstation 39 |Desktop |ProxMenux|https://download.fedoraproject.org/pub/fedora/linux/releases/39/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-39-1.5.iso" - "Fedora Workstation 38 |Desktop |ProxMenux|https://download.fedoraproject.org/pub/fedora/linux/releases/38/Workstation/x86_64/iso/Fedora-Workstation-Live-x86_64-38-1.6.iso" - "Rocky Linux 9.3 Gnome |Desktop |ProxMenux|https://download.rockylinux.org/pub/rocky/9.3/isos/x86_64/Rocky-9.3-x86_64-boot.iso" - "Rocky Linux 8.9 Gnome |Desktop |ProxMenux|https://download.rockylinux.org/pub/rocky/8.9/isos/x86_64/Rocky-8.9-x86_64-boot.iso" - "Linux Mint 21.3 Cinnamon |Desktop |ProxMenux|https://mirrors.edge.kernel.org/linuxmint/stable/21.3/linuxmint-21.3-cinnamon-64bit.iso" - "Linux Mint 21.2 Cinnamon |Desktop |ProxMenux|https://mirrors.edge.kernel.org/linuxmint/stable/21.2/linuxmint-21.2-cinnamon-64bit.iso" - "openSUSE Leap 15.5 |Desktop |ProxMenux|https://download.opensuse.org/distribution/leap/15.5/iso/openSUSE-Leap-15.5-DVD-x86_64.iso" - "openSUSE Leap 15.4 |Desktop |ProxMenux|https://download.opensuse.org/distribution/leap/15.4/iso/openSUSE-Leap-15.4-DVD-x86_64.iso" - "Alpine Linux 3.19 |CLI |ProxMenux|https://dl-cdn.alpinelinux.org/alpine/v3.19/releases/x86_64/alpine-standard-3.19.1-x86_64.iso" - "Kali Linux 2024.1 |Desktop |ProxMenux|https://cdimage.kali.org/kali-2024.1/kali-linux-2024.1-installer-amd64.iso" - "Arch Linux (automatizado) |Automatizado |Helper Scripts|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/archlinux-vm.sh" - "Debian 12 (automatizado) |Automatizado |Helper Scripts|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/debian-vm.sh" - "Ubuntu 22.04 (automatizado) |Automatizado |Helper Scripts|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2204-vm.sh" - "Ubuntu 24.04 (automatizado) |Automatizado |Helper Scripts|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2404-vm.sh" - "Ubuntu 24.10 (automatizado) |Automatizado |Helper Scripts|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2410-vm.sh" -) - -# Construir menú con columnas alineadas -MENU_OPTIONS=("HEADER" "Versión │ Tipo │ Fuente") -INDEX=0 -for entry in "${DISTROS[@]}"; do - NAME=$(echo "$entry" | cut -d"|" -f1) - TYPE=$(echo "$entry" | cut -d"|" -f2) - SOURCE=$(echo "$entry" | cut -d"|" -f3) - DISPLAY="${NAME} │ ${TYPE} │ ${SOURCE}" - MENU_OPTIONS+=("$INDEX" "$DISPLAY") - URLS[$INDEX]="$entry" - ((INDEX++)) -done - -CHOICE=$(whiptail --title "Instalación Linux" \ - --menu "Selecciona la distribución que deseas instalar o descargar:" 25 100 20 \ - "${MENU_OPTIONS[@]}" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -SELECTED="${URLS[$CHOICE]}" -NAME=$(echo "$SELECTED" | cut -d"|" -f1) -TYPE=$(echo "$SELECTED" | cut -d"|" -f2) -SOURCE=$(echo "$SELECTED" | cut -d"|" -f3) -URL=$(echo "$SELECTED" | cut -d"|" -f4) - -if [[ "$TYPE" == "Automatizado" ]]; then - echo "Ejecutando script remoto para: $NAME" - bash -c "$(curl -fsSL $URL)" -else - FILENAME=$(basename "$URL") - if [ -f "$ISO_DIR/$FILENAME" ]; then - echo "ℹ️ La imagen ya existe: $ISO_DIR/$FILENAME" - else - echo "⬇️ Descargando $NAME..." - wget -O "$ISO_DIR/$FILENAME" "$URL" - fi - echo "✅ Imagen lista: $ISO_DIR/$FILENAME" -fi \ No newline at end of file diff --git a/scripts/test/uupdump.sh b/scripts/test/uupdump.sh deleted file mode 100644 index 278739b..0000000 --- a/scripts/test/uupdump.sh +++ /dev/null @@ -1,83 +0,0 @@ -#!/bin/bash - -# Ruta donde se guardarán las ISOs -ISO_DIR="/var/lib/vz/template/iso" -WORK_DIR="/root/uupdump" -mkdir -p "$WORK_DIR" -cd "$WORK_DIR" || exit 1 - -# Comprobar dependencias necesarias -REQUIRED_PACKAGES=(aria2 cabextract wimtools chntpw genisoimage unzip curl jq whiptail) -MISSING="" -for pkg in "${REQUIRED_PACKAGES[@]}"; do - dpkg -s $pkg &>/dev/null || MISSING+="$pkg " -done -if [ -n "$MISSING" ]; then - echo "Instalando dependencias necesarias: $MISSING" - apt update && apt install -y $MISSING -fi - -# Versiones predefinidas -VERSIONS=( - "Win11_Pro_23H2|22631.1.230530-1536|x64|es-es" - "Win10_LTSC_2021|19044.1288|x64|es-es" - "Win_Server_2022|20348.1|x64|es-es" -) - -# Crear menú con whiptail -MENU_OPTIONS=() -for i in "${!VERSIONS[@]}"; do - NAME=$(echo "${VERSIONS[$i]}" | cut -d"|" -f1) - MENU_OPTIONS+=("$i" "$NAME") -done - -CHOICE=$(whiptail --title "Descarga de ISO Windows" \ - --menu "Elige una versión de Windows para generar la ISO:" 20 60 10 \ - "${MENU_OPTIONS[@]}" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -# Obtener datos seleccionados -SELECTED="${VERSIONS[$CHOICE]}" -NAME=$(echo "$SELECTED" | cut -d"|" -f1) -BUILD=$(echo "$SELECTED" | cut -d"|" -f2) -ARCH=$(echo "$SELECTED" | cut -d"|" -f3) -LANG=$(echo "$SELECTED" | cut -d"|" -f4) - -# Consultar API para obtener ID de descarga -API_URL="https://api.uupdump.net/listid.php?search=$NAME&arch=$ARCH&ring=retail" - -ID=$(curl -s "$API_URL" | jq -r ".response[] | select(.build == \"$BUILD\") | .uuid" | head -n1) - -if [ -z "$ID" ]; then - echo "No se encontró la versión en la API." - exit 1 -fi - -# Descargar el ZIP de UUP dump -ZIP_URL="https://api.uupdump.net/getpkg.php?id=$ID&autodl=2" -ZIP_NAME="uupdump_$ID.zip" -curl -L "$ZIP_URL" -o "$ZIP_NAME" -unzip -o "$ZIP_NAME" -d "$WORK_DIR/$ID" -cd "$WORK_DIR/$ID" || exit 1 -chmod +x uup_download_linux.sh - -# Ejecutar generador de ISO -./uup_download_linux.sh - -# Mover ISO generada -ISO_FILE=$(find . -type f -name "*.iso" | head -n1) -if [ -f "$ISO_FILE" ]; then - mv "$ISO_FILE" "$ISO_DIR/" - echo "✅ ISO generada y movida a: $ISO_DIR/$(basename "$ISO_FILE")" - - # Limpieza de archivos temporales - echo "🧹 Limpiando archivos temporales..." - rm -rf "$WORK_DIR/$ID" - rm -f "$WORK_DIR/$ZIP_NAME" - echo "✅ Limpieza completada." -else - echo "❌ No se encontró la ISO generada." - exit 1 -fi diff --git a/scripts/test/uupdump_2.sh b/scripts/test/uupdump_2.sh deleted file mode 100644 index 337b45b..0000000 --- a/scripts/test/uupdump_2.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/bin/bash - -# Ruta donde se guardarán las ISOs -ISO_DIR="/var/lib/vz/template/iso" -WORK_DIR="/root/uupdump" -mkdir -p "$WORK_DIR" -cd "$WORK_DIR" || exit 1 - -# Comprobar dependencias necesarias -REQUIRED_PACKAGES=(aria2 cabextract wimtools chntpw genisoimage unzip curl jq whiptail) -MISSING="" -for pkg in "${REQUIRED_PACKAGES[@]}"; do - dpkg -s $pkg &>/dev/null || MISSING+="$pkg " -done -if [ -n "$MISSING" ]; then - echo "Instalando dependencias necesarias: $MISSING" - apt update && apt install -y $MISSING -fi - -# Menú principal para elegir familia de Windows -FAMILY=$(whiptail --title "Tipo de Windows" \ - --menu "Selecciona qué tipo de Windows deseas descargar:" 15 60 4 \ - "w11" "Windows 11" \ - "w10" "Windows 10" \ - "srv" "Windows Server" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -# Parámetros de búsqueda según la familia seleccionada -case $FAMILY in - w11) - SEARCH_TERM="windows 11" - TITLE_MENU="Windows 11" - ;; - w10) - SEARCH_TERM="windows 10" - TITLE_MENU="Windows 10" - ;; - srv) - SEARCH_TERM="windows server" - TITLE_MENU="Windows Server" - ;; - *) - echo "Selección inválida" - exit 1 - ;; -esac - -# Obtener lista dinámica de builds desde UUP dump API -API_URL="https://api.uupdump.net/listid.php?search=$(echo $SEARCH_TERM | sed 's/ /+/g')&arch=x64&ring=retail" -VERSIONS=$(curl -s "$API_URL" | jq -r '.response[] | [.title, .build, .arch] | @tsv' | head -n 10) - -# Construir menú dinámico -MENU_OPTIONS=() -INDEX=0 -while IFS=$'\t' read -r TITLE BUILD ARCH; do - DISPLAY_NAME="$TITLE ($BUILD)" - MENU_OPTIONS+=("$INDEX" "$DISPLAY_NAME") - VERSION_DATA[$INDEX]="$TITLE|$BUILD|$ARCH|es-es" - ((INDEX++)) -done <<< "$VERSIONS" - -CHOICE=$(whiptail --title "Descarga de ISO $TITLE_MENU" \ - --menu "Elige una versión para generar la ISO:" 20 78 10 \ - "${MENU_OPTIONS[@]}" \ - 3>&1 1>&2 2>&3) - -[ $? -ne 0 ] && echo "Cancelado." && exit 1 - -# Obtener datos seleccionados -SELECTED="${VERSION_DATA[$CHOICE]}" -NAME=$(echo "$SELECTED" | cut -d"|" -f1) -BUILD=$(echo "$SELECTED" | cut -d"|" -f2) -ARCH=$(echo "$SELECTED" | cut -d"|" -f3) -LANG=$(echo "$SELECTED" | cut -d"|" -f4) - -# Consultar API para obtener ID de descarga -API_URL="https://api.uupdump.net/listid.php?search=$(echo $NAME | sed 's/ /+/g')&arch=$ARCH&ring=retail" - -ID=$(curl -s "$API_URL" | jq -r ".response[] | select(.build == \"$BUILD\") | .uuid" | head -n1) - -if [ -z "$ID" ]; then - echo "No se encontró la versión en la API." - exit 1 -fi - -# Descargar el ZIP de UUP dump -ZIP_URL="https://api.uupdump.net/getpkg.php?id=$ID&autodl=2" -ZIP_NAME="uupdump_$ID.zip" -curl -L "$ZIP_URL" -o "$ZIP_NAME" -unzip -o "$ZIP_NAME" -d "$WORK_DIR/$ID" -cd "$WORK_DIR/$ID" || exit 1 -chmod +x uup_download_linux.sh - -# Ejecutar generador de ISO -./uup_download_linux.sh - -# Mover ISO generada -ISO_FILE=$(find . -type f -name "*.iso" | head -n1) -if [ -f "$ISO_FILE" ]; then - mv "$ISO_FILE" "$ISO_DIR/" - echo "✅ ISO generada y movida a: $ISO_DIR/$(basename "$ISO_FILE")" - - # Limpieza de archivos temporales - echo "🧹 Limpiando archivos temporales..." - rm -rf "$WORK_DIR/$ID" - rm -f "$WORK_DIR/$ZIP_NAME" - echo "✅ Limpieza completada." -else - echo "❌ No se encontró la ISO generada." - exit 1 -fi diff --git a/scripts/test/vm/create_vm.sh b/scripts/test/vm/create_vm.sh new file mode 100644 index 0000000..0134431 --- /dev/null +++ b/scripts/test/vm/create_vm.sh @@ -0,0 +1,114 @@ +#!/usr/bin/env bash + +# ================================================ +# ProxMenux - Create VM Entry Point +# ================================================ +# Author : MacRimi +# ================================================ + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" +VM_CONFIG="./vm_configurator.sh" +DISK_SELECTOR="./disk_selector.sh" +VM_CREATOR="./vm_creator.sh" +#LINUX_ISO="./select_linux_iso.sh" +GUEST_AGENT="./guest_agent_config.sh" + + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + +# Load modules +[[ -f "$UTILS_FILE" ]] && source "$UTILS_FILE" +[[ -f "$VM_CONFIG" ]] && source "$VM_CONFIG" +[[ -f "$DISK_SELECTOR" ]] && source "$DISK_SELECTOR" +[[ -f "$VM_CREATOR" ]] && source "$VM_CREATOR" +[[ -f "$LINUX_ISO" ]] && source "$LINUX_ISO" +[[ -f "$GUEST_AGENT" ]] && source "$GUEST_AGENT" + + + + +function header_info() { + clear + show_proxmenux_logo + echo -e "${BL}╔═══════════════════════════════════════════════╗${CL}" + echo -e "${BL}║ ║${CL}" + echo -e "${BL}║${YWB} ProxMenux VM Creator ${BL}║${CL}" + echo -e "${BL}║ ║${CL}" + echo -e "${BL}╚═══════════════════════════════════════════════╝${CL}" + echo -e +} + +# ========================================================== +# MAIN EXECUTION +# ========================================================== + +header_info +echo -e "\n Loading..." +sleep 1 + +# Step 1 - Select OS Type +OS_TYPE=$(whiptail --title "ProxMenux" --menu "$(translate "Select the type of system to install")" 15 60 4 \ + "nas" "$(translate "Create VM System NAS")" \ + "windows" "$(translate "Create VM System Windows")" \ + "linux" "$(translate "Create VM System Linux")" \ + "lite" "$(translate "Create VM System Others (based Linux)")" 3>&1 1>&2 2>&3) + +[[ -z "$OS_TYPE" ]] && clear && exit + + +if [[ "$OS_TYPE" == "nas" ]]; then + header_info + source ./select_nas_iso.sh + select_nas_iso || exit 1 +fi + + +# Si es Windows, invocar selección de ISO +if [[ "$OS_TYPE" == "windows" ]]; then + header_info + source ./select_windows_iso.sh + select_windows_iso || exit 1 +fi + + +# Si es Linux, invocar selección de ISO +if [[ "$OS_TYPE" == "linux" ]]; then + header_info + source ./select_linux_iso.sh + select_linux_iso || exit 1 +fi + + + + + +# Step 2 - Default or Advanced config +if (whiptail --title "ProxMenux" --yesno "$(translate "Use Default Settings?")" --no-button "$(translate "Advanced")" 10 60); then + header_info + load_default_vm_config "$OS_TYPE" + apply_default_vm_config +else + header_info + echo -e "${CUS}$(translate "Using advanced configuration")${CL}" + configure_vm_advanced "$OS_TYPE" +fi + +# Step 3 - Disk selection +select_disk_type +if [[ -z "$DISK_TYPE" ]]; then + msg_error "$(translate "Disk type selection failed or cancelled")" + exit 1 +fi + +# Step 4 - Create VM +create_vm + +# Step 5 - Guest Agent integration +configure_guest_agent diff --git a/scripts/test/vm/disk_selector.sh b/scripts/test/vm/disk_selector.sh new file mode 100644 index 0000000..82cb0fb --- /dev/null +++ b/scripts/test/vm/disk_selector.sh @@ -0,0 +1,280 @@ +#!/usr/bin/env bash + +# ========================================================== +# Disk Selector Module - ProxMenux +# ========================================================== +# Reutiliza la lógica original de selección de discos +# virtuales y físicos con integración de traducciones +# ========================================================== + + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + +function select_disk_type() { + DISK_TYPE=$(whiptail --backtitle "ProxMenux" --title "DISK TYPE" --menu "$(translate "Choose disk type:")" 12 58 2 \ + "virtual" "$(translate "Create virtual disk")" \ + "passthrough" "$(translate "Use physical disk passthrough")" \ + --ok-button "Select" --cancel-button "Cancel" 3>&1 1>&2 2>&3) + + [[ -z "$DISK_TYPE" ]] && return 1 + + if [[ "$DISK_TYPE" == "virtual" ]]; then + select_virtual_disk + else + select_passthrough_disk + fi +} + +# ========================================================== +# Select Virtual Disks +# ========================================================== +function select_virtual_disk() { + + VIRTUAL_DISKS=() + + # Loop to add multiple disks + local add_more_disks=true + while $add_more_disks; do + + msg_info "Detecting available storage volumes..." + + # Get list of available storage + STORAGE_MENU=() + while read -r line; do + TAG=$(echo $line | awk '{print $1}') + TYPE=$(echo $line | awk '{print $2}') + FREE=$(echo $line | numfmt --field 4-6 --from-unit=K --to=iec --format "%.2f" | awk '{printf( "%9sB", $6)}') + ITEM=$(printf "%-15s %-10s %-15s" "$TAG" "$TYPE" "$FREE") + STORAGE_MENU+=("$TAG" "$ITEM" "OFF") + done < <(pvesm status -content images | awk 'NR>1') + + # Check that storage is available + VALID=$(pvesm status -content images | awk 'NR>1') + if [ -z "$VALID" ]; then + msg_error "Unable to detect a valid storage location." + sleep 2 + select_disk_type + fi + + + # Select storage + if [ $((${#STORAGE_MENU[@]} / 3)) -eq 1 ]; then + STORAGE=${STORAGE_MENU[0]} + msg_ok "Using ${CL}${BL}$STORAGE${CL} ${GN}for Storage Location." + else + + kill $SPINNER_PID > /dev/null + STORAGE=$(whiptail --backtitle "ProxMenuX" --title "$(translate "Select Storage Volume")" --radiolist \ + "$(translate "Choose the storage volume for the virtual disk:\n")" 20 78 10 \ + "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) + + if [ $? -ne 0 ] || [ -z "$STORAGE" ]; then + if [ ${#VIRTUAL_DISKS[@]} -eq 0 ]; then + msg_error "No storage selected. At least one disk is required." + select_disk_type + else + add_more_disks=false + continue + fi + fi + + + fi + + # Request disk size + DISK_SIZE=$(whiptail --backtitle "ProxMenuX" --inputbox "$(translate "System Disk Size (GB)")" 8 58 32 --title "VIRTUAL DISK" --cancel-button Cancel 3>&1 1>&2 2>&3) + + if [ $? -ne 0 ]; then + if [ ${#VIRTUAL_DISKS[@]} -eq 0 ]; then + msg_error "Disk size not specified. At least one disk is required." + sleep 2 + select_disk_type + + else + add_more_disks=false + continue + fi + fi + + if [ -z "$DISK_SIZE" ]; then + DISK_SIZE="32" + fi + + # Store the configuration in the disk list + VIRTUAL_DISKS+=("${STORAGE}:${DISK_SIZE}") + + + # Ask if you want to create another disk + if ! whiptail --backtitle "ProxMenuX" --title "$(translate "Add Another Disk")" \ + --yesno "$(translate "Do you want to add another virtual disk?")" 8 58; then + add_more_disks=false + fi + done + + # Show summary of the created disks + if [ ${#VIRTUAL_DISKS[@]} -gt 0 ]; then + + msg_ok "Virtual Disks Created:" + for i in "${!VIRTUAL_DISKS[@]}"; do + echo -e "${TAB}${BL}- Disk $((i+1)): ${VIRTUAL_DISKS[$i]}GB${CL}" + done + fi + + + export VIRTUAL_DISKS + + +} + +# ========================================================== + + + + + + +# ========================================================== +# Select Physical Disks +# ========================================================== +function select_passthrough_disk() { + + msg_info "$(translate "Detecting available disks...")" + + FREE_DISKS=() + + USED_DISKS=$(lsblk -n -o PKNAME,TYPE | grep 'lvm' | awk '{print "/dev/" $1}') + MOUNTED_DISKS=$(lsblk -ln -o NAME,MOUNTPOINT | awk '$2!="" {print "/dev/" $1}') + + ZFS_DISKS="" + ZFS_RAW=$(zpool list -v -H 2>/dev/null | awk '{print $1}' | grep -v '^NAME$' | grep -v '^-' | grep -v '^mirror') + + for entry in $ZFS_RAW; do + path="" + if [[ "$entry" == wwn-* || "$entry" == ata-* ]]; then + if [ -e "/dev/disk/by-id/$entry" ]; then + path=$(readlink -f "/dev/disk/by-id/$entry") + fi + elif [[ "$entry" == /dev/* ]]; then + path="$entry" + fi + + if [ -n "$path" ]; then + base_disk=$(lsblk -no PKNAME "$path" 2>/dev/null) + if [ -n "$base_disk" ]; then + ZFS_DISKS+="/dev/$base_disk"$'\n' + fi + fi + done + + ZFS_DISKS=$(echo "$ZFS_DISKS" | sort -u) + LVM_DEVICES=$(pvs --noheadings -o pv_name 2> >(grep -v 'File descriptor .* leaked') | xargs -n1 readlink -f | sort -u) + + RAID_ACTIVE=$(grep -Po 'md\d+\s*:\s*active\s+raid[0-9]+' /proc/mdstat | awk '{print $1}' | sort -u) + + while read -r DISK; do + [[ "$DISK" =~ /dev/zd ]] && continue + + INFO=($(lsblk -dn -o MODEL,SIZE "$DISK")) + MODEL="${INFO[@]::${#INFO[@]}-1}" + SIZE="${INFO[-1]}" + LABEL="" + SHOW_DISK=true + + IS_MOUNTED=false + IS_RAID=false + IS_ZFS=false + IS_LVM=false + + while read -r part fstype; do + [[ "$fstype" == "zfs_member" ]] && IS_ZFS=true + [[ "$fstype" == "linux_raid_member" ]] && IS_RAID=true + [[ "$fstype" == "LVM2_member" ]] && IS_LVM=true + if grep -q "/dev/$part" <<< "$MOUNTED_DISKS"; then + IS_MOUNTED=true + fi + done < <(lsblk -ln -o NAME,FSTYPE "$DISK" | tail -n +2) + + REAL_PATH=$(readlink -f "$DISK") + if echo "$LVM_DEVICES" | grep -qFx "$REAL_PATH"; then + IS_MOUNTED=true + fi + + USED_BY="" + REAL_PATH=$(readlink -f "$DISK") + CONFIG_DATA=$(cat /etc/pve/qemu-server/*.conf /etc/pve/lxc/*.conf 2>/dev/null) + + if grep -Fq "$REAL_PATH" <<< "$CONFIG_DATA"; then + USED_BY="⚠ $(translate "In use")" + else + for SYMLINK in /dev/disk/by-id/*; do + if [[ "$(readlink -f "$SYMLINK")" == "$REAL_PATH" ]]; then + if grep -Fq "$SYMLINK" <<< "$CONFIG_DATA"; then + USED_BY="⚠ $(translate "In use")" + break + fi + fi + done + fi + + if $IS_RAID && grep -q "$DISK" <<< "$(cat /proc/mdstat)" && grep -q "active raid" /proc/mdstat; then + SHOW_DISK=false + fi + + if $IS_ZFS || $IS_MOUNTED || [[ "$ZFS_DISKS" == *"$DISK"* ]]; then + SHOW_DISK=false + fi + + if $SHOW_DISK; then + [[ -n "$USED_BY" ]] && LABEL+=" [$USED_BY]" + [[ "$IS_RAID" == true ]] && LABEL+=" ⚠ RAID" + [[ "$IS_LVM" == true ]] && LABEL+=" ⚠ LVM" + [[ "$IS_ZFS" == true ]] && LABEL+=" ⚠ ZFS" + DESCRIPTION=$(printf "%-30s %10s%s" "$MODEL" "$SIZE" "$LABEL") + FREE_DISKS+=("$DISK" "$DESCRIPTION" "OFF") + fi + done < <(lsblk -dn -e 7,11 -o PATH) + + + if [ "${#FREE_DISKS[@]}" -eq 0 ]; then + cleanup + whiptail --title "Error" --msgbox "$(translate "No disks available for this VM.")" 8 40 + select_disk_type + return + fi + + MAX_WIDTH=$(printf "%s\n" "${FREE_DISKS[@]}" | awk '{print length}' | sort -nr | head -n1) + TOTAL_WIDTH=$((MAX_WIDTH + 20)) + [ $TOTAL_WIDTH -lt 50 ] && TOTAL_WIDTH=50 + cleanup + SELECTED_DISKS=$(whiptail --title "Select Disks" --checklist \ + "$(translate "Select the disks you want to use (use spacebar to select):")" 20 $TOTAL_WIDTH 10 \ + "${FREE_DISKS[@]}" 3>&1 1>&2 2>&3) + + if [ -z "$SELECTED_DISKS" ]; then + msg_error "Disk not specified. At least one disk is required." + sleep 2 + select_disk_type + return + fi + + + msg_ok "Disk passthrough selected:" + PASSTHROUGH_DISKS=() + for DISK in $(echo "$SELECTED_DISKS" | tr -d '"'); do + DISK_INFO=$(lsblk -ndo MODEL,SIZE "$DISK" | xargs) + echo -e "${TAB}${CL}${BL}- $DISK $DISK_INFO${GN}${CL}" + PASSTHROUGH_DISKS+=("$DISK") + done + + +} +# ========================================================== \ No newline at end of file diff --git a/scripts/test/vm/guest_agent_config.sh b/scripts/test/vm/guest_agent_config.sh new file mode 100644 index 0000000..92cb0f8 --- /dev/null +++ b/scripts/test/vm/guest_agent_config.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# ========================================================== +# Guest Agent Configurator - ProxMenux +# ========================================================== +# Añade soporte al QEMU Guest Agent y dispositivos útiles. +# Se adapta según el sistema operativo. +# ========================================================== + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + + + +function configure_guest_agent() { + if [[ -z "$VMID" ]]; then + msg_error "$(translate "No VMID defined. Cannot apply guest agent config.")" + return 1 + fi + + msg_info "$(translate "Adding QEMU Guest Agent support...")" + + # Habilitar el agente en la VM + qm set "$VMID" -agent enabled=1 >/dev/null 2>&1 + + # Añadir canal de comunicación virtio + qm set "$VMID" -chardev socket,id=qga0,path=/var/run/qemu-server/$VMID.qga,server=on,wait=off >/dev/null 2>&1 + qm set "$VMID" -device virtio-serial-pci -device virtserialport,chardev=qga0,name=org.qemu.guest_agent.0 >/dev/null 2>&1 + + msg_ok "$(translate "Guest Agent configuration applied")" + + if [[ "$OS_TYPE" == "windows" ]]; then + echo -e "${YW}$(translate "Reminder: You must install the QEMU Guest Agent inside the Windows VM")${NC}" + echo -e "${YW}$(translate "Tip: Also mount the VirtIO ISO for drivers and guest agent installer")${NC}" + echo -e "${TAB}- https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/" + elif [[ "$OS_TYPE" == "linux" || "$OS_TYPE" == "lite" ]]; then + echo -e "${YW}$(translate "Tip: You can install the QEMU Guest Agent inside the VM with:")${NC}" + echo -e "${TAB}apt install qemu-guest-agent -y && systemctl enable --now qemu-guest-agent" + fi +} + diff --git a/scripts/test/linux_4.sh b/scripts/test/vm/select_linux_iso.sh similarity index 74% rename from scripts/test/linux_4.sh rename to scripts/test/vm/select_linux_iso.sh index 03133a7..5ca2e49 100644 --- a/scripts/test/linux_4.sh +++ b/scripts/test/vm/select_linux_iso.sh @@ -1,20 +1,28 @@ -#!/bin/bash +#!/usr/bin/env bash + +# ============================================================== +# ProxMenux - Linux ISO Selector (No download yet) +# ============================================================== + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + + + +function select_linux_iso() { ISO_DIR="/var/lib/vz/template/iso" mkdir -p "$ISO_DIR" -# Comprobar dependencias necesarias -REQUIRED_PACKAGES=(curl wget whiptail) -MISSING="" -for pkg in "${REQUIRED_PACKAGES[@]}"; do - dpkg -s $pkg &>/dev/null || MISSING+="$pkg " -done -if [ -n "$MISSING" ]; then - echo "Instalando dependencias necesarias: $MISSING" - apt update && apt install -y $MISSING -fi -# Menú combinado único con fuente de origen DISTROS=( "Ubuntu 22.04 LTS Desktop|Desktop|ProxMenux|https://releases.ubuntu.com/22.04/ubuntu-22.04.4-desktop-amd64.iso" "Ubuntu 20.04 LTS Desktop|Desktop|ProxMenux|https://releases.ubuntu.com/20.04/ubuntu-20.04.6-desktop-amd64.iso" @@ -42,44 +50,37 @@ DISTROS=( "Ubuntu 24.10 (automatizado)|Cloud-ini|Helper Scripts|https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/vm/ubuntu2410-vm.sh" ) -# Construir menú con alineación perfecta usando printf MENU_OPTIONS=() INDEX=0 for entry in "${DISTROS[@]}"; do IFS='|' read -r NAME TYPE SOURCE URL <<< "$entry" - LINE=$(printf "%-35s │ %-12s │ %s" "$NAME" "$TYPE" "$SOURCE") + LINE=$(printf "%-35s │ %-10s │ %s" "$NAME" "$TYPE" "$SOURCE") MENU_OPTIONS+=("$INDEX" "$LINE") URLS[$INDEX]="$entry" ((INDEX++)) done -HEADER="%-41s │ %-12s │ %s" +HEADER="%-41s │ %-10s │ %s" HEADER_TEXT=$(printf "$HEADER" " Versión" "Tipo" "Fuente") -CHOICE=$(whiptail --title "Instalación Linux" \ - --menu "Selecciona la distribución que deseas instalar o descargar: - -$HEADER_TEXT" 20 80 10 \ +CHOICE=$(whiptail --title "ProxMenux - Linux ISO" \ + --menu "$(translate "Select the Linux distribution to install"):\n\n$HEADER_TEXT" 20 80 10 \ "${MENU_OPTIONS[@]}" \ 3>&1 1>&2 2>&3) -[ $? -ne 0 ] && echo "Cancelado." && exit 1 +[[ $? -ne 0 ]] && echo "Cancelled" && exit 1 SELECTED="${URLS[$CHOICE]}" -IFS='|' read -r NAME TYPE SOURCE URL <<< "$SELECTED" +IFS='|' read -r ISO_NAME ISO_TYPE SOURCE ISO_URL <<< "$SELECTED" +ISO_FILE=$(basename "$ISO_URL") +ISO_PATH="$ISO_DIR/$ISO_FILE" -if [[ "$TYPE" == "Automatizado" ]]; then - echo "Ejecutando script remoto para: $NAME" - bash -c "$(curl -fsSL $URL)" -else - FILENAME=$(basename "$URL") - if [ -f "$ISO_DIR/$FILENAME" ]; then - echo "ℹ️ La imagen ya existe: $ISO_DIR/$FILENAME" - else - echo "⬇️ Descargando $NAME..." - # wget -O "$ISO_DIR/$FILENAME" "$URL" - wget -q --show-progress -O "$ISO_DIR/$FILENAME" "$URL" - - fi - echo "✅ Imagen lista: $ISO_DIR/$FILENAME" -fi \ No newline at end of file +# Exportar para que los use el script principal +export ISO_NAME +export ISO_TYPE +export ISO_URL +export ISO_FILE +export ISO_PATH + + +} \ No newline at end of file diff --git a/scripts/test/vm/select_nas_iso.sh b/scripts/test/vm/select_nas_iso.sh new file mode 100644 index 0000000..2c79c96 --- /dev/null +++ b/scripts/test/vm/select_nas_iso.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env bash + +# ============================================================== +# ProxMenux - NAS ISO Selector +# ============================================================== + +# Configuracion Base +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + +ISO_DIR="/var/lib/vz/template/iso" +mkdir -p "$ISO_DIR" + +function select_nas_iso() { + + NAS_OPTIONS=( + "1" "$(translate "Synology DSM VM")" + "2" "$(translate "TrueNAS SCALE VM 24.04.2.5") (Dragonfish)" + "3" "$(translate "TrueNAS CORE VM (FreeBSD based)")" + "4" "$(translate "OpenMediaVault VM (Debian based)")" + "5" "$(translate "Rockstor VM (openSUSE based)")" + ) + + NAS_TYPE=$(whiptail --title "ProxMenux - NAS Systems" --menu "$(translate "Select the NAS system to install")" 20 70 6 \ + "${NAS_OPTIONS[@]}" 3>&1 1>&2 2>&3) + + [[ $? -ne 0 ]] && echo "Cancelled." && exit 1 + + case "$NAS_TYPE" in + 1) + bash <(curl -s "https://raw.githubusercontent.com/MacRimi/ProxMenux/main/scripts/vm/synology.sh") + exit 0 + ;; + 2) + ISO_NAME="TrueNAS SCALE 24.04.2.5 (Dragonfish)" + ISO_URL="https://download.truenas.com/TrueNAS-SCALE-Dragonfish/24.04.2.5/TrueNAS-SCALE-24.04.2.5.iso" + ISO_FILE="TrueNAS-SCALE-24.04.2.5.iso" + ISO_PATH="$ISO_DIR/$ISO_FILE" + ;; + 3) + LATEST_ISO=$(wget -qO- https://download.freenas.org/latest/x64/ | grep -oP 'href="\K[^"]+\.iso' | head -n1) + ISO_NAME="TrueNAS CORE (Latest)" + ISO_URL="https://download.freenas.org/latest/x64/$LATEST_ISO" + ISO_FILE=$(basename "$LATEST_ISO") + ISO_PATH="$ISO_DIR/$ISO_FILE" + ;; + 4) + ISO_NAME="OpenMediaVault" + ISO_URL="https://downloads.sourceforge.net/project/openmediavault/7.2.0/openmediavault_7.2.0-amd64.iso" + ISO_FILE="openmediavault_7.2.0-amd64.iso" + ISO_PATH="$ISO_DIR/$ISO_FILE" + ;; + 5) + ISO_NAME="Rockstor" + ISO_URL="https://rockstor.com/downloads/installer/leap/15.6/x86_64/Rockstor-Leap15.6-generic.x86_64-5.0.15-0.install.iso" + ISO_FILE="Rockstor-Leap15.6-generic.x86_64-5.0.15-0.install.iso" + ISO_PATH="$ISO_DIR/$ISO_FILE" + ;; + esac + + export ISO_NAME + export ISO_URL + export ISO_FILE + export ISO_PATH +} diff --git a/scripts/test/vm/select_windows_iso.sh b/scripts/test/vm/select_windows_iso.sh new file mode 100644 index 0000000..e46c319 --- /dev/null +++ b/scripts/test/vm/select_windows_iso.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash + +# ============================================================== +# ProxMenux - Windows ISO Selector +# ============================================================== + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + +ISO_DIR="/var/lib/vz/template/iso" +mkdir -p "$ISO_DIR" + + + + +function select_windows_iso() { + local CHOICE=$(whiptail --title "ProxMenux - Windows ISO" --menu "$(translate "Select how to provide the Windows ISO")" 15 60 2 \ + "1" "$(translate "Use existing ISO from storage")" \ + "2" "$(translate "Download ISO using UUP Dump")" 3>&1 1>&2 2>&3) + + [[ $? -ne 0 ]] && msg_error "$(translate "Operation cancelled.")" && exit 1 + + case "$CHOICE" in + 1) + select_existing_iso + ;; + 2) + if [[ -f ./uupdump_creator.sh ]]; then + source ./uupdump_creator.sh + run_uupdump_creator || exit 1 + detect_latest_iso_created + else + msg_error "$(translate "UUP Dump script not found.")" + exit 1 + fi + ;; + esac +} + +function select_existing_iso() { + ISO_LIST=() + while read -r line; do + FILENAME=$(basename "$line") + SIZE=$(du -h "$line" | cut -f1) + ISO_LIST+=("$FILENAME" "$SIZE") + done < <(find "$ISO_DIR" -type f -iname "*.iso" ! -iname "virtio*" | sort) + + if [[ ${#ISO_LIST[@]} -eq 0 ]]; then + msg_error "$(translate "No ISO images found in $ISO_DIR.")" + exit 1 + fi + + ISO_FILE=$(whiptail --title "ProxMenux - Windows ISO" --menu "$(translate "Choose a Windows ISO to use:")" 20 70 10 "${ISO_LIST[@]}" 3>&1 1>&2 2>&3) + + if [[ -z "$ISO_FILE" ]]; then + msg_error "$(translate "No ISO selected.")" + exit 1 + fi + + ISO_PATH="$ISO_DIR/$ISO_FILE" + ISO_NAME="$ISO_FILE" + + export ISO_PATH ISO_FILE ISO_NAME +} + + + + +function detect_latest_iso_created() { + ISO_FILE=$(find "$ISO_DIR" -maxdepth 1 -type f -iname "*.iso" ! -iname "virtio*" -printf "%T@ %p\n" | sort -n | awk '{print $2}' | tail -n 1) + + if [[ -z "$ISO_FILE" ]]; then + msg_error "$(translate "No ISO file detected after UUP Dump process.")" + exit 1 + fi + + ISO_NAME=$(basename "$ISO_FILE") + ISO_PATH="$ISO_FILE" + + export ISO_PATH ISO_FILE ISO_NAME +} + diff --git a/scripts/test/vm/uupdump_creator.sh b/scripts/test/vm/uupdump_creator.sh new file mode 100644 index 0000000..731fe28 --- /dev/null +++ b/scripts/test/vm/uupdump_creator.sh @@ -0,0 +1,139 @@ +#!/usr/bin/env bash + +# ============================================================== +# ProxMenux - Windows ISO Creator from UUP Dump +# ============================================================== + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + +function run_uupdump_creator() { + +clear +show_proxmenux_logo + +# Configuración de carpetas +TMP_DIR="/root/uup-temp" +OUT_DIR="/var/lib/vz/template/iso" +CONVERTER="/root/uup-converter" + +mkdir -p "$TMP_DIR" "$OUT_DIR" +cd "$TMP_DIR" || exit 1 + +# Solicitar URL UUP Dump al usuario +UUP_URL=$(whiptail --inputbox "$(translate "Paste the UUP Dump URL here")" 10 90 3>&1 1>&2 2>&3) +[[ $? -ne 0 ]] && msg_error "$(translate "Cancelled by user.")" && exit 1 + +# Validar que la URL tenga los parámetros necesarios +if [[ ! "$UUP_URL" =~ id=.+\&pack=.+\&edition=.+ ]]; then + msg_error "$(translate "The URL does not contain the required parameters (id, pack, edition).")" + exit 1 +fi + +# Extraer parámetros de la URL +BUILD_ID=$(echo "$UUP_URL" | grep -oP 'id=\K[^&]+') +LANG=$(echo "$UUP_URL" | grep -oP 'pack=\K[^&]+') +EDITION=$(echo "$UUP_URL" | grep -oP 'edition=\K[^&]+') +ARCH="amd64" + +echo -e "\n${BGN}=============== UUP Dump Creator ===============${CL}" +echo -e " ${BGN}🆔 ID:${CL} ${DGN}$BUILD_ID${CL}" +echo -e " ${BGN}🌐 Language:${CL} ${DGN}$LANG${CL}" +echo -e " ${BGN}💿 Edition:${CL} ${DGN}$EDITION${CL}" +echo -e " ${BGN}🖥️ Architecture:${CL} ${DGN}$ARCH${CL}" +echo -e "${BGN}===============================================${CL}\n" + +# Descargar el conversor si no existe +if [[ ! -f "$CONVERTER/convert.sh" ]]; then + echo "📦 $(translate "Downloading UUP converter...")" + mkdir -p "$CONVERTER" + cd "$CONVERTER" || exit 1 + wget -q https://git.uupdump.net/uup-dump/converter/archive/refs/heads/master.tar.gz -O converter.tar.gz + tar -xzf converter.tar.gz --strip-components=1 + chmod +x convert.sh + cd "$TMP_DIR" || exit 1 +fi + +# Crear script de descarga uup_download_linux.sh +cat > uup_download_linux.sh < files/converter_multi + +for prog in aria2c cabextract wimlib-imagex chntpw; do + which \$prog &>/dev/null || { echo "\$prog not found."; exit 1; } +done +which genisoimage &>/dev/null || which mkisofs &>/dev/null || { echo "genisoimage/mkisofs not found."; exit 1; } + +destDir="UUPs" +tempScript="aria2_script.\$RANDOM.txt" + +aria2c --no-conf --console-log-level=warn --log-level=info --log="aria2_download.log" \ + -x16 -s16 -j2 --allow-overwrite=true --auto-file-renaming=false -d"files" -i"files/converter_multi" || exit 1 + +aria2c --no-conf --console-log-level=warn --log-level=info --log="aria2_download.log" \ + -o"\$tempScript" --allow-overwrite=true --auto-file-renaming=false \ + "https://uupdump.net/get.php?id=$BUILD_ID&pack=$LANG&edition=$EDITION&aria2=2" || exit 1 + +grep '#UUPDUMP_ERROR:' "\$tempScript" && { echo "❌ Error generating UUP download list."; exit 1; } + +aria2c --no-conf --console-log-level=warn --log-level=info --log="aria2_download.log" \ + -x16 -s16 -j5 -c -R -d"\$destDir" -i"\$tempScript" || exit 1 +EOF + +chmod +x uup_download_linux.sh + +# Ejecutar la descarga de archivos UUP +./uup_download_linux.sh + +# Buscar carpeta UUPs descargada +UUP_FOLDER=$(find "$TMP_DIR" -type d -name "UUPs" | head -n1) +[[ -z "$UUP_FOLDER" ]] && msg_error "$(translate "No UUP folder found.")" && exit 1 + +# Iniciar conversión a ISO +echo -e "\n${GN}=======================================${CL}" +echo -e " 💿 ${GN}Starting ISO conversion...${CL}" +echo -e "${GN}=======================================${CL}\n" + +"$CONVERTER/convert.sh" wim "$UUP_FOLDER" 1 + +# Buscar la ISO generada +ISO_FILE=$(find "$TMP_DIR" "$CONVERTER" "$UUP_FOLDER" -maxdepth 1 -iname "*.iso" | head -n1) +if [[ -f "$ISO_FILE" ]]; then + mv "$ISO_FILE" "$OUT_DIR/" + msg_ok "$(translate "ISO created successfully:") $OUT_DIR/$(basename "$ISO_FILE")" + + # Limpiar temporales + msg_ok "$(translate "Cleaning temporary files...")" + rm -rf "$TMP_DIR" "$CONVERTER" + + export LANGUAGE=C + export LANG=C + export LC_ALL=C + load_language + initialize_cache + + msg_success "$(translate "Press Enter to return to menu...")" + read -r +else + msg_warn "$(translate "No ISO was generated.")" + + export LANGUAGE=C + export LANG=C + export LC_ALL=C + load_language + initialize_cache + + msg_success "$(translate "Press Enter to return to menu...")" + read -r +fi + +} \ No newline at end of file diff --git a/scripts/test/vm/vm_configurator.sh b/scripts/test/vm/vm_configurator.sh new file mode 100644 index 0000000..88a9761 --- /dev/null +++ b/scripts/test/vm/vm_configurator.sh @@ -0,0 +1,191 @@ +#!/usr/bin/env bash + +# ================================================ +# VM Configuration Module - ProxMenux +# ================================================ + + + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + + + +function generate_mac() { + local GEN_MAC="02" + for i in {1..5}; do + BYTE=$(printf "%02X" $((RANDOM % 256))) + GEN_MAC="${GEN_MAC}:${BYTE}" + done + echo "$GEN_MAC" +} + +function load_default_vm_config() { + local os_type="$1" + + VMID=$(pvesh get /cluster/nextid 2>/dev/null || echo "100") + MAC=$(generate_mac) + + case "$os_type" in + "nas") + HN="synology-nas" + CORE_COUNT="2" + RAM_SIZE="8192" + MACHINE=" -machine q35" + BIOS_TYPE=" -bios ovmf" + START_VM="no" + ;; + "windows") + HN="windows-vm" + CORE_COUNT="4" + RAM_SIZE="8192" + MACHINE=" -machine q35" + BIOS_TYPE=" -bios ovmf" + START_VM="no" + ;; + "linux") + HN="linux-vm" + CORE_COUNT="2" + RAM_SIZE="4096" + MACHINE=" -machine q35" + BIOS_TYPE=" -bios ovmf" + START_VM="no" + ;; + "lite") + HN="lite-vm" + CORE_COUNT="1" + RAM_SIZE="2048" + MACHINE="" + BIOS_TYPE=" -bios seabios" + START_VM="no" + ;; + *) + HN="vm-proxmenux" + CORE_COUNT="2" + RAM_SIZE="2048" + MACHINE=" -machine q35" + BIOS_TYPE=" -bios ovmf" + START_VM="no" + ;; + esac + + CPU_TYPE=" -cpu host" + BRG="vmbr0" + VLAN="" + MTU="" + SERIAL_PORT="socket" + FORMAT="" + DISK_CACHE="" +} + +function apply_default_vm_config() { + echo -e "${DEF}$(translate "Applying default VM configuration")${CL}" + echo -e "${DGN}$(translate "Virtual Machine ID")${CL}: ${BGN}$VMID${CL}" + echo -e "${DGN}$(translate "Hostname")${CL}: ${BGN}$HN${CL}" + echo -e "${DGN}$(translate "CPU Cores")${CL}: ${BGN}$CORE_COUNT${CL}" + echo -e "${DGN}$(translate "RAM Size")${CL}: ${BGN}$RAM_SIZE MiB${CL}" + echo -e "${DGN}$(translate "Machine Type")${CL}: ${BGN}${MACHINE/ -machine /}${CL}" + echo -e "${DGN}$(translate "BIOS Type")${CL}: ${BGN}${BIOS_TYPE/ -bios /}${CL}" + echo -e "${DGN}$(translate "CPU Model")${CL}: ${BGN}${CPU_TYPE/ -cpu /}${CL}" + echo -e "${DGN}$(translate "Network Bridge")${CL}: ${BGN}$BRG${CL}" + echo -e "${DGN}$(translate "MAC Address")${CL}: ${BGN}$MAC${CL}" + echo -e "${DGN}$(translate "Start VM after creation")${CL}: ${BGN}$START_VM${CL}" + echo -e +} + + + +function configure_vm_advanced() { + # VMID + while true; do + VMID=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Set Virtual Machine ID")" 8 58 "$VMID" --title "VM ID" 3>&1 1>&2 2>&3) || return + if [ -z "$VMID" ]; then continue; fi + if qm status "$VMID" &>/dev/null || pct status "$VMID" &>/dev/null; then + msg_error "$(translate "ID already in use. Please choose another.")" + else + break + fi + done + + # Hostname + HN=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Set Hostname")" 8 58 "$HN" --title "Hostname" 3>&1 1>&2 2>&3) || return + [[ -z "$HN" ]] && HN="vm-proxmenux" + + # Machine Type + MACHINE_TYPE=$(whiptail --backtitle "ProxMenux" --title "$(translate "MACHINE TYPE")" --radiolist \ + "$(translate "Select machine type")" 10 60 2 \ + "q35" "QEMU q35" ON \ + "i440fx" "Legacy i440fx" OFF 3>&1 1>&2 2>&3) || return + + if [ "$MACHINE_TYPE" = "q35" ]; then + MACHINE=" -machine q35" + FORMAT="" + else + MACHINE="" + FORMAT=",efitype=4m" + fi + + # BIOS + BIOS=$(whiptail --backtitle "ProxMenux" --title "$(translate "BIOS TYPE")" --radiolist \ + "$(translate "Choose BIOS type")" 10 60 2 \ + "ovmf" "UEFI (OVMF)" ON \ + "seabios" "Legacy BIOS (SeaBIOS)" OFF 3>&1 1>&2 2>&3) || return + + BIOS_TYPE=" -bios $BIOS" + + # CPU Type + CPU_CHOICE=$(whiptail --backtitle "ProxMenux" --title "$(translate "CPU MODEL")" --radiolist \ + "$(translate "Select CPU model")" 10 60 2 \ + "host" "Host (recommended)" ON \ + "kvm64" "Generic KVM64" OFF 3>&1 1>&2 2>&3) || return + + if [ "$CPU_CHOICE" = "host" ]; then + CPU_TYPE=" -cpu host" + else + CPU_TYPE=" -cpu kvm64" + fi + + # Core Count + CORE_COUNT=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Number of CPU cores")" 8 58 "$CORE_COUNT" --title "CPU Cores" 3>&1 1>&2 2>&3) || return + + # RAM + RAM_SIZE=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Amount of RAM in MiB")" 8 58 "$RAM_SIZE" --title "RAM" 3>&1 1>&2 2>&3) || return + + # Bridge + BRG=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Set network bridge")" 8 58 "$BRG" --title "Network Bridge" 3>&1 1>&2 2>&3) || return + + # MAC + MAC_INPUT=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Set MAC Address (leave empty for random)")" 8 58 "$MAC" --title "MAC Address" 3>&1 1>&2 2>&3) || return + if [[ -z "$MAC_INPUT" ]]; then + MAC=$(generate_mac) + else + MAC="$MAC_INPUT" + fi + + # VLAN + VLAN_INPUT=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Set VLAN Tag (leave empty for none)")" 8 58 --title "VLAN" 3>&1 1>&2 2>&3) || return + VLAN="" + [[ -n "$VLAN_INPUT" ]] && VLAN=",tag=$VLAN_INPUT" + + # MTU + MTU_INPUT=$(whiptail --backtitle "ProxMenux" --inputbox "$(translate "Set MTU size (leave empty for default)")" 8 58 --title "MTU" 3>&1 1>&2 2>&3) || return + MTU="" + [[ -n "$MTU_INPUT" ]] && MTU=",mtu=$MTU_INPUT" + + # Start VM + if (whiptail --backtitle "ProxMenux" --title "$(translate "START VM")" --yesno "$(translate "Start VM when finished?")" 10 60); then + START_VM="yes" + else + START_VM="no" + fi + + msg_ok "$(translate "Advanced configuration completed.")" +} diff --git a/scripts/test/vm/vm_creator.sh b/scripts/test/vm/vm_creator.sh new file mode 100644 index 0000000..63959c5 --- /dev/null +++ b/scripts/test/vm/vm_creator.sh @@ -0,0 +1,310 @@ +#!/usr/bin/env bash + +# ========================================================== +# VM Creator Module - ProxMenux +# ========================================================== +# Este módulo recibe las variables globales y crea la VM +# con su configuración, discos y descripción. +# ========================================================== + +BASE_DIR="/usr/local/share/proxmenux" +UTILS_FILE="$BASE_DIR/utils.sh" +VENV_PATH="/opt/googletrans-env" + +if [[ -f "$UTILS_FILE" ]]; then + source "$UTILS_FILE" +fi + +load_language +initialize_cache + +# ========================================================== +# Función para montar ISOs +# ========================================================== +function mount_iso_to_vm() { + local vmid="$1" + local iso_path="$2" + local device="$3" + + if [[ -f "$iso_path" ]]; then + local iso_basename + iso_basename=$(basename "$iso_path") + qm set "$vmid" -$device "local:iso/$iso_basename,media=cdrom" >/dev/null 2>&1 + msg_ok "$(translate "Mounted ISO on device") $device → $iso_basename" + else + msg_warn "$(translate "ISO not found to mount on device") $device" + fi +} + + + + +# ========================================================== +# Select Interface Type +# ========================================================== +function select_interface_type() { + INTERFACE_TYPE=$(whiptail --backtitle "ProxMenux" --title "$(translate "Select Disk Interface")" --radiolist \ + "$(translate "Select the bus type for the disks:")" 15 70 4 \ + "scsi" "$(translate "SCSI (recommended for Linux and Windows)")" ON \ + "sata" "$(translate "SATA (standard - high compatibility)")" OFF \ + "virtio" "$(translate "VirtIO (advanced - high performance)")" OFF \ + "ide" "IDE (legacy)" OFF \ + 3>&1 1>&2 2>&3) || exit 1 + + case "$INTERFACE_TYPE" in + "scsi"|"sata") + DISCARD_OPTS=",discard=on,ssd=on" + ;; + "virtio") + DISCARD_OPTS=",discard=on" + ;; + "ide") + DISCARD_OPTS="" + ;; + esac + + msg_ok "$(translate "Disk interface selected:") $INTERFACE_TYPE" +} + + +# ========================================================== +# Función principal para crear la VM +# ========================================================== +function create_vm() { + local BOOT_ORDER="" + local DISK_INFO="" + local DISK_INDEX=0 + local ISO_DIR="/var/lib/vz/template/iso" + + + # Descargar ISO si es necesario + if [[ -n "$ISO_PATH" && -n "$ISO_URL" && ! -f "$ISO_PATH" ]]; then + wget --no-verbose --show-progress -O "$ISO_PATH" "$ISO_URL" + if [[ -f "$ISO_PATH" ]]; then + msg_ok "$(translate "ISO image downloaded")" + else + msg_error "$(translate "Failed to download ISO image")" + return + fi + fi + + + # Crear la VM base primero (mínima) + qm create "$VMID" -agent 1${MACHINE} -tablet 0 -localtime 1${BIOS_TYPE}${CPU_TYPE} \ + -cores "$CORE_COUNT" -memory "$RAM_SIZE" -name "$HN" -tags proxmenux \ + -net0 "virtio,bridge=$BRG,macaddr=$MAC$VLAN$MTU" -ostype l26 \ + -scsihw virtio-scsi-pci -serial0 "$SERIAL_PORT" + msg_ok "$(translate "Base VM created with ID") $VMID" + + + # Crear disco EFI si corresponde + if [[ "$BIOS_TYPE" == *"ovmf"* ]]; then + msg_info "$(translate "Configuring EFI disk")" + EFI_STORAGE=$(select_efi_storage "$VMID") + EFI_DISK_NAME="vm-${VMID}-disk-efivars" + + STORAGE_TYPE=$(pvesm status -storage "$EFI_STORAGE" | awk 'NR>1 {print $2}') + case "$STORAGE_TYPE" in + nfs | dir) + EFI_DISK_EXT=".raw" + EFI_DISK_REF="$VMID/" + ;; + *) + EFI_DISK_EXT="" + EFI_DISK_REF="" + ;; + esac + + if pvesm alloc "$EFI_STORAGE" "$VMID" "$EFI_DISK_NAME$EFI_DISK_EXT" 4M >/dev/null 2>&1; then + if qm set "$VMID" -efidisk0 "$EFI_STORAGE:${EFI_DISK_REF}$EFI_DISK_NAME$EFI_DISK_EXT,pre-enrolled-keys=0" >/dev/null 2>&1; then + msg_ok "$(translate "EFI disk created and configured on") $EFI_STORAGE" + else + msg_error "$(translate "Failed to configure EFI disk")" + fi + else + msg_error "$(translate "Failed to create EFI disk")" + fi + fi + + + + +# ========================================================== +# Crear discos virtuales o físicos con interfaz seleccionada +# ========================================================== + +# Primero seleccionar la interfaz +select_interface_type + + if [[ "$DISK_TYPE" == "virtual" && ${#VIRTUAL_DISKS[@]} -gt 0 ]]; then + for i in "${!VIRTUAL_DISKS[@]}"; do + DISK_INDEX=$((i+1)) + IFS=':' read -r STORAGE SIZE <<< "${VIRTUAL_DISKS[$i]}" + DISK_NAME="vm-${VMID}-disk-${DISK_INDEX}" + SLOT_NAME="${INTERFACE_TYPE}${i}" + + STORAGE_TYPE=$(pvesm status -storage "$STORAGE" | awk 'NR>1 {print $2}') + case "$STORAGE_TYPE" in + dir|nfs) + DISK_EXT=".raw" + DISK_REF="$VMID/" + ;; + *) + DISK_EXT="" + DISK_REF="" + ;; + esac + + if pvesm alloc "$STORAGE" "$VMID" "$DISK_NAME$DISK_EXT" "$SIZE"G >/dev/null 2>&1; then + qm set "$VMID" -$SLOT_NAME "$STORAGE:${DISK_REF}${DISK_NAME}${DISK_EXT}${DISCARD_OPTS}" >/dev/null + msg_ok "$(translate "Virtual disk") $DISK_INDEX ${SIZE}GB - $STORAGE ($SLOT_NAME)" + DISK_INFO+="

Virtual Disk $DISK_INDEX: ${SIZE}GB ($STORAGE / $SLOT_NAME)

" + [[ -z "$BOOT_ORDER" ]] && BOOT_ORDER="$SLOT_NAME" + else + msg_error "$(translate "Failed to create disk") $DISK_INDEX" + fi + done + fi + + if [[ "$DISK_TYPE" == "passthrough" && ${#PASSTHROUGH_DISKS[@]} -gt 0 ]]; then + for i in "${!PASSTHROUGH_DISKS[@]}"; do + SLOT_NAME="${INTERFACE_TYPE}${i}" + DISK="${PASSTHROUGH_DISKS[$i]}" + MODEL=$(lsblk -ndo MODEL "$DISK") + SIZE=$(lsblk -ndo SIZE "$DISK") + qm set "$VMID" -$SLOT_NAME "$DISK${DISCARD_OPTS}" >/dev/null 2>&1 + msg_ok "$(translate "Passthrough disk assigned") ($DISK → $SLOT_NAME)" + DISK_INFO+="

Passthrough Disk $((i+1)): $DISK ($MODEL $SIZE)

" + [[ -z "$BOOT_ORDER" ]] && BOOT_ORDER="$SLOT_NAME" + done + fi + + + + + # Ahora montamos las ISOs + if [[ -f "$ISO_PATH" ]]; then + mount_iso_to_vm "$VMID" "$ISO_PATH" "ide2" + fi + + # Para Windows, preguntar y montar ISO VirtIO + if [[ "$OS_TYPE" == "windows" ]]; then + local VIRTIO_DIR="/var/lib/vz/template/iso" + local VIRTIO_SELECTED="" + local VIRTIO_DOWNLOAD_URL="https://fedorapeople.org/groups/virt/virtio-win/direct-downloads/stable-virtio/virtio-win.iso" + + while true; do + VIRTIO_OPTION=$(whiptail --title "ProxMenux - VirtIO Drivers" --menu "$(translate "Select how to provide VirtIO drivers")" 15 70 2 \ + "1" "$(translate "Download latest VirtIO ISO automatically")" \ + "2" "$(translate "Use existing VirtIO ISO from storage")" 3>&1 1>&2 2>&3) + + [[ $? -ne 0 ]] && msg_warn "$(translate "VirtIO ISO selection cancelled.")" && break + + case "$VIRTIO_OPTION" in + 1) + + if [[ -f "$VIRTIO_DIR/virtio-win.iso" ]]; then + if whiptail --title "ProxMenux" --yesno "$(translate "A VirtIO ISO already exists. Do you want to overwrite it?")" 10 60; then + wget -q --show-progress -O "$VIRTIO_DIR/virtio-win.iso" "$VIRTIO_DOWNLOAD_URL" + if [[ -f "$VIRTIO_DIR/virtio-win.iso" ]]; then + msg_ok "$(translate "VirtIO driver ISO downloaded successfully.")" + else + msg_error "$(translate "Failed to download VirtIO driver ISO.")" + fi + fi + else + wget -q --show-progress -O "$VIRTIO_DIR/virtio-win.iso" "$VIRTIO_DOWNLOAD_URL" + if [[ -f "$VIRTIO_DIR/virtio-win.iso" ]]; then + msg_ok "$(translate "VirtIO driver ISO downloaded successfully.")" + else + msg_error "$(translate "Failed to download VirtIO driver ISO.")" + fi + fi + + VIRTIO_SELECTED="$VIRTIO_DIR/virtio-win.iso" + ;; + 2) + + VIRTIO_LIST=() + while read -r line; do + FILENAME=$(basename "$line") + SIZE=$(du -h "$line" | cut -f1) + VIRTIO_LIST+=("$FILENAME" "$SIZE") + done < <(find "$VIRTIO_DIR" -type f -iname "virtio*.iso" | sort) + + if [[ ${#VIRTIO_LIST[@]} -eq 0 ]]; then + msg_warn "$(translate "No VirtIO ISO found. Please download one.")" + continue # Volver a preguntar + fi + + VIRTIO_FILE=$(whiptail --title "ProxMenux - VirtIO ISOs" --menu "$(translate "Select a VirtIO ISO to use:")" 20 70 10 "${VIRTIO_LIST[@]}" 3>&1 1>&2 2>&3) + + if [[ -n "$VIRTIO_FILE" ]]; then + VIRTIO_SELECTED="$VIRTIO_DIR/$VIRTIO_FILE" + else + msg_warn "$(translate "No VirtIO ISO selected. Please choose again.")" + continue + fi + ;; + esac + + if [[ -n "$VIRTIO_SELECTED" && -f "$VIRTIO_SELECTED" ]]; then + mount_iso_to_vm "$VMID" "$VIRTIO_SELECTED" "ide3" + else + msg_warn "$(translate "VirtIO ISO not found after selection.")" + fi + + break + done + fi + + + # Configurar el orden de arranque (primer disco, luego CD) + local BOOT_FINAL="$BOOT_ORDER" + [[ -f "$ISO_PATH" ]] && BOOT_FINAL="$BOOT_ORDER;ide2" + qm set "$VMID" -boot order="$BOOT_FINAL" >/dev/null + msg_ok "$(translate "Boot order set to") $BOOT_FINAL" + + # Crear descripción + local DESC="

$HN

Created with ProxMenux

$DISK_INFO
" + qm set "$VMID" -description "$DESC" >/dev/null + msg_ok "$(translate "VM description configured")" + + # Arrancar la VM si corresponde + if [[ "$START_VM" == "yes" ]]; then + qm start "$VMID" + msg_ok "$(translate "VM started")" + fi + + msg_success "$(translate "VM creation completed")" +} + + +# ========================================================== +# Función select_efi_storage (no cambia) +# ========================================================== +function select_efi_storage() { + local vmid=$1 + local STORAGE="" + + STORAGE_MENU=() + while read -r line; do + TAG=$(echo "$line" | awk '{print $1}') + TYPE=$(echo "$line" | awk '{printf "%-10s", $2}') + FREE=$(echo "$line" | numfmt --field 4-6 --from-unit=K --to=iec --format "%.2f" | awk '{printf("%9sB", $6)}') + STORAGE_MENU+=("$TAG" "Type: $TYPE Free: $FREE" "OFF") + done < <(pvesm status -content images | awk 'NR>1') + + if [ ${#STORAGE_MENU[@]} -eq 0 ]; then + msg_error "$(translate "Unable to detect a valid storage location for EFI disk.")" + exit 1 + elif [ $((${#STORAGE_MENU[@]} / 3)) -eq 1 ]; then + STORAGE=${STORAGE_MENU[0]} + else + STORAGE=$(whiptail --backtitle "ProxMenux" --title "$(translate "EFI Disk Storage")" --radiolist \ + "$(translate "Choose the storage volume for the EFI disk (4MB):")" 16 70 6 \ + "${STORAGE_MENU[@]}" 3>&1 1>&2 2>&3) || exit 1 + fi + + echo "$STORAGE" +}