12118f387SNathan Whitehorn#!/bin/sh 22118f387SNathan Whitehorn#- 32118f387SNathan Whitehorn# Copyright (c) 2011 Nathan Whitehorn 42118f387SNathan Whitehorn# All rights reserved. 57986af23SBjoern A. Zeeb# Copyright (c) 2011 The FreeBSD Foundation 67986af23SBjoern A. Zeeb# All rights reserved. 77986af23SBjoern A. Zeeb# 87986af23SBjoern A. Zeeb# Portions of this software were developed by Bjoern Zeeb 97986af23SBjoern A. Zeeb# under sponsorship from the FreeBSD Foundation. 102118f387SNathan Whitehorn# 112118f387SNathan Whitehorn# Redistribution and use in source and binary forms, with or without 122118f387SNathan Whitehorn# modification, are permitted provided that the following conditions 132118f387SNathan Whitehorn# are met: 142118f387SNathan Whitehorn# 1. Redistributions of source code must retain the above copyright 152118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer. 162118f387SNathan Whitehorn# 2. Redistributions in binary form must reproduce the above copyright 172118f387SNathan Whitehorn# notice, this list of conditions and the following disclaimer in the 182118f387SNathan Whitehorn# documentation and/or other materials provided with the distribution. 192118f387SNathan Whitehorn# 202118f387SNathan Whitehorn# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 212118f387SNathan Whitehorn# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 222118f387SNathan Whitehorn# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 232118f387SNathan Whitehorn# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 242118f387SNathan Whitehorn# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 252118f387SNathan Whitehorn# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 262118f387SNathan Whitehorn# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 272118f387SNathan Whitehorn# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 282118f387SNathan Whitehorn# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 292118f387SNathan Whitehorn# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 302118f387SNathan Whitehorn# SUCH DAMAGE. 312118f387SNathan Whitehorn# 322118f387SNathan Whitehorn 33cc42ef53SBrad DavisBSDCFG_SHARE="/usr/share/bsdconfig" 34cc42ef53SBrad Davis. $BSDCFG_SHARE/common.subr || exit 1 35cc42ef53SBrad Davis 362118f387SNathan WhitehornINTERFACES="" 376833ac67SAlfonso S. SicilianoBSDDIALOG_ITEMS="" 382118f387SNathan Whitehorn 396833ac67SAlfonso S. Siciliano: ${BSDDIALOG_OK=0} 406833ac67SAlfonso S. Siciliano: ${BSDDIALOG_CANCEL=1} 416833ac67SAlfonso S. Siciliano: ${BSDDIALOG_HELP=2} 426833ac67SAlfonso S. Siciliano: ${BSDDIALOG_EXTRA=3} 436833ac67SAlfonso S. Siciliano: ${BSDDIALOG_ESC=5} 446833ac67SAlfonso S. Siciliano: ${BSDDIALOG_ERROR=255} 452118f387SNathan Whitehorn 462118f387SNathan Whitehornfor IF in `ifconfig -l`; do 472118f387SNathan Whitehorn test "$IF" = "lo0" && continue 482118f387SNathan Whitehorn (ifconfig -g wlan | egrep -wq $IF) && continue 492118f387SNathan Whitehorn INTERFACES="$INTERFACES $IF" 50159ca5c8SNathan Whitehorndone 51159ca5c8SNathan Whitehorn 52b809c7d6SJessica ClarkeWIRELESS_INTERFACES="$(sysctl -in net.wlan.devices)" 53b809c7d6SJessica ClarkeINTERFACES="$INTERFACES${WIRELESS_INTERFACES:+ }$WIRELESS_INTERFACES" 54159ca5c8SNathan Whitehornis_wireless_if() { 55159ca5c8SNathan Whitehorn for IF in $(sysctl -in net.wlan.devices); do 56159ca5c8SNathan Whitehorn if [ $IF = $1 ]; then 57159ca5c8SNathan Whitehorn return 0 58159ca5c8SNathan Whitehorn fi 59159ca5c8SNathan Whitehorn done 60159ca5c8SNathan Whitehorn return 1 61159ca5c8SNathan Whitehorn} 62159ca5c8SNathan Whitehorn 63159ca5c8SNathan Whitehornfor IF in $INTERFACES; do 642118f387SNathan Whitehorn DESC=`sysctl -n dev.$(echo $IF | sed -E 's/([[:alpha:]]*)([[:digit:]]*)/\1.\2/g').%desc` 656833ac67SAlfonso S. Siciliano BSDDIALOG_ITEMS="$BSDDIALOG_ITEMS $IF \"$DESC\"" 662118f387SNathan Whitehorndone 672118f387SNathan Whitehorn 6841f2f866SNathan Whitehornif [ -z "$INTERFACES" ]; then 69cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" \ 707414d14bSJessica Clarke --title 'Network Configuration' \ 7141f2f866SNathan Whitehorn --msgbox 'No network interfaces present to configure.' 0 0 7241f2f866SNathan Whitehorn exit 1 7341f2f866SNathan Whitehornfi 7441f2f866SNathan Whitehorn 75c0e249d3SLars Kellogg-Stedmanexec 5>&1 76c0e249d3SLars Kellogg-StedmanINTERFACE=`echo $BSDDIALOG_ITEMS | xargs -o bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --menu 'Please select a network interface to configure:' 0 0 0 2>&1 1>&5` 776833ac67SAlfonso S. Sicilianoif [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi 78c0e249d3SLars Kellogg-Stedmanexec 5>&- 792118f387SNathan Whitehorn 80d63d020eSBjoern A. Zeeb: > $BSDINSTALL_TMPETC/._rc.conf.net 81f0cdc181SBjoern A. Zeeb 822118f387SNathan WhitehornIFCONFIG_PREFIX="" 83bce09b12SDevin Teskeif is_wireless_if $INTERFACE; then 842118f387SNathan Whitehorn NEXT_WLAN_IFACE=wlan0 # XXX 85*1e75e61dSJessica Clarke sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net wlans_$INTERFACE="$NEXT_WLAN_IFACE" 862118f387SNathan Whitehorn IFCONFIG_PREFIX="WPA " 872118f387SNathan Whitehorn if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 882118f387SNathan Whitehorn ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE 892118f387SNathan Whitehorn ifconfig $NEXT_WLAN_IFACE up 902118f387SNathan Whitehorn fi 912118f387SNathan Whitehorn bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0 922118f387SNathan Whitehorn INTERFACE="$NEXT_WLAN_IFACE" 932118f387SNathan Whitehornfi 942118f387SNathan Whitehorn 957986af23SBjoern A. ZeebIPV6_AVAIL=0 967986af23SBjoern A. ZeebIPV4_AVAIL=0 977986af23SBjoern A. Zeebsysctl -N kern.features.inet6 > /dev/null 2>&1 987986af23SBjoern A. Zeebcase $? in 997986af23SBjoern A. Zeeb0) IPV6_AVAIL=1 ;; 1007986af23SBjoern A. Zeebesac 1017986af23SBjoern A. Zeebsysctl -N kern.features.inet > /dev/null 2>&1 1027986af23SBjoern A. Zeebcase $? in 1037986af23SBjoern A. Zeeb0) IPV4_AVAIL=1 ;; 1047986af23SBjoern A. Zeebesac 1052118f387SNathan Whitehorn 1067986af23SBjoern A. Zeebif [ ${IPV4_AVAIL} -eq 1 ]; then 107cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ 1087986af23SBjoern A. Zeeb --yesno 'Would you like to configure IPv4 for this interface?' 0 0 1096833ac67SAlfonso S. Siciliano if [ $? -eq $BSDDIALOG_OK ]; then 1107986af23SBjoern A. Zeeb bsdinstall netconfig_ipv4 ${INTERFACE} "${IFCONFIG_PREFIX}" || \ 1112118f387SNathan Whitehorn exec $0 1127986af23SBjoern A. Zeeb else 1137986af23SBjoern A. Zeeb IPV4_AVAIL=0 1142118f387SNathan Whitehorn fi 1152118f387SNathan Whitehornfi 1167986af23SBjoern A. Zeeb# In case wlanconfig left an option and we do not support IPv4 we need to write 1177986af23SBjoern A. Zeeb# it out on its own. We cannot write it out with IPv6 as that suffix. 1187986af23SBjoern A. Zeebif [ ${IPV4_AVAIL} -eq 0 -a -n ${IFCONFIG_PREFIX} ]; then 119*1e75e61dSJessica Clarke sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE="${IFCONFIG_PREFIX}" 1207986af23SBjoern A. Zeebfi 1217986af23SBjoern A. Zeebif [ ${IPV6_AVAIL} -eq 1 ]; then 122cc42ef53SBrad Davis bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ 1237986af23SBjoern A. Zeeb --yesno 'Would you like to configure IPv6 for this interface?' 0 0 1246833ac67SAlfonso S. Siciliano if [ $? -eq $BSDDIALOG_OK ]; then 1257986af23SBjoern A. Zeeb bsdinstall netconfig_ipv6 ${INTERFACE} || exec $0 1267986af23SBjoern A. Zeeb else 1277986af23SBjoern A. Zeeb IPV6_AVAIL=0 1287986af23SBjoern A. Zeeb fi 1297986af23SBjoern A. Zeebfi 1307986af23SBjoern A. Zeeb 1317986af23SBjoern A. ZeebSEARCH="" 1327986af23SBjoern A. ZeebIP4_1="" 1337986af23SBjoern A. ZeebIP4_2="" 1347986af23SBjoern A. ZeebIP6_1="" 1357986af23SBjoern A. ZeebIP6_2="" 1367986af23SBjoern A. Zeebwhile read key value; do 1377986af23SBjoern A. Zeeb case "${key}" in 1387986af23SBjoern A. Zeeb search) SEARCH="${value}" ;; 1397986af23SBjoern A. Zeeb nameserver) # is more trick as we have to distinguish v4 and v6 1407986af23SBjoern A. Zeeb case "${value}" in 1417986af23SBjoern A. Zeeb [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) 1427986af23SBjoern A. Zeeb if [ -z "${IP4_1}" ] ; then 1437986af23SBjoern A. Zeeb IP4_1="${value}" 1447986af23SBjoern A. Zeeb elif [ -z "${IP4_2}" ]; then 1457986af23SBjoern A. Zeeb IP4_2="${value}" 1467986af23SBjoern A. Zeeb fi 1477986af23SBjoern A. Zeeb ;; 1487986af23SBjoern A. Zeeb [0-9A-Fa-f:]*:*) 1497986af23SBjoern A. Zeeb if [ -z "${IP6_1}" ] ; then 1507986af23SBjoern A. Zeeb IP6_1="${value}" 1517986af23SBjoern A. Zeeb elif [ -z "${IP6_2}" ]; then 1527986af23SBjoern A. Zeeb IP6_2="${value}" 1537986af23SBjoern A. Zeeb fi 1547986af23SBjoern A. Zeeb ;; 1557986af23SBjoern A. Zeeb esac 1567986af23SBjoern A. Zeeb ;; 1577986af23SBjoern A. Zeeb # ignore others 1587986af23SBjoern A. Zeeb esac 1597986af23SBjoern A. Zeebdone < ${BSDINSTALL_TMPETC}/resolv.conf 1607986af23SBjoern A. Zeeb 1617986af23SBjoern A. ZeebRESOLV="" 1627986af23SBjoern A. Zeebif [ ${IPV6_AVAIL} -eq 1 -a ${IPV4_AVAIL} -eq 1 ]; then 1637986af23SBjoern A. Zeeb RESOLV=" 1646833ac67SAlfonso S. Siciliano 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 1656833ac67SAlfonso S. Siciliano 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 1666833ac67SAlfonso S. Siciliano 'IPv6 DNS #1' 2 1 \"${IP6_1}\" 2 16 50 50 0 1676833ac67SAlfonso S. Siciliano 'IPv6 DNS #2' 3 1 \"${IP6_2}\" 3 16 50 50 0 1686833ac67SAlfonso S. Siciliano 'IPv4 DNS #1' 4 1 \"${IP4_1}\" 4 16 16 16 0 1696833ac67SAlfonso S. Siciliano 'IPv4 DNS #2' 5 1 \"${IP4_2}\" 5 16 16 16 0" 1707986af23SBjoern A. Zeebelif [ ${IPV6_AVAIL} -eq 1 ]; then 1717986af23SBjoern A. Zeeb RESOLV=" 1726833ac67SAlfonso S. Siciliano 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 1736833ac67SAlfonso S. Siciliano 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 1746833ac67SAlfonso S. Siciliano 'IPv6 DNS #1' 2 1 \"${IP6_1}\" 2 16 50 50 0 1756833ac67SAlfonso S. Siciliano 'IPv6 DNS #2' 3 1 \"${IP6_2}\" 3 16 50 50 0" 1767986af23SBjoern A. Zeebelif [ ${IPV4_AVAIL} -eq 1 ]; then 1777986af23SBjoern A. Zeeb RESOLV=" 1786833ac67SAlfonso S. Siciliano 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 1796833ac67SAlfonso S. Siciliano 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 1806833ac67SAlfonso S. Siciliano 'IPv4 DNS #1' 2 1 \"${IP4_1}\" 2 16 16 16 0 1816833ac67SAlfonso S. Siciliano 'IPv4 DNS #2' 3 1 \"${IP4_2}\" 3 16 16 16 0" 1827986af23SBjoern A. Zeebelse 1832118f387SNathan Whitehorn exit 0 1842118f387SNathan Whitehornfi 1852118f387SNathan Whitehorn 186c0e249d3SLars Kellogg-Stedmanexec 5>&1 187cc42ef53SBrad DavisRESOLV=$(echo "${RESOLV}" | xargs -o bsddialog --backtitle "$OSNAME Installer" \ 1887986af23SBjoern A. Zeeb --title 'Network Configuration' \ 189092b5f7cSBjoern A. Zeeb --mixedform 'Resolver Configuration' 0 0 0 \ 190c0e249d3SLars Kellogg-Stedman2>&1 1>&5) 1916833ac67SAlfonso S. Sicilianoif [ $? -eq $BSDDIALOG_CANCEL ]; then exec $0; fi 192c0e249d3SLars Kellogg-Stedmanexec 5>&- 1932118f387SNathan Whitehorn 1947986af23SBjoern A. Zeebecho ${RESOLV} | tr ' ' '\n' | \ 1957986af23SBjoern A. Zeebawk ' 1967986af23SBjoern A. ZeebBEGIN { 1979ab173deSBjoern A. Zeeb search=-1; 1987986af23SBjoern A. Zeeb} 1997986af23SBjoern A. Zeeb{ 2007986af23SBjoern A. Zeeb if (/^[[:space:]]+$/) { 2017986af23SBjoern A. Zeeb next; 2027986af23SBjoern A. Zeeb } 2037986af23SBjoern A. Zeeb if (/^Nameserver$/) { 2047986af23SBjoern A. Zeeb printf "\n"; 2057986af23SBjoern A. Zeeb search=0; 2067986af23SBjoern A. Zeeb next; 2077986af23SBjoern A. Zeeb } 2089ab173deSBjoern A. Zeeb if (search == -1) { 2099ab173deSBjoern A. Zeeb printf "search "; 2109ab173deSBjoern A. Zeeb search=1; 2119ab173deSBjoern A. Zeeb } 2127986af23SBjoern A. Zeeb if (search > 0) { 2139ab173deSBjoern A. Zeeb printf "%s%s", (search > 1) ? " " : "", $1; 2149ab173deSBjoern A. Zeeb search++; 2157986af23SBjoern A. Zeeb next; 2167986af23SBjoern A. Zeeb } 2177986af23SBjoern A. Zeeb printf "nameserver %s\n", $1; 2187986af23SBjoern A. Zeeb}' > ${BSDINSTALL_TMPETC}/resolv.conf 2192118f387SNathan Whitehorn 220d63d020eSBjoern A. Zeebmv $BSDINSTALL_TMPETC/._rc.conf.net $BSDINSTALL_TMPETC/rc.conf.net 221