On Fri, Mar 02, 2018 at 07:32:04AM -0700, Aaron Bieber wrote:
> Hi,
>
> Currently disks can only be entered in the [sw]d[0-9][0-9] format at the
> "Which disk is the root disk?" prompt. This is great for humans, but
> things get tricky when doing an autoinstall upgrade on systems where
> connected disks change frequently.
>
> This diff lets you put the DUID in the response file.
>
> If anyone has a better way to determine the disk from the duid, I am all
> ears :D
>
> Cheers,
> Aaron
>

New version uses hw.disknames vs the ghetto diskutil | grep check.

Thanks to Philipp Buehler for proper cluesticking :D

Index: distrib/miniroot/install.sub
===================================================================
RCS file: /cvs/src/distrib/miniroot/install.sub,v
retrieving revision 1.1065
diff -u -p -r1.1065 install.sub
--- distrib/miniroot/install.sub        21 Feb 2018 20:02:37 -0000      1.1065
+++ distrib/miniroot/install.sub        2 Mar 2018 17:25:39 -0000
@@ -306,6 +306,13 @@ scan_disknames() {
        bsort $(for _n in $_disks; do echo "${_n%%:*} "; done | sed -n "$1")
 }

+# Return disk devices along with their uids.
+scan_disks() {
+       local IFS=, _disks=$(sysctl -n hw.disknames)
+
+       bsort $(for _n in $_disks; do echo "${_n}"; done)
+}
+
 # Return disk devices found in hw.disknames.
 get_dkdevs() {
        echo $(scan_disknames "${MDDKDEVS:-/^[sw]d[0-9][0-9]* /s/ .*//p}")
@@ -2201,6 +2208,26 @@ set_timezone() {
        done
 }

+# Determine the disk name from supplied disk uid.
+duid_to_disk() {
+       local _in=$1 _disk
+       local _disks=$(scan_disks)
+
+       for _d in ${_disks}; do
+               local _a=${_d##*:}
+               local _b=${_d%%:*}
+               if [[ $_in == ${_a} ]]; then
+                       _disk=$_b
+               fi
+       done
+
+       if [[ -z $_disk ]]; then
+               echo $_in
+       else
+               echo $_disk
+       fi
+}
+
 # Determine if the supplied disk is a potential root disk, by:
 # - Check the disklabel if there is an 'a' partition of type 4.2BSD
 # - Mount the partition (read-only) and look for typical root filesystem layout
@@ -2231,7 +2258,8 @@ get_rootinfo() {
                case $resp in
                "?")    diskinfo $(get_dkdevs);;
                '')     ;;
-               *)      if isin "$resp" $(get_dkdevs); then
+               *)      resp=$(duid_to_disk "$resp")
+                       if isin "$resp" $(get_dkdevs); then
                                [[ $MODE == install ]] && break
                                is_rootdisk "$resp" && break
                                echo "$resp is not a valid root disk."

--
PGP: 0x1F81112D62A9ADCE / 3586 3350 BFEA C101 DB1A  4AF0 1F81 112D 62A9 ADCE

Reply via email to