git: 52ce808aba3f - stable/13 - bsdinstall: zfsboot: Prompt user for zpool name if the pool already exists

From: Emmanuel Vadot <manu_at_FreeBSD.org>
Date: Thu, 30 Dec 2021 09:10:15 UTC
The branch stable/13 has been updated by manu:

URL: https://cgit.FreeBSD.org/src/commit/?id=52ce808aba3f8b0dfd7529b530232e327af704a3

commit 52ce808aba3f8b0dfd7529b530232e327af704a3
Author:     Emmanuel Vadot <manu@FreeBSD.org>
AuthorDate: 2021-12-08 10:37:50 +0000
Commit:     Emmanuel Vadot <manu@FreeBSD.org>
CommitDate: 2021-12-30 09:10:05 +0000

    bsdinstall: zfsboot: Prompt user for zpool name if the pool already exists
    
    If one install FreeBSD on multiple disks (say 13 and CURRENT) the first created
    pool will always be used.
    Prompt the user for a new pool name if we detect that the default or supplied one
    already exists.
    
    Reviewed by:    imp
    MFC after:      2 weeks
    Sponsored by:   Beckhoff Automation GmbH & Co. KG
    Differential Revision:  https://reviews.freebsd.org/D33331
    
    (cherry picked from commit 9935b0e8ea41804b32576987531be4d31ba705f1)
---
 usr.sbin/bsdinstall/scripts/zfsboot | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/usr.sbin/bsdinstall/scripts/zfsboot b/usr.sbin/bsdinstall/scripts/zfsboot
index 3b673addb10a..7efa40ff8d20 100755
--- a/usr.sbin/bsdinstall/scripts/zfsboot
+++ b/usr.sbin/bsdinstall/scripts/zfsboot
@@ -1547,6 +1547,28 @@ dialog_menu_diskinfo()
 	return $SUCCESS
 }
 
+dialog_zpool_name()
+{
+	local prompt="$* is already taken, please enter a name for the ZFS pool \
+	(Or confirm using the same name by just pressing enter)"
+	local hline=
+	local value="$*"
+	local height width
+
+	f_dialog_inputbox_size height width \
+		"$DIALOG_TITLE" "$DIALOG_BACKTITLE" "$prompt" "$value" "$hline"
+
+	$DIALOG \
+		--title "$DIALOG_TITLE"         \
+		--backtitle "$DIALOG_BACKTITLE" \
+		--hline "$hline"                \
+		--ok-label "Ok"                 \
+		--no-cancel                     \
+		--inputbox "$prompt"            \
+		$height $width "$value"         \
+		2>&1 >&$DIALOG_TERMINAL_PASSTHRU_FD
+}
+
 ############################################################ MAIN
 
 #
@@ -1565,6 +1587,16 @@ f_dprintf "BSDINSTALL_CHROOT=[%s]" "$BSDINSTALL_CHROOT"
 f_dprintf "BSDINSTALL_TMPETC=[%s]" "$BSDINSTALL_TMPETC"
 f_dprintf "FSTAB_FMT=[%s]" "$FSTAB_FMT"
 
+pools=$(zpool import | awk '$1 == "pool:" { print $2}')
+for pool in ${pools}; do
+	f_dprintf "Checking ${pool} against ${ZFSBOOT_POOL_NAME}"
+	if [ "${pool}" = "${ZFSBOOT_POOL_NAME}" ]; then
+		f_dprintf "Pool ${pool} already taken"
+		ZFSBOOT_POOL_NAME=$(dialog_zpool_name "${ZFSBOOT_POOL_NAME}")
+		break;
+	fi
+done
+
 #
 # Determine default boot type
 #