Files

78 lines
3.4 KiB
Bash
Executable File

#!/bin/bash
# TUI disk selection. Uses `dialog` to show detected disks/partitions
# and require explicit user confirmation before any destructive action.
# Sets globals: TARGET_DISK, ROOT_PART, EFI_PART
# shellcheck source=common.sh
source "$(dirname "${BASH_SOURCE[0]}")/common.sh"
tui_select_install_target() {
step "Disk selection"
local default_root="${DEFAULT_ROOT_PART:-}"
local default_efi="${DEFAULT_EFI_PART:-}"
# Build a human menu of partitions (skip loop/ram/zram, only TYPE=part).
local menu_items=()
local dev type fstype size label
while read -r dev type fstype size label; do
[[ "$type" == "part" ]] || continue
[[ "$dev" =~ ^/dev/(sd|nvme|vd|mmcblk|hd|xvd) ]] || continue
local marker=""
[[ "$dev" == "$default_root" ]] && marker=" (DEFAULT ROOT)"
[[ "$fstype" == "vfat" ]] && marker+=" [EFI?]"
[[ "$fstype" == "ntfs" ]] && marker+=" [WINDOWS - DO NOT TOUCH]"
menu_items+=("$dev" "${fstype:-?} ${size} '${label:-}'${marker}")
done < <(lsblk -lnpo NAME,TYPE,FSTYPE,SIZE,LABEL 2>/dev/null || true)
if [[ ${#menu_items[@]} -eq 0 ]]; then
log "lsblk output for diagnosis:"
lsblk -lnpo NAME,TYPE,FSTYPE,SIZE,LABEL 2>&1 | while read -r l; do log " $l"; done
die "no candidate partitions found"
fi
local choice
if [[ "${UNATTENDED:-0}" == "1" ]]; then
choice="$default_root"
log "[unattended] target root partition = $choice"
else
choice=$(dialog --stdout --title "Void Installer — SELECT ROOT PARTITION" \
--backtitle "WARNING: the chosen partition will be WIPED. Windows partitions show [WINDOWS]." \
--default-item "$default_root" \
--menu "Choose the partition to install Void Linux onto.\nDefault highlights $default_root (current Linux Mint).\nAbsolutely DO NOT pick a partition labelled [WINDOWS]." \
25 90 14 "${menu_items[@]}") \
|| die "user cancelled disk selection"
fi
[[ -b "$choice" ]] || die "selected device $choice is not a block device"
local fstype
fstype=$(lsblk -no FSTYPE "$choice" 2>/dev/null | head -1)
if [[ "$fstype" == "ntfs" ]]; then
die "REFUSING to wipe NTFS partition $choice (looks like Windows)"
fi
ROOT_PART="$choice"
EFI_PART="${default_efi}"
# Resolve the parent block device robustly (works for nvme, mmcblk, sd*, vd*).
TARGET_DISK="/dev/$(lsblk -no PKNAME "$choice" 2>/dev/null | head -1)"
[[ "$TARGET_DISK" == "/dev/" ]] && TARGET_DISK="$DEFAULT_DISK"
# Confirmation step: must type the partition device name verbatim.
if [[ "${UNATTENDED:-0}" != "1" ]]; then
local typed
typed=$(dialog --stdout --title "FINAL CONFIRMATION" \
--backtitle "Type the device name to confirm WIPE" \
--inputbox "About to:\n - WIPE : $ROOT_PART (will become btrfs)\n - SHARE : $EFI_PART (kept intact, only adds /EFI/Void)\n - LEAVE : everything else (Windows, recovery)\n\nType the FULL device path of the partition to wipe to continue:" \
18 75) \
|| die "user cancelled confirmation"
[[ "$typed" == "$ROOT_PART" ]] \
|| die "confirmation mismatch (typed '$typed' != '$ROOT_PART')"
fi
ok "target root : $ROOT_PART"
ok "shared EFI : $EFI_PART"
ok "parent disk : $TARGET_DISK"
export TARGET_DISK ROOT_PART EFI_PART
}