Update import-disk-image.sh

This commit is contained in:
MacRimi 2025-01-26 20:27:28 +01:00 committed by GitHub
parent fd95e18deb
commit 33c133c3d0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -51,7 +51,13 @@ if [ -z "$STORAGE_LIST" ]; then
fi fi
msg_ok "$(translate 'Storage volumes retrieved')" msg_ok "$(translate 'Storage volumes retrieved')"
STORAGE=$(whiptail --title "$(translate 'Select Storage')" --menu "$(translate 'Select the storage volume for disk import:')" 15 60 8 $STORAGE_LIST 3>&1 1>&2 2>&3) # Create an array of storage options for whiptail
STORAGE_OPTIONS=()
for storage in $STORAGE_LIST; do
STORAGE_OPTIONS+=("$storage" "$storage")
done
STORAGE=$(whiptail --title "$(translate 'Select Storage')" --menu "$(translate 'Select the storage volume for disk import:')" 15 60 8 "${STORAGE_OPTIONS[@]}" 3>&1 1>&2 2>&3)
if [ -z "$STORAGE" ]; then if [ -z "$STORAGE" ]; then
msg_error "$(translate 'No storage selected')" msg_error "$(translate 'No storage selected')"
@ -116,10 +122,16 @@ for IMAGE in $SELECTED_IMAGES; do
NEXT_SLOT=$(qm config "$VMID" | grep -oP "${INTERFACE}\d+" | sort -n | tail -n1 | sed "s/${INTERFACE}//") NEXT_SLOT=$(qm config "$VMID" | grep -oP "${INTERFACE}\d+" | sort -n | tail -n1 | sed "s/${INTERFACE}//")
NEXT_SLOT=$((NEXT_SLOT + 1)) NEXT_SLOT=$((NEXT_SLOT + 1))
if qm set "$VMID" --${INTERFACE}${NEXT_SLOT} "$STORAGE:vm-${VMID}-disk-${NEXT_SLOT}"; then IMPORTED_DISK=$(qm config "$VMID" | grep -oP "${STORAGE}:[^\s]+")
msg_ok "$(translate 'Successfully imported') $IMAGE $(translate 'as') ${INTERFACE}${NEXT_SLOT}"
if [ -n "$IMPORTED_DISK" ]; then
if qm set "$VMID" --${INTERFACE}${NEXT_SLOT} "$IMPORTED_DISK"; then
msg_ok "$(translate 'Successfully imported') $IMAGE $(translate 'as') ${INTERFACE}${NEXT_SLOT}"
else
msg_error "$(translate 'Failed to configure disk') ${INTERFACE}${NEXT_SLOT} $(translate 'for VM') $VMID"
fi
else else
msg_error "$(translate 'Failed to configure disk') ${INTERFACE}${NEXT_SLOT} $(translate 'for VM') $VMID" msg_error "$(translate 'Failed to find imported disk')"
fi fi
else else
msg_error "$(translate 'Failed to import') $IMAGE" msg_error "$(translate 'Failed to import') $IMAGE"