On Tue, Dec 06, 2022 at 06:11:33PM -0800, Andrew Hewus Fresh wrote: > Here's an initial draft of a diff to allow configuring by lladdr in the > installer. I'm not a super fan of how it works, but could use some > feedback from folks trying it and suggesting improvements. > > It's a larger diff than I first expected since I didn't want to include > the lladdrs in the "available interfaces" list, but ask_which() doesn't > allow two lists.
Here's a second try, with some nits picked and some bugs squashed. The output from "?" is quite a bit less verbose now, and although I'd like to be able to see which interface has the cable plugged in right there, it's hard to know where to stop. The main thing that still needs addressing is that the question worded as it was wraps and really shouldn't. I didn't want to reword the question and break folks answer files, but we may need to. I'll keep thinking about how best to handle this. Especially as when answering with an lladdr it makes things really long. Now though, dinner time. System hostname? (short form, e.g. 'foo') foo Available network interfaces are: vio0 vlan0. Which interface do you wish to configure? (name, lladdr, '?', or 'done') [vio0] ? Available network interfaces are: vio0 vlan0. vio0: lladdr fe:e1:bb:d1:dd:97 Which interface do you wish to configure? (name, lladdr, '?', or 'done') [vio0] fe:e1:bb:d1:dd:97 IPv4 address for vio0? (or 'autoconf' or 'none') [autoconf] IPv6 address for vio0? (or 'autoconf' or 'none') [none] Available network interfaces are: vio0 vlan0. Which interface do you wish to configure? (name, lladdr, '?', or 'done') [done] ? Available network interfaces are: vio0 vlan0. vio0: lladdr fe:e1:bb:d1:dd:97 Which interface do you wish to configure? (name, lladdr, '?', or 'done') [done] Using DNS domainname my.domain Using DNS nameservers at 100.64.1.2 Index: distrib/miniroot/install.sub =================================================================== RCS file: /cvs/src/distrib/miniroot/install.sub,v retrieving revision 1.1215 diff -u -p -r1.1215 install.sub --- distrib/miniroot/install.sub 5 Dec 2022 20:12:00 -0000 1.1215 +++ distrib/miniroot/install.sub 7 Dec 2022 03:51:38 -0000 @@ -356,6 +356,17 @@ get_ifs() { done } +get_ifs_and_lladdrs() { + local _if _lladdr + for _if in $(get_ifs); do + echo $_if + _lladdr=$(ifconfig $_if | + sed -n 's/^[[:space:]]*lladdr[[:space:]]//p' ) + [[ -n $_lladdr && -n $(ifconfig -M $_lladdr) ]] && + echo $_lladdr + done +} + # Return the device name of the disk device $1, which may be a disklabel UID. get_dkdev_name() { local _dev=${1#/dev/} _d @@ -1291,7 +1302,7 @@ ieee80211_config() { # Set up IPv4 and IPv6 interface configuration. configure_ifs() { - local _first _hn _if _name _p _vi _vn + local _first _hn _if _name _p _q _vi _vn # Always need lo0 configured. ifconfig lo0 inet 127.0.0.1/8 @@ -1306,12 +1317,41 @@ configure_ifs() { [[ -n $_vi ]] && ((_vi++)) [[ -n $(get_ifs) ]] && _vn="vlan${_vi:-0}" - ask_which "network interface" "do you wish to configure" \ - "\$(get_ifs) $_vn" \ - ${_p:-'$( (get_ifs netboot; get_ifs) | sed q )'} - [[ $resp == done ]] && break + set -- $(get_ifs) $_vn; _q="$*" + echo "Available network interfaces are: $_q." + if [[ $_if = DETAILS ]]; then + for _if in $(get_ifs); do + _name=$(ifconfig $_if | + sed -n 's/^[[:space:]]*lladdr[[:space:]]//p' ) + [[ -n $_name && -n $(ifconfig -M $_name) ]] && + echo " $_if: lladdr $_name" + done + _if= + _name= + fi + _q="Which interface do you wish to configure?" + ask_until "$_q (name, lladdr, '?', or 'done')" \ + ${_p:-$( (get_ifs netboot; get_ifs) | sed q )} + case $resp in + done) break + ;; + \?) _if=DETAILS + continue + ;; + *) # Quote $resp to prevent user from confusing isin() by + # entering something like 'a a'. + if isin "$resp" $( get_ifs_and_lladdrs ) $_vn done; then + log_answers "$_q" "$resp" + _if=$resp + else + echo "'$resp' is not a valid choice." + $AI && [[ -n $AI_RESPFILE ]] && exit 1 + fi + ;; + esac + + [[ -z $_if ]] && continue - _if=$resp _hn=/tmp/i/hostname.$_if rm -f $_hn @@ -1319,6 +1359,15 @@ configure_ifs() { # questions and bring it up. if [[ $_if == vlan+([0-9]) ]]; then vlan_config $_if || continue + fi + + # Test if we're configuring by lladdr + if [[ $_if == ??:??:??:??:??:?? ]]; then + _if=$( ifconfig -M $_if ) + if [[ -z $_if ]]; then + echo "'${#/tmp/i/hostname.}' does not refer to a valid interface." + continue + fi fi # Test if it is an 802.11 interface.