xref: /freebsd/usr.sbin/bsdinstall/scripts/netconfig_ipv4 (revision 5b046b47ec1229879125ec0222a0e12854447921)
17986af23SBjoern A. Zeeb#!/bin/sh
27986af23SBjoern A. Zeeb#-
37986af23SBjoern A. Zeeb# Copyright (c) 2011 Nathan Whitehorn
47986af23SBjoern A. Zeeb# All rights reserved.
57986af23SBjoern A. Zeeb#
67986af23SBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without
77986af23SBjoern A. Zeeb# modification, are permitted provided that the following conditions
87986af23SBjoern A. Zeeb# are met:
97986af23SBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright
107986af23SBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer.
117986af23SBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright
127986af23SBjoern A. Zeeb#    notice, this list of conditions and the following disclaimer in the
137986af23SBjoern A. Zeeb#    documentation and/or other materials provided with the distribution.
147986af23SBjoern A. Zeeb#
157986af23SBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
167986af23SBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
177986af23SBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
187986af23SBjoern A. Zeeb# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
197986af23SBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
207986af23SBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
217986af23SBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
227986af23SBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
237986af23SBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
247986af23SBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
257986af23SBjoern A. Zeeb# SUCH DAMAGE.
267986af23SBjoern A. Zeeb#
277986af23SBjoern A. Zeeb# $FreeBSD$
287986af23SBjoern A. Zeeb
297986af23SBjoern A. Zeeb: ${DIALOG_OK=0}
307986af23SBjoern A. Zeeb: ${DIALOG_CANCEL=1}
317986af23SBjoern A. Zeeb: ${DIALOG_HELP=2}
327986af23SBjoern A. Zeeb: ${DIALOG_EXTRA=3}
337986af23SBjoern A. Zeeb: ${DIALOG_ITEM_HELP=4}
347986af23SBjoern A. Zeeb: ${DIALOG_ESC=255}
357986af23SBjoern A. Zeeb
367986af23SBjoern A. ZeebINTERFACE=$1
377986af23SBjoern A. ZeebIFCONFIG_PREFIX="$2"
387986af23SBjoern A. Zeebcase "${INTERFACE}" in
397986af23SBjoern A. Zeeb"")	dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
407986af23SBjoern A. Zeeb	    --msgbox 'No interface specified for IPv4 configuration.' 0 0
417986af23SBjoern A. Zeeb	exit 1
427986af23SBjoern A. Zeeb	;;
437986af23SBjoern A. Zeebesac
447986af23SBjoern A. Zeeb
457986af23SBjoern A. Zeebdialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0
467986af23SBjoern A. Zeebif [ $? -eq $DIALOG_OK ]; then
47d63d020eSBjoern A. Zeeb	echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/._rc.conf.net
487986af23SBjoern A. Zeeb
497986af23SBjoern A. Zeeb	if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
507986af23SBjoern A. Zeeb		dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0
517986af23SBjoern A. Zeeb		dhclient $INTERFACE 2>> $BSDINSTALL_LOG
527986af23SBjoern A. Zeeb		if [ $? -ne 0 ]; then
537986af23SBjoern A. Zeeb			dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0
547986af23SBjoern A. Zeeb			exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}"
557986af23SBjoern A. Zeeb		fi
567986af23SBjoern A. Zeeb	fi
577986af23SBjoern A. Zeeb	exit 0
587986af23SBjoern A. Zeebfi
597986af23SBjoern A. Zeeb
607986af23SBjoern A. ZeebIP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'`
617986af23SBjoern A. ZeebNETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'`
627986af23SBjoern A. ZeebROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'`
637986af23SBjoern A. Zeeb
647986af23SBjoern A. Zeebexec 3>&1
657986af23SBjoern A. ZeebIF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \
667986af23SBjoern A. Zeeb	'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \
677986af23SBjoern A. Zeeb	'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \
687986af23SBjoern A. Zeeb	'Default Router' 3 0 "$ROUTER" 3 20 16 0 \
697986af23SBjoern A. Zeeb2>&1 1>&3)
707986af23SBjoern A. Zeebif [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi
717986af23SBjoern A. Zeebexec 3>&-
727986af23SBjoern A. Zeeb
737986af23SBjoern A. Zeebecho $INTERFACE $IF_CONFIG |
747986af23SBjoern A. Zeeb    awk -v prefix="$IFCONFIG_PREFIX" '{
757986af23SBjoern A. Zeeb	printf("ifconfig_%s=\"%s inet %s netmask %s\"\n", $1, prefix, $2, $3);
767986af23SBjoern A. Zeeb	printf("defaultrouter=\"%s\"\n", $4);
77d63d020eSBjoern A. Zeeb    }' >> $BSDINSTALL_TMPETC/._rc.conf.net
787986af23SBjoern A. Zeeb
797986af23SBjoern A. Zeebif [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
80d63d020eSBjoern A. Zeeb	. $BSDINSTALL_TMPETC/._rc.conf.net
81b5cb9d4fSBjoern A. Zeeb	ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE`
82*5b046b47SBjoern A. Zeeb	if [ -n "${defaultrouter}" ]; then
837986af23SBjoern A. Zeeb		route delete -inet default
847986af23SBjoern A. Zeeb		route add -inet default $defaultrouter
857986af23SBjoern A. Zeeb	fi
86*5b046b47SBjoern A. Zeebfi
877986af23SBjoern A. Zeeb
88