head	1.8;
access;
symbols
	RELENG_9_1_0_RELEASE:1.6.2.2.4.2
	RELENG_9_1:1.6.2.2.0.4
	RELENG_9_1_BP:1.6.2.2
	RELENG_9_0_0_RELEASE:1.6.2.2.2.1
	RELENG_9_0:1.6.2.2.0.2
	RELENG_9_0_BP:1.6.2.2
	RELENG_9:1.6.0.2
	RELENG_9_BP:1.6;
locks; strict;
comment	@# @;


1.8
date	2012.11.17.01.54.40;	author svnexp;	state Exp;
branches;
next	1.7;

1.7
date	2011.10.25.16.35.48;	author nwhitehorn;	state Exp;
branches;
next	1.6;

1.6
date	2011.09.07.00.48.58;	author bz;	state Exp;
branches
	1.6.2.1;
next	1.5;

1.5
date	2011.06.04.12.51.22;	author bz;	state Exp;
branches;
next	1.4;

1.4
date	2011.06.02.14.25.27;	author bz;	state Exp;
branches;
next	1.3;

1.3
date	2011.06.02.14.08.50;	author bz;	state Exp;
branches;
next	1.2;

1.2
date	2011.05.29.21.24.20;	author bz;	state Exp;
branches;
next	1.1;

1.1
date	2011.02.18.14.54.34;	author nwhitehorn;	state Exp;
branches;
next	;

1.6.2.1
date	2011.09.23.00.51.37;	author kensmith;	state Exp;
branches;
next	1.6.2.2;

1.6.2.2
date	2011.11.06.16.37.50;	author nwhitehorn;	state Exp;
branches
	1.6.2.2.2.1
	1.6.2.2.4.1;
next	1.6.2.3;

1.6.2.3
date	2012.11.17.11.37.43;	author svnexp;	state Exp;
branches;
next	1.6.2.4;

1.6.2.4
date	2014.03.31.02.01.46;	author svnexp;	state Exp;
branches;
next	;

1.6.2.2.2.1
date	2011.11.11.04.20.22;	author kensmith;	state Exp;
branches;
next	1.6.2.2.2.2;

1.6.2.2.2.2
date	2012.11.17.08.37.39;	author svnexp;	state Exp;
branches;
next	;

1.6.2.2.4.1
date	2012.08.05.23.54.33;	author kensmith;	state Exp;
branches;
next	1.6.2.2.4.2;

1.6.2.2.4.2
date	2012.11.17.08.48.31;	author svnexp;	state Exp;
branches;
next	;


desc
@@


1.8
log
@Switching exporter and resync
@
text
@#!/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: head/usr.sbin/bsdinstall/scripts/netconfig 226741 2011-10-25 16:35:48Z nwhitehorn $

INTERFACES=""
DIALOG_TAGS=""

: ${DIALOG_OK=0}
: ${DIALOG_CANCEL=1}
: ${DIALOG_HELP=2}
: ${DIALOG_EXTRA=3}
: ${DIALOG_ITEM_HELP=4}
: ${DIALOG_ESC=255}

for IF in `ifconfig -l`; do
	test "$IF" = "lo0" && continue
	(ifconfig -g wlan | egrep -wq $IF) && continue
	INTERFACES="$INTERFACES $IF"
	DESC=`sysctl -n dev.$(echo $IF | sed -E 's/([[:alpha:]]*)([[:digit:]]*)/\1.\2/g').%desc`
	DIALOG_TAGS="$DIALOG_TAGS $IF \"$DESC\""
done

if [ -z "$INTERFACES" ]; then
	dialog --backtitle 'FreeBSD Installer' \
	    --title 'Network Configuration Error' \
	    --msgbox 'No network interfaces present to configure.' 0 0
	exit 1
fi

exec 3>&1
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`
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
	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
	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
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 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
RESOLV=$(echo "${RESOLV}" | xargs dialog --backtitle 'FreeBSD Installer' \
	--title 'Network Configuration' \
	--mixedform 'Resolver Configuration' 0 0 0 \
2>&1 1>&3)
if [ $? -eq $DIALOG_CANCEL ]; then exec $0; fi
exec 3>&-

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
@


1.7
log
@SVN rev 226741 on 2011-10-25 16:35:48Z by nwhitehorn

Provide an error message and error handling if there are no network
interfaces in the system. This is a non-fatal error except when doing a
network installation.

PR:		bin/161950
MFC after:	3 days
@
text
@d32 1
a32 1
# $FreeBSD$
@


1.6
log
@SVN rev 225430 on 2011-09-07 00:48:58Z by bz

Correct a typo.

Submitted by:	gcooper
Reviewed by:	nwhitehorn
Approved by:	re (kib)
@
text
@d52 7
@


1.6.2.1
log
@SVN rev 225736 on 2011-09-23 00:51:37Z by kensmith

Copy head to stable/9 as part of 9.0-RELEASE release cycle.

Approved by:	re (implicit)
@
text
@@


1.6.2.2
log
@SVN rev 227222 on 2011-11-06 16:37:50Z by nwhitehorn

MFC r226666,226739,226741:
Avoid showing the user some spurious error messages from GEOM [1] and do
provide error messages instead of silent failure if there are no disks
or no network interfaces in the system [2].

PR:		bin/161926 [1], bin/161926 [2]
Approved by:	re (kib)
@
text
@a51 7
if [ -z "$INTERFACES" ]; then
	dialog --backtitle 'FreeBSD Installer' \
	    --title 'Network Configuration Error' \
	    --msgbox 'No network interfaces present to configure.' 0 0
	exit 1
fi

@


1.6.2.3
log
@## SVN ##
## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/ 242902
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ## r242902 | dteske | 2012-11-11 23:29:45 +0000 (Sun, 11 Nov 2012) | 10 lines
## SVN ##
## SVN ## Fix a regression introduced by SVN r211417 that saw the breakage of a feature
## SVN ## documented in usr.sbin/sysinstall/help/shortcuts.hlp (reproduced below):
## SVN ##
## SVN ## If /usr/sbin/sysinstall is linked to another filename, say
## SVN ## `/usr/local/bin/configPackages', then the basename will be used
## SVN ## as an implicit command name.
## SVN ##
## SVN ## Reviewed by:	adrian (co-mentor)
## SVN ## Approved by:	adrian (co-mentor)
## SVN ##
## SVN ## ------------------------------------------------------------------------
## SVN ##
@
text
@d32 1
a32 1
# $FreeBSD: stable/9/usr.sbin/bsdinstall/scripts/netconfig 227222 2011-11-06 16:37:50Z nwhitehorn $
@


1.6.2.4
log
@## SVN ## Exported commit - http://svnweb.freebsd.org/changeset/base/263956
## SVN ## CVS IS DEPRECATED: http://wiki.freebsd.org/CvsIsDeprecated
@
text
@d32 1
a32 1
# $FreeBSD: stable/9/usr.sbin/bsdinstall/scripts/netconfig 263956 2014-03-31 01:04:40Z dteske $
a43 6
# Do a dirty check to see if this a wireless interface -- there should be a
# better way
is_wireless_if() {
	ifconfig $1 | grep -q 'media: IEEE 802.11 Wireless'
}

a48 2
	is_wireless_if $IF && echo $DESC |
		grep -iqv wireless && DESC="Wireless $DESC"
d66 2
d69 1
a69 1
if is_wireless_if $INTERFACE; then
@


1.6.2.2.4.1
log
@SVN rev 239080 on 2012-08-05 23:54:33Z by kensmith

Copy stable/9 to releng/9.1 as part of the 9.1-RELEASE release process.

Approved by:	re (implicit)
@
text
@@


1.6.2.2.4.2
log
@Switch importer
@
text
@d32 1
a32 1
# $FreeBSD: releng/9.1/usr.sbin/bsdinstall/scripts/netconfig 227222 2011-11-06 16:37:50Z nwhitehorn $
@


1.6.2.2.2.1
log
@SVN rev 227445 on 2011-11-11 04:20:22Z by kensmith

Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
cycle.

Approved by:	re (implicit)
@
text
@@


1.6.2.2.2.2
log
@Switch importer
@
text
@d32 1
a32 1
# $FreeBSD: releng/9.0/usr.sbin/bsdinstall/scripts/netconfig 227222 2011-11-06 16:37:50Z nwhitehorn $
@


1.5
log
@SVN rev 222681 on 2011-06-04 12:51:22Z by bz

Fix resolv.conf search list creation:
1) do not print out an empty "search ", things do not like it.
2) the search list is not comma separated.

Sponsored by:	The FreeBSD Foundation
Sponsored by:	iXsystems
@
text
@d168 1
a168 1
	--mixedform 'Resovler Configuration' 0 0 0 \
@


1.4
log
@SVN rev 222619 on 2011-06-02 14:25:27Z by bz

Write the multi step netconfig to a temporary file and only move that
to the final name if netconfig was completely finished.  This fixes
reentrance problems even better than r222611.

Suggested by:	nwhitehorn
Reviewed by:	nwhitehorn
Sponsored by:	The FreeBSD Foundation
Sponsored by:	iXsystems
@
text
@d176 1
a176 2
	search=1
	printf "search ";
d187 4
d192 2
a193 1
		printf "%s%s", (search > 1) ? "," : "", $1;
@


1.3
log
@SVN rev 222611 on 2011-06-02 14:08:50Z by bz

Empty the network configuration only after the user decided to pick an
interface.  Otherwise an accidental start of the netowrk configuration
and immediate cancel after the install has finished removes the previously
configured settings.

Discussed with:	nwhitehorn
Sponsored by:	The FreeBSD Foundation
Sponsored by:	iXsystems
@
text
@d57 1
a57 1
: > $BSDINSTALL_TMPETC/rc.conf.net
d64 1
a64 1
	echo wlans_$INTERFACE=\"$NEXT_WLAN_IFACE\" >> $BSDINSTALL_TMPETC/rc.conf.net
d98 1
a98 1
	echo ifconfig_${INTERFACE}=\"${IFCONFIG_PREFIX}\" >> $BSDINSTALL_TMPETC/rc.conf.net
d195 1
@


1.2
log
@SVN rev 222468 on 2011-05-29 21:24:20Z by bz

Split netconfig into three parts:
- netconfig - what auto will call which in turn will check for
  IPv4 and IPv6 to be available and ask the user to configure it
  by calling
- netconfig_ipv4 doing DHCP and static IPv4 addresses, and
- netconfig_ipv6 doing rtsol and static IPv6 addresses,
and then checking, querying and updating resolv.conf upon return.
Both DHCP and rtsol (in the future) might update resolv.conf already so
we seed ourselves from that file if available.

Reviewed by:	nwhitehorn
Sponsored by:	The FreeBSD Foundation
Sponsored by:	iXsystems
@
text
@a43 2
echo -n > $BSDINSTALL_TMPETC/rc.conf.net

d57 2
@


1.1
log
@SVN rev 218799 on 2011-02-18 14:54:34Z by nwhitehorn

Import bsdinstall. This is meant to be (eventually in conjunction with
pc-sysinstall) a replacement for sysinstall in the 9.0 release and beyond.
Currently supported platforms are sparc64, pc98, i386, amd64, powerpc, and
powerpc64. Integration into the build system will occur in the coming
weeks.

Merging with pc-sysinstall will use this code as a frontend, while
temporarily retaining the interactive partition editor here. This work
will be done in parallel with improvements on this code and release
integration.

Thanks to all who have provided testing and comments!
@
text
@d5 5
d74 35
a108 3
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
d110 52
a161 8
	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
	fi
a164 4
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);}'`

d166 3
a168 7
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 \
d173 21
a193 21
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
@

