diff --git a/usr.sbin/bsdinstall/scripts/netconfig b/usr.sbin/bsdinstall/scripts/netconfig index 58fbe1883d40..77b71867eb4a 100755 --- a/usr.sbin/bsdinstall/scripts/netconfig +++ b/usr.sbin/bsdinstall/scripts/netconfig @@ -1,220 +1,220 @@ #!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn # All rights reserved. # Copyright (c) 2011 The FreeBSD Foundation # All rights reserved. # # Portions of this software were developed by Bjoern Zeeb # under sponsorship from the FreeBSD Foundation. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 INTERFACES="" BSDDIALOG_ITEMS="" : ${BSDDIALOG_OK=0} : ${BSDDIALOG_CANCEL=1} : ${BSDDIALOG_HELP=2} : ${BSDDIALOG_EXTRA=3} : ${BSDDIALOG_ESC=5} : ${BSDDIALOG_ERROR=255} for IF in `ifconfig -l`; do test "$IF" = "lo0" && continue (ifconfig -g wlan | egrep -wq $IF) && continue INTERFACES="$INTERFACES $IF" done WIRELESS_INTERFACES="$(sysctl -in net.wlan.devices)" INTERFACES="$INTERFACES${WIRELESS_INTERFACES:+ }$WIRELESS_INTERFACES" is_wireless_if() { for IF in $(sysctl -in net.wlan.devices); do if [ $IF = $1 ]; then return 0 fi done return 1 } for IF in $INTERFACES; do DESC=`sysctl -n dev.$(echo $IF | sed -E 's/([[:alpha:]]*)([[:digit:]]*)/\1.\2/g').%desc` BSDDIALOG_ITEMS="$BSDDIALOG_ITEMS $IF \"$DESC\"" done if [ -z "$INTERFACES" ]; then bsddialog --backtitle "$OSNAME Installer" \ --title 'Network Configuration' \ --msgbox 'No network interfaces present to configure.' 0 0 exit 1 fi exec 5>&1 INTERFACE=`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` if [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi exec 5>&- : > $BSDINSTALL_TMPETC/._rc.conf.net IFCONFIG_PREFIX="" if is_wireless_if $INTERFACE; then NEXT_WLAN_IFACE=wlan0 # XXX - sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net wlans_$INTERFACE "$NEXT_WLAN_IFACE" + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net wlans_$INTERFACE="$NEXT_WLAN_IFACE" IFCONFIG_PREFIX="WPA " if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE ifconfig $NEXT_WLAN_IFACE up fi bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0 INTERFACE="$NEXT_WLAN_IFACE" fi IPV6_AVAIL=0 IPV4_AVAIL=0 sysctl -N kern.features.inet6 > /dev/null 2>&1 case $? in 0) IPV6_AVAIL=1 ;; esac sysctl -N kern.features.inet > /dev/null 2>&1 case $? in 0) IPV4_AVAIL=1 ;; esac if [ ${IPV4_AVAIL} -eq 1 ]; then bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ --yesno 'Would you like to configure IPv4 for this interface?' 0 0 if [ $? -eq $BSDDIALOG_OK ]; then bsdinstall netconfig_ipv4 ${INTERFACE} "${IFCONFIG_PREFIX}" || \ exec $0 else IPV4_AVAIL=0 fi fi # In case wlanconfig left an option and we do not support IPv4 we need to write # it out on its own. We cannot write it out with IPv6 as that suffix. if [ ${IPV4_AVAIL} -eq 0 -a -n ${IFCONFIG_PREFIX} ]; then - sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE "${IFCONFIG_PREFIX}" + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE="${IFCONFIG_PREFIX}" fi if [ ${IPV6_AVAIL} -eq 1 ]; then bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ --yesno 'Would you like to configure IPv6 for this interface?' 0 0 if [ $? -eq $BSDDIALOG_OK ]; then bsdinstall netconfig_ipv6 ${INTERFACE} || exec $0 else IPV6_AVAIL=0 fi fi SEARCH="" IP4_1="" IP4_2="" IP6_1="" IP6_2="" while read key value; do case "${key}" in search) SEARCH="${value}" ;; nameserver) # is more trick as we have to distinguish v4 and v6 case "${value}" in [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*) if [ -z "${IP4_1}" ] ; then IP4_1="${value}" elif [ -z "${IP4_2}" ]; then IP4_2="${value}" fi ;; [0-9A-Fa-f:]*:*) if [ -z "${IP6_1}" ] ; then IP6_1="${value}" elif [ -z "${IP6_2}" ]; then IP6_2="${value}" fi ;; esac ;; # ignore others esac done < ${BSDINSTALL_TMPETC}/resolv.conf RESOLV="" if [ ${IPV6_AVAIL} -eq 1 -a ${IPV4_AVAIL} -eq 1 ]; then RESOLV=" 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 'IPv6 DNS #1' 2 1 \"${IP6_1}\" 2 16 50 50 0 'IPv6 DNS #2' 3 1 \"${IP6_2}\" 3 16 50 50 0 'IPv4 DNS #1' 4 1 \"${IP4_1}\" 4 16 16 16 0 'IPv4 DNS #2' 5 1 \"${IP4_2}\" 5 16 16 16 0" elif [ ${IPV6_AVAIL} -eq 1 ]; then RESOLV=" 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 'IPv6 DNS #1' 2 1 \"${IP6_1}\" 2 16 50 50 0 'IPv6 DNS #2' 3 1 \"${IP6_2}\" 3 16 50 50 0" elif [ ${IPV4_AVAIL} -eq 1 ]; then RESOLV=" 'Search' 1 1 \"${SEARCH}\" 1 16 50 50 0 'Nameserver' 2 1 \"Nameserver\" 2 1 11 11 2 'IPv4 DNS #1' 2 1 \"${IP4_1}\" 2 16 16 16 0 'IPv4 DNS #2' 3 1 \"${IP4_2}\" 3 16 16 16 0" else exit 0 fi exec 5>&1 RESOLV=$(echo "${RESOLV}" | xargs -o bsddialog --backtitle "$OSNAME Installer" \ --title 'Network Configuration' \ --mixedform 'Resolver Configuration' 0 0 0 \ 2>&1 1>&5) if [ $? -eq $BSDDIALOG_CANCEL ]; then exec $0; fi exec 5>&- echo ${RESOLV} | tr ' ' '\n' | \ awk ' BEGIN { search=-1; } { if (/^[[:space:]]+$/) { next; } if (/^Nameserver$/) { printf "\n"; search=0; next; } if (search == -1) { printf "search "; search=1; } if (search > 0) { printf "%s%s", (search > 1) ? " " : "", $1; search++; next; } printf "nameserver %s\n", $1; }' > ${BSDINSTALL_TMPETC}/resolv.conf mv $BSDINSTALL_TMPETC/._rc.conf.net $BSDINSTALL_TMPETC/rc.conf.net diff --git a/usr.sbin/bsdinstall/scripts/netconfig_ipv4 b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 index 9097a1f9617c..8f747a9d0162 100755 --- a/usr.sbin/bsdinstall/scripts/netconfig_ipv4 +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 @@ -1,108 +1,108 @@ #!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn # Copyright (c) 2013-2015 Devin Teske # All rights reserved. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # ############################################################ INCLUDES BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 f_dprintf "%s: loading includes..." "$0" f_include $BSDCFG_SHARE/dialog.subr ############################################################ MAIN : ${BSDDIALOG_OK=0} : ${BSDDIALOG_CANCEL=1} INTERFACE=$1 IFCONFIG_PREFIX="$2" test -z "$IFCONFIG_PREFIX" || IFCONFIG_PREFIX="$2 " case "${INTERFACE}" in "") bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ --msgbox 'No interface specified for IPv4 configuration.' 0 0 exit 1 ;; esac bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 if [ $? -eq $BSDDIALOG_OK ]; then if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then # XXX: get interface down otherwise after installation restart # dhclient does not build a new resolv.conf (see PR262262). ifconfig $INTERFACE down ifconfig $INTERFACE up bsddialog --backtitle "$OSNAME Installer" --infobox "Acquiring DHCP lease..." 0 0 err=$( pkill -F /var/run/dhclient/dhclient.${INTERFACE}.pid; dhclient $INTERFACE 2>&1 ) if [ $? -ne 0 ]; then f_dprintf "%s" "$err" bsddialog --backtitle "$OSNAME Installer" --msgbox "DHCP lease acquisition failed." 0 0 exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}" fi fi - sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE "${IFCONFIG_PREFIX}DHCP" + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_$INTERFACE="${IFCONFIG_PREFIX}DHCP" exit 0 fi IP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'` NETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'` ROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'` exec 5>&1 IF_CONFIG=$(bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ 'IP Address' 1 1 "$IP_ADDRESS" 1 20 16 0 \ 'Subnet Mask' 2 1 "$NETMASK" 2 20 16 0 \ 'Default Router' 3 1 "$ROUTER" 3 20 16 0 \ 2>&1 1>&5) if [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi exec 5>&- echo $INTERFACE $IF_CONFIG | awk -v prefix="$IFCONFIG_PREFIX" '{ printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); printf("defaultrouter=\"%s\"\n", $4); }' >> $BSDINSTALL_TMPETC/._rc.conf.net retval=$? if [ "$BSDINSTALL_CONFIGCURRENT" ]; then . $BSDINSTALL_TMPETC/._rc.conf.net if [ -n "$2" ]; then ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE | sed "s|$2||"` else ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE` fi if [ "$defaultrouter" ]; then route delete -inet default route add -inet default $defaultrouter retval=$? fi fi exit $retval ################################################################################ # END ################################################################################ diff --git a/usr.sbin/bsdinstall/scripts/netconfig_ipv6 b/usr.sbin/bsdinstall/scripts/netconfig_ipv6 index 99ec379197fb..b851069eee14 100755 --- a/usr.sbin/bsdinstall/scripts/netconfig_ipv6 +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv6 @@ -1,162 +1,162 @@ #!/bin/sh #- # Copyright (c) 2011 Nathan Whitehorn # Copyright (c) 2011 The FreeBSD Foundation # Copyright (c) 2013-2015 Devin Teske # All rights reserved. # # Portions of this software were developed by Bjoern Zeeb # under sponsorship from the FreeBSD Foundation. # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions # are met: # 1. Redistributions of source code must retain the above copyright # notice, this list of conditions and the following disclaimer. # 2. Redistributions in binary form must reproduce the above copyright # notice, this list of conditions and the following disclaimer in the # documentation and/or other materials provided with the distribution. # # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF # SUCH DAMAGE. # # ############################################################ INCLUDES BSDCFG_SHARE="/usr/share/bsdconfig" . $BSDCFG_SHARE/common.subr || exit 1 f_dprintf "%s: loading includes..." "$0" f_include $BSDCFG_SHARE/dialog.subr ############################################################ MAIN : ${BSDDIALOG_OK=0} : ${BSDDIALOG_CANCEL=1} # # TODO: # - Add DHCPv6 support once FreeBSD ships with it. # INTERFACE=$1 case "${INTERFACE}" in "") bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ --msgbox 'No interface specified for IPv6 configuration.' 0 0 exit 1 ;; esac AGAIN="" while : ; do MSG="Would you like to try stateless address autoconfiguration (SLAAC)${AGAIN}?" bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \ --yesno "${MSG}" 0 0 if [ $? -eq $BSDDIALOG_OK ]; then if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then bsddialog --backtitle "$OSNAME Installer" \ --infobox "Sending Router Solicitation ..." 0 0 ifconfig ${INTERFACE} inet6 -ifdisabled accept_rtadv up err=$( rtsol -F $INTERFACE 2>&1 ) if [ $? -ne 0 ]; then f_dprintf "%s" "$err" bsddialog --backtitle "$OSNAME Installer" --msgbox "SLAAC failed." 0 0 AGAIN=" again" continue fi fi - sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_${INTERFACE}_ipv6 "inet6 accept_rtadv" + sysrc -f $BSDINSTALL_TMPETC/._rc.conf.net ifconfig_${INTERFACE}_ipv6="inet6 accept_rtadv" exit 0 else break fi done ROUTER6=`netstat -Wrn -f inet6 | awk '/default/ {printf("%s\n", $2);}'` ADDRS=`ifconfig ${INTERFACE} inet6 | \ awk -v dfr="${ROUTER6}" ' BEGIN { n=0; } { if (/inet6/) { if (match($2, "^fe80:")) { next; }; # For the moment ignore all but the first address; it might confuse the user. if (n > 0) { next; }; n++; printf "\"IPv6 Address\" %d 1 \"%s/%s\" %d 16 50 50 0 ", n, $2, $4, n; } } END { if (n == 0) { n++; printf "\"IPv6 Address\" %d 1 \"\" %d 16 50 50 0 ", n, n; } n++; # Nasty trick adding a (hidden, same y) read-only field as a marker # to separate interface address(es) from the default router. printf "\"Default Router\" %d 1 \"%s\" %d 1 14 14 2 ", n, "DefaultRouter", n; printf "\"Default Router\" %d 1 \"%s\" %d 16 50 50 0 ", n, dfr, n; }'` exec 5>&1 IF_CONFIG=$(echo ${ADDRS} | xargs -o bsddialog --backtitle "$OSNAME Installer" \ --title 'Network Configuration' \ --mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \ 2>&1 1>&5) if [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi exec 5>&- echo ${IF_CONFIG} | tr ' ' '\n' | \ awk -v iface="${INTERFACE}" ' BEGIN { dfr=0; count=0; } { if (/^[[:space:]]+$/) { next; } if (/DefaultRouter/) { dfr=1; next; } if (dfr == 1) { printf("ipv6_defaultrouter=\"%s\"\n", $1); next; } if (count > 0) { # Ignore all but the first IP address for now. next; } count++; if (!match($1, "/")) { sub("$", "/64", $1); } printf("ifconfig_%s_ipv6=\"inet6 %s\"\n", iface, $1); }' >> $BSDINSTALL_TMPETC/._rc.conf.net retval=$? if [ "$BSDINSTALL_CONFIGCURRENT" ]; then . $BSDINSTALL_TMPETC/._rc.conf.net ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6` if [ "$ipv6_defaultrouter" ]; then route delete -inet6 default route add -inet6 default ${ipv6_defaultrouter} retval=$? fi fi exit $retval ################################################################################ # END ################################################################################