2025-05-07 23:57:51 +02:00
#!/usr/bin/env bash
2025-03-23 17:50:33 +01:00
# ==========================================================
2025-05-07 23:57:51 +02:00
# ProxMenuX - Virtual Machine Creator Script
2025-03-23 17:50:33 +01:00
# ==========================================================
# Author : MacRimi
# Copyright : (c) 2024 MacRimi
2026-01-19 17:15:00 +01:00
# License : (GPL-3.0) (https://github.com/MacRimi/ProxMenux/blob/main/LICENSE)
2025-03-23 17:50:33 +01:00
# Version : 1.0
2025-05-07 23:57:51 +02:00
# Last Updated: 07/05/2025
2025-03-23 17:50:33 +01:00
# ==========================================================
2025-05-07 23:57:51 +02:00
# Description:
# This script is part of the central ProxMenux VM creation module. It allows users
# to create virtual machines (VMs) in Proxmox VE using either default or advanced
# configurations, streamlining the deployment of Linux, Windows, and other systems.
#
# Key features:
2026-04-05 11:24:08 +02:00
# - Supports virtual disks, import disks, and Controller + NVMe passthrough.
2025-05-07 23:57:51 +02:00
# - Automates CPU, RAM, BIOS, network and storage configuration.
# - Provides a user-friendly menu to select OS type, ISO image and disk interface.
# - Automatically generates a detailed and styled HTML description for each VM.
#
# All operations are designed to simplify and accelerate VM creation in a
# consistent and maintainable way, using ProxMenux standards.
# ==========================================================
2026-04-05 11:24:08 +02:00
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0] } " ) " && pwd ) "
LOCAL_SCRIPTS_DEFAULT = "/usr/local/share/proxmenux/scripts"
LOCAL_SCRIPTS_LOCAL = " $( cd " $SCRIPT_DIR /.. " && pwd ) "
2025-03-23 17:50:33 +01:00
2026-04-05 11:24:08 +02:00
if [ [ -f " $LOCAL_SCRIPTS_LOCAL /vm/disk_selector.sh " ] ] ; then
LOCAL_SCRIPTS = " $LOCAL_SCRIPTS_LOCAL "
else
LOCAL_SCRIPTS = " $LOCAL_SCRIPTS_DEFAULT "
fi
2025-03-23 17:50:33 +01:00
2025-11-03 00:46:23 +00:00
VM_REPO = " $LOCAL_SCRIPTS /vm "
ISO_REPO = " $LOCAL_SCRIPTS /vm "
MENU_REPO = " $LOCAL_SCRIPTS /menus "
2025-03-23 17:50:33 +01:00
BASE_DIR = "/usr/local/share/proxmenux"
2026-04-05 11:24:08 +02:00
UTILS_FILE = " $LOCAL_SCRIPTS /utils.sh "
[ [ ! -f " $UTILS_FILE " ] ] && UTILS_FILE = " $BASE_DIR /utils.sh "
2025-03-23 17:50:33 +01:00
VENV_PATH = "/opt/googletrans-env"
2025-11-03 00:46:23 +00:00
# Source utilities and required scripts
2025-03-23 17:50:33 +01:00
if [ [ -f " $UTILS_FILE " ] ] ; then
source " $UTILS_FILE "
2025-11-03 00:46:23 +00:00
else
echo " Error: $UTILS_FILE not found "
exit 1
2025-03-23 17:50:33 +01:00
fi
2025-05-07 23:57:51 +02:00
2025-03-23 17:50:33 +01:00
load_language
initialize_cache
2025-05-07 23:57:51 +02:00
2025-11-03 00:46:23 +00:00
# Source VM management scripts
[ [ -f " $VM_REPO /vm_configurator.sh " ] ] && source " $VM_REPO /vm_configurator.sh " || { echo "Error: vm_configurator.sh not found" ; exit 1; }
[ [ -f " $VM_REPO /disk_selector.sh " ] ] && source " $VM_REPO /disk_selector.sh " || { echo "Error: disk_selector.sh not found" ; exit 1; }
[ [ -f " $VM_REPO /vm_creator.sh " ] ] && source " $VM_REPO /vm_creator.sh " || { echo "Error: vm_creator.sh not found" ; exit 1; }
2025-05-07 23:57:51 +02:00
function header_info( ) {
clear
show_proxmenux_logo
2026-04-05 11:24:08 +02:00
msg_title "ProxMenux VM Creator"
}
VM_WIZARD_CAPTURE_FILE = ""
VM_WIZARD_CAPTURE_ACTIVE = 0
2026-04-06 17:16:26 +02:00
VM_STORAGE_IOMMU_PENDING_REBOOT = 0
2026-04-05 11:24:08 +02:00
function start_vm_wizard_capture( ) {
[ [ " ${ VM_WIZARD_CAPTURE_ACTIVE :- 0 } " -eq 1 ] ] && return 0
VM_WIZARD_CAPTURE_FILE = " /tmp/proxmenux_vm_wizard_screen_capture_ $$ .txt "
: >" $VM_WIZARD_CAPTURE_FILE "
exec 8>& 1
exec > >( tee -a " $VM_WIZARD_CAPTURE_FILE " )
VM_WIZARD_CAPTURE_ACTIVE = 1
}
function stop_vm_wizard_capture( ) {
if [ [ " ${ VM_WIZARD_CAPTURE_ACTIVE :- 0 } " -eq 1 ] ] ; then
exec 1>& 8
exec 8>& -
VM_WIZARD_CAPTURE_ACTIVE = 0
fi
if [ [ -n " ${ VM_WIZARD_CAPTURE_FILE :- } " && -f " $VM_WIZARD_CAPTURE_FILE " ] ] ; then
rm -f " $VM_WIZARD_CAPTURE_FILE "
fi
VM_WIZARD_CAPTURE_FILE = ""
}
function has_usable_gpu_for_vm_passthrough( ) {
lspci -nn 2>/dev/null \
| grep -iE "VGA compatible controller|3D controller|Display controller" \
| grep -ivE "Ethernet|Network|Audio" \
| grep -ivE "ASPEED|AST[0-9]{3,4}|Matrox|G200e|BMC" \
| grep -q .
2025-05-07 23:57:51 +02:00
}
# ==========================================================
# MAIN EXECUTION
2025-03-23 17:50:33 +01:00
# ==========================================================
2025-06-10 13:52:30 +02:00
#header_info
#echo -e "\n Loading..."
2025-05-08 00:06:36 +02:00
#sleep 1
2025-05-07 23:57:51 +02:00
function start_vm_configuration( ) {
if ( whiptail --title "ProxMenux" --yesno " $( translate "Use Default Settings?" ) " --no-button " $( translate "Advanced" ) " 10 60) ; then
2026-04-05 11:24:08 +02:00
#header_info
#load_default_vm_config "$OS_TYPE"
2025-05-07 23:57:51 +02:00
if [ [ -z " $HN " ] ] ; then
HN = $( whiptail --inputbox " $( translate "Enter a name for the new virtual machine:" ) " 10 60 --title "VM Hostname" 3>& 1 1>& 2 2>& 3)
[ [ -z " $HN " ] ] && HN = "custom-vm"
fi
2026-04-05 11:24:08 +02:00
header_info
load_default_vm_config " $OS_TYPE "
2025-05-07 23:57:51 +02:00
apply_default_vm_config
else
header_info
echo -e " ${ CUS } $( translate "Using advanced configuration" ) ${ CL } "
configure_vm_advanced " $OS_TYPE "
fi
}
2025-03-23 17:50:33 +01:00
while true; do
2026-04-06 17:16:26 +02:00
VM_STORAGE_IOMMU_PENDING_REBOOT = 0
2025-05-07 23:57:51 +02:00
OS_TYPE = $( dialog --backtitle "ProxMenux" \
--title " $( translate "Select System Type" ) " \
2025-06-10 12:48:26 +02:00
--menu " \n $( translate "Choose the type of virtual system to install:" ) " 20 70 10 \
2025-05-07 23:57:51 +02:00
1 " $( translate "Create" ) VM System NAS " \
2 " $( translate "Create" ) VM System Windows " \
3 " $( translate "Create" ) VM System Linux " \
2025-05-16 17:24:09 +02:00
4 " $( translate "Create" ) VM System macOS (OSX-PROXMOX) " \
5 " $( translate "Create" ) VM System Others (based Linux) " \
6 " $( translate "Return to Main Menu" ) " \
2025-05-07 23:57:51 +02:00
3>& 1 1>& 2 2>& 3)
2025-11-03 00:46:23 +00:00
[ [ $? -ne 0 || " $OS_TYPE " = = "6" ] ] && exec bash " $MENU_REPO /main_menu.sh "
2025-05-07 23:57:51 +02:00
case " $OS_TYPE " in
1)
2025-11-03 00:46:23 +00:00
source " $ISO_REPO /select_nas_iso.sh " && select_nas_iso || continue
2025-05-07 23:57:51 +02:00
; ;
2)
2025-11-03 00:46:23 +00:00
source " $ISO_REPO /select_windows_iso.sh " && select_windows_iso || continue
2025-05-07 23:57:51 +02:00
; ;
3)
2025-11-03 00:46:23 +00:00
source " $ISO_REPO /select_linux_iso.sh " && select_linux_iso || continue
2025-05-07 23:57:51 +02:00
; ;
4)
2025-05-16 17:30:13 +02:00
whiptail --title "OSX-PROXMOX" --yesno " $( translate "This is an external script that creates a macOS VM in Proxmox VE in just a few steps, whether you are using AMD or Intel hardware." ) \n\n $( translate "The script clones the osx-proxmox.com repository and once the setup is complete, the server will automatically reboot." ) \n\n $( translate "Make sure there are no critical services running as they will be interrupted. Ensure your server can be safely rebooted." ) \n\n $( translate "Visit https://osx-proxmox.com for more information." ) \n\n $( translate "Do you want to run the script now?" ) " 24 70
2025-05-16 17:24:09 +02:00
if [ [ $? -eq 0 ] ] ; then
bash -c " $( curl -fsSL https://install.osx-proxmox.com) "
fi
continue
; ;
5)
2025-11-03 00:46:23 +00:00
source " $ISO_REPO /select_linux_iso.sh " && select_linux_other_scripts || continue
2025-05-07 23:57:51 +02:00
; ;
esac
if ! confirm_vm_creation; then
2026-04-05 11:24:08 +02:00
stop_vm_wizard_capture
2025-05-07 23:57:51 +02:00
continue
fi
2026-04-05 11:24:08 +02:00
start_vm_wizard_capture
2025-05-07 23:57:51 +02:00
2026-04-05 11:24:08 +02:00
if ! start_vm_configuration; then
stop_vm_wizard_capture
continue
fi
2025-05-07 23:57:51 +02:00
2026-04-05 11:24:08 +02:00
unset DISK_TYPE
if ! select_disk_type; then
stop_vm_wizard_capture
msg_error " $( translate "Storage plan selection failed or cancelled" ) "
2025-05-07 23:57:51 +02:00
continue
fi
2026-04-05 11:24:08 +02:00
WIZARD_ADD_GPU = "no"
if has_usable_gpu_for_vm_passthrough; then
if whiptail --backtitle "ProxMenux" --title " $( translate "Optional GPU Passthrough" ) " \
--yesno " $( translate "Do you want to configure GPU passthrough for this VM now?" ) \n\n $( translate "This will launch the GPU assistant after VM creation and may require a host reboot." ) " 12 78 --defaultno; then
WIZARD_ADD_GPU = "yes"
fi
else
msg_warn " $( translate "No compatible GPU detected for VM passthrough. Skipping GPU wizard option." ) "
fi
export WIZARD_ADD_GPU
if [ [ " $WIZARD_ADD_GPU " != "yes" ] ] ; then
stop_vm_wizard_capture
fi
if ! create_vm; then
stop_vm_wizard_capture
msg_error " $( translate "VM creation failed or was cancelled during storage setup." ) "
continue
fi
stop_vm_wizard_capture
2025-05-07 23:57:51 +02:00
break
done