CTID=$(whiptail --title "$(translate "Select CT for destination disk")" --menu "$(translate "Select the CT to which you want to add disks:")"15608$CT_LIST 3>&1 1>&2 2>&3)
whiptail --title "$(translate "Error")" --msgbox "$(translate "No CT was selected.")"840
exit1
fi
CTID=$(echo"$CTID"| tr -d '"')
msg_ok "$(translate "CT selected successfully.")"
CT_STATUS=$(pct status "$CTID"| awk '{print $2}')
if["$CT_STATUS" !="running"];then
msg_info "$(translate "Starting CT")$CTID..."
pct start "$CTID"
sleep 2
if["$(pct status "$CTID"| awk '{print $2}')" !="running"];then
msg_error "$(translate "Failed to start the CT.")"
exit1
fi
msg_ok "$(translate "CT started successfully.")"
fi
CONF_FILE="/etc/pve/lxc/$CTID.conf"
if grep -q '^unprivileged: 1'"$CONF_FILE";then
if whiptail --title "$(translate "Privileged Container")"\
--yesno "$(translate "The selected container is unprivileged. A privileged container is required for direct device passthrough.")\\n\\n$(translate "Do you want to convert it to a privileged container now?")"12 70;then
ERROR_MESSAGES+="$(translate "The disk")$DISK_INFO$(translate "is in use by the following running VM(s) or CT(s):")\\n$RUNNING_CTS$RUNNING_VMS\\n\\n"
continue
fi
if[ -n "$ASSIGNED_TO"];then
cleanup
whiptail --title "$(translate "Disk Already Assigned")" --yesno "$(translate "The disk")$DISK_INFO$(translate "is already assigned to the following VM(s) or CT(s):")\\n$ASSIGNED_TO\\n\\n$(translate "Do you want to continue anyway?")"1570
if[$? -ne 0];then
sleep 1
exec"$0"
fi
fi
cleanup
if lsblk "$DISK"| grep -q "raid"|| grep -q "${DISK##*/}" /proc/mdstat;then
whiptail --title "$(translate "RAID Detected")" --msgbox "$(translate "The disk")$DISK_INFO$(translate "appears to be part of a") RAID. $(translate "For security reasons, the system cannot format it.")\\n\\n$(translate "If you are sure you want to use it, please remove the") RAID metadata $(translate "or format it manually using external tools.")\\n\\n$(translate "After that, run this script again to add it.")"1870
exit
fi
MOUNT_POINT=$(whiptail --title "$(translate "Mount Point")" --inputbox "$(translate "Enter the mount point for the disk (e.g., /mnt/disk_passthrough):")"1060"/mnt/disk_passthrough" 3>&1 1>&2 2>&3)
if[ -z "$MOUNT_POINT"];then
whiptail --title "$(translate "Error")" --msgbox "$(translate "No mount point was specified.")"840
continue
fi
msg_ok "$(translate "Mount point specified: $MOUNT_POINT")"
PARTITION=$(lsblk -rno NAME "$DISK"| awk -v disk="$(basename "$DISK")"'$1 != disk {print $1; exit}')
whiptail --title "$(translate "Unsupported Filesystem")" --yesno "$(translate "The partition")$PARTITION$(translate "has an unsupported filesystem ($CURRENT_FS).\\nDo you want to format it?")"1070
msg_ok "$(translate "Detected filesystem")$CURRENT_FS$(translate "directly on disk")$DISK.)"
else
whiptail --title "$(translate "No Valid Partitions")" --yesno "$(translate "The disk has no partitions and no valid filesystem. Do you want to create a new partition and format it?")"1070
if[$? -ne 0];then
continue
fi
echo -e "$(translate "Creating partition table and partition...")"
parted -s "$DISK" mklabel gpt
parted -s "$DISK" mkpart primary 0% 100%
sleep 2
partprobe "$DISK"
sleep 2
PARTITION=$(lsblk -rno NAME "$DISK"| awk -v disk="$(basename "$DISK")"'$1 != disk {print $1; exit}')
if[ -n "$PARTITION"];then
PARTITION="/dev/$PARTITION"
else
whiptail --title "$(translate "Partition Error")" --msgbox "$(translate "Failed to create partition on disk")$DISK_INFO."870
whiptail --title "$(translate "Format Cancelled")" --msgbox "$(translate "Format operation cancelled. The disk will not be added.")"860
continue
fi
whiptail --title "$(translate "WARNING")" --yesno "$(translate "WARNING: This operation will FORMAT the disk")$DISK_INFO$(translate "with")$FORMAT_TYPE.\\n\\n$(translate "ALL DATA ON THIS DISK WILL BE PERMANENTLY LOST!")\\n\\n$(translate "Are you sure you want to continue")"1570
if[$? -ne 0];then
whiptail --title "$(translate "Format Cancelled")" --msgbox "$(translate "Format operation cancelled. The disk will not be added.")"860
whiptail --title "$(translate "Format Failed")" --msgbox "$(translate "Failed to format partition")$PARTITION$(translate "with")$FORMAT_TYPE.\\n\\n$(translate "The disk may be in use by the system or have hardware issues.")"1270