3 # Copyright (c) 2011 Nathan Whitehorn
5 # Copyright (c) 2011 The FreeBSD Foundation
8 # Portions of this software were developed by Bjoern Zeeb
9 # under sponsorship from the FreeBSD Foundation.
11 # Redistribution and use in source and binary forms, with or without
12 # modification, are permitted provided that the following conditions
14 # 1. Redistributions of source code must retain the above copyright
15 # notice, this list of conditions and the following disclaimer.
16 # 2. Redistributions in binary form must reproduce the above copyright
17 # notice, this list of conditions and the following disclaimer in the
18 # documentation and/or other materials provided with the distribution.
20 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 : ${DIALOG_ITEM_HELP=4}
44 for IF in `ifconfig -l`; do
45 test "$IF" = "lo0" && continue
46 (ifconfig -g wlan | egrep -wq $IF) && continue
47 INTERFACES="$INTERFACES $IF"
48 DESC=`sysctl -n dev.$(echo $IF | sed -E 's/([[:alpha:]]*)([[:digit:]]*)/\1.\2/g').%desc`
49 DIALOG_TAGS="$DIALOG_TAGS $IF \"$DESC\""
53 INTERFACE=`echo $DIALOG_TAGS | xargs dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --menu 'Please select a network interface to configure:' 0 0 0 2>&1 1>&3`
54 if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
57 : > $BSDINSTALL_TMPETC/._rc.conf.net
59 # Do a dirty check to see if this a wireless interface -- there should be a
62 if ifconfig $INTERFACE | grep -q 'media: IEEE 802.11 Wireless'; then
63 NEXT_WLAN_IFACE=wlan0 # XXX
64 echo wlans_$INTERFACE=\"$NEXT_WLAN_IFACE\" >> $BSDINSTALL_TMPETC/._rc.conf.net
65 IFCONFIG_PREFIX="WPA "
66 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
67 ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE
68 ifconfig $NEXT_WLAN_IFACE up
70 bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0
71 INTERFACE="$NEXT_WLAN_IFACE"
76 sysctl -N kern.features.inet6 > /dev/null 2>&1
80 sysctl -N kern.features.inet > /dev/null 2>&1
85 if [ ${IPV4_AVAIL} -eq 1 ]; then
86 dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
87 --yesno 'Would you like to configure IPv4 for this interface?' 0 0
88 if [ $? -eq $DIALOG_OK ]; then
89 bsdinstall netconfig_ipv4 ${INTERFACE} "${IFCONFIG_PREFIX}" || \
95 # In case wlanconfig left an option and we do not support IPv4 we need to write
96 # it out on its own. We cannot write it out with IPv6 as that suffix.
97 if [ ${IPV4_AVAIL} -eq 0 -a -n ${IFCONFIG_PREFIX} ]; then
98 echo ifconfig_${INTERFACE}=\"${IFCONFIG_PREFIX}\" >> $BSDINSTALL_TMPETC/._rc.conf.net
100 if [ ${IPV6_AVAIL} -eq 1 ]; then
101 dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
102 --yesno 'Would you like to configure IPv6 for this interface?' 0 0
103 if [ $? -eq $DIALOG_OK ]; then
104 bsdinstall netconfig_ipv6 ${INTERFACE} || exec $0
115 while read key value; do
117 search) SEARCH="${value}" ;;
118 nameserver) # is more trick as we have to distinguish v4 and v6
120 [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)
121 if [ -z "${IP4_1}" ] ; then
123 elif [ -z "${IP4_2}" ]; then
128 if [ -z "${IP6_1}" ] ; then
130 elif [ -z "${IP6_2}" ]; then
138 done < ${BSDINSTALL_TMPETC}/resolv.conf
141 if [ ${IPV6_AVAIL} -eq 1 -a ${IPV4_AVAIL} -eq 1 ]; then
143 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0
144 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2
145 'IPv6 DNS #1' 2 0 \"${IP6_1}\" 2 16 50 0 0
146 'IPv6 DNS #2' 3 0 \"${IP6_2}\" 3 16 50 0 0
147 'IPv4 DNS #1' 4 0 \"${IP4_1}\" 4 16 16 0 0
148 'IPv4 DNS #2' 5 0 \"${IP4_2}\" 5 16 16 0 0"
149 elif [ ${IPV6_AVAIL} -eq 1 ]; then
151 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0
152 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2
153 'IPv6 DNS #1' 2 0 \"${IP6_1}\" 2 16 50 0 0
154 'IPv6 DNS #2' 3 0 \"${IP6_2}\" 3 16 50 0 0"
155 elif [ ${IPV4_AVAIL} -eq 1 ]; then
157 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0
158 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2
159 'IPv4 DNS #1' 2 0 \"${IP4_1}\" 2 16 16 0 0
160 'IPv4 DNS #2' 3 0 \"${IP4_2}\" 3 16 16 0 0"
166 RESOLV=$(echo "${RESOLV}" | xargs dialog --backtitle 'FreeBSD Installer' \
167 --title 'Network Configuration' \
168 --mixedform 'Resolver Configuration' 0 0 0 \
170 if [ $? -eq $DIALOG_CANCEL ]; then exec $0; fi
173 echo ${RESOLV} | tr ' ' '\n' | \
179 if (/^[[:space:]]+$/) {
182 if (/^Nameserver$/) {
192 printf "%s%s", (search > 1) ? " " : "", $1;
196 printf "nameserver %s\n", $1;
197 }' > ${BSDINSTALL_TMPETC}/resolv.conf
199 mv $BSDINSTALL_TMPETC/._rc.conf.net $BSDINSTALL_TMPETC/rc.conf.net