mirror of
https://github.com/MacRimi/ProxMenux.git
synced 2025-06-28 12:16:53 +00:00
Update import-disk-image.sh
This commit is contained in:
parent
c7cc9f4e94
commit
97261bf491
@ -1,68 +1,111 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Ruta donde están las imágenes de disco
|
# ProxMenu - A menu-driven script for Proxmox VE administration
|
||||||
|
# Copyright (c) 2024 ProxMenu
|
||||||
|
# Author: MacRimi
|
||||||
|
# License: MIT
|
||||||
|
# https://raw.githubusercontent.com/MacRimi/ProxMenux/main/LICENSE
|
||||||
|
|
||||||
|
# Source utility functions
|
||||||
|
source "/usr/local/share/proxmenux/utils.sh"
|
||||||
|
|
||||||
|
# Path where disk images are stored
|
||||||
IMAGES_DIR="/var/lib/vz/template/images/"
|
IMAGES_DIR="/var/lib/vz/template/images/"
|
||||||
|
|
||||||
# Mensaje inicial
|
# Check dependencies
|
||||||
|
check_dependencies qm whiptail jq
|
||||||
|
|
||||||
|
# Initial setup
|
||||||
if ! [ -d "$IMAGES_DIR" ]; then
|
if ! [ -d "$IMAGES_DIR" ]; then
|
||||||
|
msg_info "$(translate 'Creating images directory...')"
|
||||||
mkdir -p "$IMAGES_DIR"
|
mkdir -p "$IMAGES_DIR"
|
||||||
|
msg_ok "$(translate 'Images directory created')"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
whiptail --title "Importar Imagen de Disco" --msgbox "Por favor, asegúrate de tener las imágenes de disco que quieres importar en la siguiente ubicación:\n\n$IMAGES_DIR\n\nFormatos soportados: .img, .qcow2, .vmdk." 12 60
|
# Display initial message
|
||||||
|
whiptail --title "$(translate 'Import Disk Image')" --msgbox "$(translate 'Please ensure that the disk images you want to import are located in:')\n\n$IMAGES_DIR\n\n$(translate 'Supported formats: .img, .qcow2, .vmdk.')" 12 60
|
||||||
|
|
||||||
# 1. Seleccionar VM
|
# 1. Select VM
|
||||||
|
msg_info "$(translate 'Getting VM list...')"
|
||||||
VM_LIST=$(qm list | awk 'NR>1 {print $1, $2}')
|
VM_LIST=$(qm list | awk 'NR>1 {print $1, $2}')
|
||||||
if [ -z "$VM_LIST" ]; then
|
if [ -z "$VM_LIST" ]; then
|
||||||
whiptail --title "Error" --msgbox "No hay VMs disponibles en el sistema." 8 40
|
msg_error "$(translate 'No VMs available in the system')"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
msg_ok "$(translate 'VM list retrieved')"
|
||||||
|
|
||||||
VMID=$(whiptail --title "Seleccionar VM" --menu "Selecciona la VM a la que deseas importar la imagen de disco:" 15 60 8 $VM_LIST 3>&1 1>&2 2>&3)
|
VMID=$(whiptail --title "$(translate 'Select VM')" --menu "$(translate 'Select the VM where you want to import the disk image:')" 15 60 8 $VM_LIST 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
if [ -z "$VMID" ]; then
|
if [ -z "$VMID" ]; then
|
||||||
whiptail --title "Error" --msgbox "No se seleccionó ninguna VM." 8 40
|
msg_error "$(translate 'No VM selected')"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 2. Seleccionar las imágenes de disco
|
# 2. Select disk images
|
||||||
IMAGENES=$(whiptail --title "Seleccionar Imágenes de Disco" --checklist "Selecciona las imágenes de disco para importar:" 20 60 10 $(ls "$IMAGES_DIR" | grep -E "\.(img|qcow2|vmdk)$" | awk '{print $1, "OFF"}') 3>&1 1>&2 2>&3)
|
msg_info "$(translate 'Scanning for disk images...')"
|
||||||
|
IMAGES=$(ls "$IMAGES_DIR" | grep -E "\.(img|qcow2|vmdk)$")
|
||||||
|
if [ -z "$IMAGES" ]; then
|
||||||
|
msg_error "$(translate 'No compatible disk images found in') $IMAGES_DIR"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
msg_ok "$(translate 'Disk images found')"
|
||||||
|
|
||||||
if [ -z "$IMAGENES" ]; then
|
IMAGE_LIST=""
|
||||||
whiptail --title "Error" --msgbox "No se seleccionó ninguna imagen." 8 40
|
for img in $IMAGES; do
|
||||||
|
IMAGE_LIST="$IMAGE_LIST $img OFF"
|
||||||
|
done
|
||||||
|
|
||||||
|
SELECTED_IMAGES=$(whiptail --title "$(translate 'Select Disk Images')" --checklist "$(translate 'Select the disk images to import:')" 20 60 10 $IMAGE_LIST 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
|
if [ -z "$SELECTED_IMAGES" ]; then
|
||||||
|
msg_error "$(translate 'No images selected')"
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# 3. Importar cada imagen seleccionada
|
# 3. Import each selected image
|
||||||
for IMAGEN in $IMAGENES; do
|
for IMAGE in $SELECTED_IMAGES; do
|
||||||
# Quitar comillas de la imagen seleccionada
|
# Remove quotes from selected image
|
||||||
IMAGEN=$(echo "$IMAGEN" | tr -d '"')
|
IMAGE=$(echo "$IMAGE" | tr -d '"')
|
||||||
|
|
||||||
# 4. Seleccionar tipo de disco para cada imagen
|
# 4. Select disk type for each image
|
||||||
INTERFAZ=$(whiptail --title "Tipo de Interfaz" --menu "Selecciona el tipo de disco para la imagen: $IMAGEN" 15 40 4 \
|
INTERFACE=$(whiptail --title "$(translate 'Interface Type')" --menu "$(translate 'Select disk type for image:') $IMAGE" 15 40 4 \
|
||||||
"sata" "Añadir como SATA" \
|
"sata" "$(translate 'Add as SATA')" \
|
||||||
"scsi" "Añadir como SCSI" \
|
"scsi" "$(translate 'Add as SCSI')" \
|
||||||
"virtio" "Añadir como VirtIO" \
|
"virtio" "$(translate 'Add as VirtIO')" \
|
||||||
"ide" "Añadir como IDE" 3>&1 1>&2 2>&3)
|
"ide" "$(translate 'Add as IDE')" 3>&1 1>&2 2>&3)
|
||||||
|
|
||||||
if [ -z "$INTERFAZ" ]; then
|
if [ -z "$INTERFACE" ]; then
|
||||||
whiptail --title "Error" --msgbox "No se seleccionó un tipo de disco para $IMAGEN." 8 40
|
msg_error "$(translate 'No disk type selected for') $IMAGE"
|
||||||
exit 1
|
continue
|
||||||
fi
|
fi
|
||||||
|
|
||||||
FULL_PATH="$IMAGES_DIR/$IMAGEN"
|
FULL_PATH="$IMAGES_DIR/$IMAGE"
|
||||||
|
|
||||||
# 5. Añadir la imagen con índice automático
|
# 5. Add image with automatic index
|
||||||
INDEX=0
|
INDEX=0
|
||||||
|
|
||||||
# Buscar índice disponible
|
# Find available index
|
||||||
while qm config "$VMID" | grep -q "${INTERFAZ}${INDEX}"; do
|
while qm config "$VMID" | grep -q "${INTERFACE}${INDEX}"; do
|
||||||
((INDEX++))
|
((INDEX++))
|
||||||
done
|
done
|
||||||
|
|
||||||
whiptail --title "Importando" --infobox "Importando imagen: $IMAGEN como ${INTERFAZ}${INDEX}..." 8 40
|
msg_info "$(translate 'Importing image:') $IMAGE $(translate 'as') ${INTERFACE}${INDEX}..."
|
||||||
qm importdisk "$VMID" "$FULL_PATH" "local-lvm" --format "$INTERFAZ"
|
|
||||||
qm set "$VMID" -${INTERFAZ}${INDEX} "$FULL_PATH"
|
(
|
||||||
|
if qm importdisk "$VMID" "$FULL_PATH" "local-lvm" --format "$INTERFACE"; then
|
||||||
|
if qm set "$VMID" -${INTERFACE}${INDEX} "$FULL_PATH"; then
|
||||||
|
msg_ok "$(translate 'Successfully imported') $IMAGE $(translate 'as') ${INTERFACE}${INDEX}"
|
||||||
|
else
|
||||||
|
msg_error "$(translate 'Failed to configure disk') ${INTERFACE}${INDEX} $(translate 'for VM') $VMID"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
msg_error "$(translate 'Failed to import') $IMAGE"
|
||||||
|
fi
|
||||||
|
) &
|
||||||
|
|
||||||
|
spinner
|
||||||
|
wait
|
||||||
done
|
done
|
||||||
|
|
||||||
whiptail --title "Completado" --msgbox "Todas las imágenes se importaron correctamente." 8 40
|
msg_ok "$(translate 'All selected images have been processed')"
|
||||||
exit 0
|
exit 0
|
||||||
|
Loading…
x
Reference in New Issue
Block a user