diff options
Diffstat (limited to 'usr.sbin/bsdinstall')
-rw-r--r-- | usr.sbin/bsdinstall/Makefile | 1 | ||||
-rw-r--r-- | usr.sbin/bsdinstall/bsdinstall.8 | 187 | ||||
-rw-r--r-- | usr.sbin/bsdinstall/scripts/Makefile | 3 | ||||
-rwxr-xr-x | usr.sbin/bsdinstall/scripts/auto | 4 | ||||
-rwxr-xr-x | usr.sbin/bsdinstall/scripts/netconfig | 168 | ||||
-rwxr-xr-x | usr.sbin/bsdinstall/scripts/netconfig_ipv4 | 85 | ||||
-rwxr-xr-x | usr.sbin/bsdinstall/scripts/netconfig_ipv6 | 148 |
7 files changed, 548 insertions, 48 deletions
diff --git a/usr.sbin/bsdinstall/Makefile b/usr.sbin/bsdinstall/Makefile index 5e39b0b..e72b5d3 100644 --- a/usr.sbin/bsdinstall/Makefile +++ b/usr.sbin/bsdinstall/Makefile @@ -2,5 +2,6 @@ SUBDIR= distextract distfetch partedit scripts SCRIPTS= bsdinstall +MAN= bsdinstall.8 .include <bsd.prog.mk> diff --git a/usr.sbin/bsdinstall/bsdinstall.8 b/usr.sbin/bsdinstall/bsdinstall.8 new file mode 100644 index 0000000..4b8b51e --- /dev/null +++ b/usr.sbin/bsdinstall/bsdinstall.8 @@ -0,0 +1,187 @@ +.\"- +.\" Copyright (c) 2011 Nathan Whitehorn <nwhitehorn@FreeBSD.org> +.\" 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 ``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 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. +.\" +.\" $FreeBSD$ +.\" +.Dd June 11, 2011 +.Dt bsdinstall 8 +.Os +.Sh NAME +.Nm bsdinstall +.Nd system installer +.Sh SYNOPSIS +.Nm +.Op Ar target +.Op Ar ... +.Sh DESCRIPTION +.Nm +is used for installation of new systems, both for system setup from +installation media (e.g. CD-ROMs) and for use on live systems to prepare +VM images and jails. +.Pp +Much like +.Xr make 1 , Nm +takes a target and possible parameters of the target as arguments. If +invoked with no arguments, it will invoke the +.Cm auto +target, which provides a standard interactive installation, invoking the +others in sequence. To perform a scripted installation, these subtargets +can be invoked separately by an installation script. +.Sh TARGETS +Most of the following targets are only useful for scripting the installer. +For interactive use, most users will be interested only in the +.Cm auto +and +.Cm jail +targets. +.Bl -tag -width ".Cm jail Ar destination" +.It Cm auto +Run the standard interactive installation, including disk partitioning. +.It Cm jail Ar destination +Sets up a new chroot system at +.Pa destination , +suitable for use with +.Xr jail 8 . +Behavior is generally similar to +.Cm auto , +except that disk partitioning and network setup are skipped and a kernel is +not installed into the new system. +.It Cm keymap +If the current controlling TTY is a +.Xr syscons 4 +console, asks the user to set the current keymap, and saves the result to the +new system's +.Pa rc.conf . +.It Cm hostname +Prompts the user for a host name for the new system and saves the result to the +new system's +.Pa rc.conf . +If +.Ev BSDINSTALL_CONFIGCURRENT +is set, also sets the host name of the current system. +.It Cm netconfig +Interactively configures network interfaces (first invoking +.Cm wlanconfig +on wireless interfaces), saving the result to the new system's +.Pa rc.conf +and +.Pa resolv.conf . +If +.Ev BSDINSTALL_CONFIGCURRENT +is set, also configures the network interfaces of the current system to match. +.It Cm autopart +Provides the installer's interactive guided disk partitioner for single-disk +installations. Partitions disks, runs +.Xr newfs 8 , +and writes the new system's +.Pa fstab . +.It Cm partedit +Provides the installer's interactive manual disk partitioner, with support +for multi disk setups, non-UFS file systems, and manual selection of +partition schemes. Partitions disks, runs +.Xr newfs 8 , +and writes the new system's +.Pa fstab . +.It Cm mount +Mounts the file systems previously configured by +.Cm autopart +or +.Cm partedit +under +.Ev BSDINSTALL_CHROOT . +.It Cm distfetch +Fetches the distributions in +.Ev DISTRIBUTIONS +to +.Ev BSDINSTALL_DISTDIR +from +.Ev BSDINSTALL_DISTSITE . +.It Cm checksum +Verifies the checksums of the distributions listed in +.Ev DISTRIBUTIONS +against the distribution manifest. +.It Cm distextract +Extracts the distributions listed in +.Ev DISTRIBUTIONS +into +.Ev BSDINSTALL_CHROOT . +.It Cm rootpass +Interactively invokes +.Xr passwd 1 +in the new system to set the root user's password. +.It Cm adduser +Interactively invokes +.Xr adduser 8 +in the new system. +.It Cm time +Interactively sets the time, date, and time zone of the new system. +.It Cm services +Queries the user for the system daemons to begin at system startup, +writing the result into the new system's +.Pa rc.conf . +.It Cm config +Installs the configuration files destined for the new system (e.g. rc.conf +fragments generated by +.Cm netconfig , +etc.) onto the new system. +.El +.Sh ENVIRONMENT VARIABLES +The following environment variables control various aspects of the installation +process. Many are used internally during installation and have reasonable +default values for most installation scenarios. Others are set by various +interactive user prompts, and can be usefully overridden when making scripted +or customized installers. +.Bl -tag -width ".Ev BSDINSTALL_DISTDIR" +.It Ev DISTRIBUTIONS +The set of distributions to install (e.g. "base kernel ports"). Default: none +.It Ev BSDINSTALL_DISTDIR +The directory in which the distribution files can be found (or to which they +should be downloaded). Default: +.Pa /usr/freebsd-dist +.It Ev BSDINSTALL_CHROOT +The directory into which the distribution files should be unpacked and the +directory at which the root file system of the new system should be mounted. +Default: +.Pa /mnt +.It Ev BSDINSTALL_LOG +Path to a log file for the installation. Default: +.Pa /tmp/bsdinstall_log +.It Ev BSDINSTALL_TMPETC +Directory where files destined for the new system's +.Pa /etc +will be stored until the +.Cm config +target is executed. If this directory does not already exist, it will be +created. Default: +.Pa /tmp/bsdinstall_etc +.El +.Sh HISTORY +This version of +.Nm +first appeared in +.Fx 9.0 . +.Sh AUTHORS +.An -nosplit +.An Nathan Whitehorn Aq nwhitehorn@FreeBSD.org diff --git a/usr.sbin/bsdinstall/scripts/Makefile b/usr.sbin/bsdinstall/scripts/Makefile index 8ad6744..e32fda6 100644 --- a/usr.sbin/bsdinstall/scripts/Makefile +++ b/usr.sbin/bsdinstall/scripts/Makefile @@ -1,7 +1,8 @@ # $FreeBSD$ SCRIPTS= auto adduser checksum config hostname jail keymap mirrorselect \ - mount netconfig rootpass services time umount wlanconfig + mount netconfig netconfig_ipv4 netconfig_ipv6 rootpass services \ + time umount wlanconfig BINDIR= /usr/libexec/bsdinstall NO_MAN= true diff --git a/usr.sbin/bsdinstall/scripts/auto b/usr.sbin/bsdinstall/scripts/auto index c163c2c..bdc5fc4 100755 --- a/usr.sbin/bsdinstall/scripts/auto +++ b/usr.sbin/bsdinstall/scripts/auto @@ -105,7 +105,7 @@ case $? in 1) # Shell clear echo "Use this shell to set up partitions for the new system. When finished, mount the system at $BSDINSTALL_CHROOT and place an fstab file for the new system at $PATH_FSTAB. Then type 'exit'. You can also enter the partition editor at any time by entering 'bsdinstall partedit'." - sh + sh 2>&1 ;; 3) # Manual bsdinstall partedit || error @@ -199,7 +199,7 @@ finalconfig() { clear echo This shell is operating in a chroot in the new system. \ When finished making configuration changes, type \"exit\". - chroot "$BSDINSTALL_CHROOT" /bin/sh + chroot "$BSDINSTALL_CHROOT" /bin/sh 2>&1 # Don't hose local rc.conf changes cp $BSDINSTALL_CHROOT/etc/rc.conf $BSDINSTALL_TMPETC/rc.conf.manual finalconfig diff --git a/usr.sbin/bsdinstall/scripts/netconfig b/usr.sbin/bsdinstall/scripts/netconfig index 0374d12..b78e330 100755 --- a/usr.sbin/bsdinstall/scripts/netconfig +++ b/usr.sbin/bsdinstall/scripts/netconfig @@ -2,6 +2,11 @@ #- # 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 @@ -36,8 +41,6 @@ DIALOG_TAGS="" : ${DIALOG_ITEM_HELP=4} : ${DIALOG_ESC=255} -echo -n > $BSDINSTALL_TMPETC/rc.conf.net - for IF in `ifconfig -l`; do test "$IF" = "lo0" && continue (ifconfig -g wlan | egrep -wq $IF) && continue @@ -51,12 +54,14 @@ INTERFACE=`echo $DIALOG_TAGS | xargs dialog --backtitle 'FreeBSD Installer' --ti if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi exec 3>&- +: > $BSDINSTALL_TMPETC/._rc.conf.net + # Do a dirty check to see if this a wireless interface -- there should be a # better way IFCONFIG_PREFIX="" if ifconfig $INTERFACE | grep -q 'media: IEEE 802.11 Wireless'; then NEXT_WLAN_IFACE=wlan0 # XXX - echo wlans_$INTERFACE=\"$NEXT_WLAN_IFACE\" >> $BSDINSTALL_TMPETC/rc.conf.net + echo wlans_$INTERFACE=\"$NEXT_WLAN_IFACE\" >> $BSDINSTALL_TMPETC/._rc.conf.net IFCONFIG_PREFIX="WPA " if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE @@ -66,56 +71,129 @@ if ifconfig $INTERFACE | grep -q 'media: IEEE 802.11 Wireless'; then INTERFACE="$NEXT_WLAN_IFACE" fi -dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 -if [ $? -eq $DIALOG_OK ]; then - echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/rc.conf.net +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 [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then - dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0 - dhclient $INTERFACE 2>> $BSDINSTALL_LOG - if [ $? -ne 0 ]; then - dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0 - exec $0 - fi +if [ ${IPV4_AVAIL} -eq 1 ]; then + dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ + --yesno 'Would you like to configure IPv4 for this interface?' 0 0 + if [ $? -eq $DIALOG_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 + echo ifconfig_${INTERFACE}=\"${IFCONFIG_PREFIX}\" >> $BSDINSTALL_TMPETC/._rc.conf.net +fi +if [ ${IPV6_AVAIL} -eq 1 ]; then + dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ + --yesno 'Would you like to configure IPv6 for this interface?' 0 0 + if [ $? -eq $DIALOG_OK ]; then + bsdinstall netconfig_ipv6 ${INTERFACE} || exec $0 + else + IPV6_AVAIL=0 fi - 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);}'` +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 0 \"${SEARCH}\" 1 16 50 0 0 + 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2 + 'IPv6 DNS #1' 2 0 \"${IP6_1}\" 2 16 50 0 0 + 'IPv6 DNS #2' 3 0 \"${IP6_2}\" 3 16 50 0 0 + 'IPv4 DNS #1' 4 0 \"${IP4_1}\" 4 16 16 0 0 + 'IPv4 DNS #2' 5 0 \"${IP4_2}\" 5 16 16 0 0" +elif [ ${IPV6_AVAIL} -eq 1 ]; then + RESOLV=" + 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0 + 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2 + 'IPv6 DNS #1' 2 0 \"${IP6_1}\" 2 16 50 0 0 + 'IPv6 DNS #2' 3 0 \"${IP6_2}\" 3 16 50 0 0" +elif [ ${IPV4_AVAIL} -eq 1 ]; then + RESOLV=" + 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0 + 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2 + 'IPv4 DNS #1' 2 0 \"${IP4_1}\" 2 16 16 0 0 + 'IPv4 DNS #2' 3 0 \"${IP4_2}\" 3 16 16 0 0" +else + exit 0 +fi exec 3>&1 -IF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ - 'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \ - 'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \ - 'Default Router' 3 0 "$ROUTER" 3 20 16 0 \ - \ - 'Nameserver' 5 0 "" 5 20 16 0 \ - 'Search Domain' 6 0 "" 6 20 20 0 \ +RESOLV=$(echo "${RESOLV}" | xargs dialog --backtitle 'FreeBSD Installer' \ + --title 'Network Configuration' \ + --mixedform 'Resovler Configuration' 0 0 0 \ 2>&1 1>&3) if [ $? -eq $DIALOG_CANCEL ]; then exec $0; fi exec 3>&- -echo $INTERFACE $IF_CONFIG | - awk -v prefix="$IFCONFIG_PREFIX" '{ - printf("ifconfig_%s=\"%s%s netmask %s\"\n", $1, prefix, $2, $3); - printf("defaultrouter=\"%s\"\n", $4); - }' >> $BSDINSTALL_TMPETC/rc.conf.net - -if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then - . $BSDINSTALL_TMPETC/rc.conf.net - ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE` - route delete default - route add default $defaultrouter -fi - - -echo $IF_CONFIG | - awk '{ - if ($4 != "") - printf("nameserver %s\n", $4); - if ($5 != "") - printf("search %s\n", $5); - }' > $BSDINSTALL_TMPETC/resolv.conf +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 new file mode 100755 index 0000000..72dc0ee --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv4 @@ -0,0 +1,85 @@ +#!/bin/sh +#- +# Copyright (c) 2011 Nathan Whitehorn +# 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. +# +# $FreeBSD$ + +: ${DIALOG_OK=0} +: ${DIALOG_CANCEL=1} +: ${DIALOG_HELP=2} +: ${DIALOG_EXTRA=3} +: ${DIALOG_ITEM_HELP=4} +: ${DIALOG_ESC=255} + +INTERFACE=$1 +IFCONFIG_PREFIX="$2" +case "${INTERFACE}" in +"") dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ + --msgbox 'No interface specified for IPv4 configuration.' 0 0 + exit 1 + ;; +esac + +dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 +if [ $? -eq $DIALOG_OK ]; then + echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/._rc.conf.net + + if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0 + dhclient $INTERFACE 2>> $BSDINSTALL_LOG + if [ $? -ne 0 ]; then + dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0 + exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}" + fi + fi + 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 3>&1 +IF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ + 'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \ + 'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \ + 'Default Router' 3 0 "$ROUTER" 3 20 16 0 \ +2>&1 1>&3) +if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi +exec 3>&- + +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 + +if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + . $BSDINSTALL_TMPETC/._rc.conf.net + ifconfig $INTERFACE inet `eval echo \\\$ifconfig_$INTERFACE` + route delete -inet default + route add -inet default $defaultrouter +fi + diff --git a/usr.sbin/bsdinstall/scripts/netconfig_ipv6 b/usr.sbin/bsdinstall/scripts/netconfig_ipv6 new file mode 100755 index 0000000..8bff816 --- /dev/null +++ b/usr.sbin/bsdinstall/scripts/netconfig_ipv6 @@ -0,0 +1,148 @@ +#!/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. +# +# $FreeBSD$ + +# +# TODO: +# - Add DHCPv6 support once FreeBSD ships with it. +# + +: ${DIALOG_OK=0} +: ${DIALOG_CANCEL=1} +: ${DIALOG_HELP=2} +: ${DIALOG_EXTRA=3} +: ${DIALOG_ITEM_HELP=4} +: ${DIALOG_ESC=255} + +INTERFACE=$1 +case "${INTERFACE}" in +"") dialog --backtitle 'FreeBSD 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}?" + dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ + --yesno "${MSG}" 0 0 + if [ $? -eq $DIALOG_OK ]; then + if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + dialog --backtitle 'FreeBSD Installer' \ + --infobox "Sending Router Solicitation ..." 0 0 + ifconfig ${INTERFACE} inet6 -ifdisabled accept_rtadv up + rtsol -F $INTERFACE 2>> $BSDINSTALL_LOG + if [ $? -ne 0 ]; then + dialog --backtitle 'FreeBSD Installer' --msgbox "SLAAC failed." 0 0 + AGAIN=" again" + continue + fi + fi + echo ifconfig_${INTERFACE}_ipv6=\"inet6 accept_rtadv\" >> $BSDINSTALL_TMPETC/._rc.conf.net + 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 0 \"%s/%s\" %d 16 50 0 0 ", n, $2, $4, n; + } +} +END { + if (n == 0) { + n++; + printf "\"IPv6 Address\" %d 0 \"\" %d 16 50 0 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 0 \"%s\" %d 16 50 0 2 ", n, "DefaultRouter", n; + printf "\"Default Router\" %d 0 \"%s\" %d 16 50 0 0 ", n, dfr, n; +}'` + +exec 3>&1 +IF_CONFIG=$(echo ${ADDRS} | xargs dialog --backtitle 'FreeBSD Installer' \ + --title 'Network Configuration' \ + --mixedform 'Static IPv6 Network Interface Configuration' 0 0 0 \ +2>&1 1>&3) +if [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi +exec 3>&- + +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 + +if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then + . $BSDINSTALL_TMPETC/._rc.conf.net + ifconfig ${INTERFACE} `eval echo \\\$ifconfig_${INTERFACE}_ipv6` + route delete default + route add default ${ipv6_defaultrouter} +fi + |