17986af23SBjoern A. Zeeb#!/bin/sh 27986af23SBjoern A. Zeeb#- 37986af23SBjoern A. Zeeb# Copyright (c) 2011 Nathan Whitehorn 4*5e1ed71eSDevin Teske# Copyright (c) 2013-2015 Devin Teske 57986af23SBjoern A. Zeeb# All rights reserved. 67986af23SBjoern A. Zeeb# 77986af23SBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 87986af23SBjoern A. Zeeb# modification, are permitted provided that the following conditions 97986af23SBjoern A. Zeeb# are met: 107986af23SBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 117986af23SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 127986af23SBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 137986af23SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 147986af23SBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 157986af23SBjoern A. Zeeb# 167986af23SBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 177986af23SBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 187986af23SBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 197986af23SBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 207986af23SBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 217986af23SBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 227986af23SBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 237986af23SBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 247986af23SBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 257986af23SBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 267986af23SBjoern A. Zeeb# SUCH DAMAGE. 277986af23SBjoern A. Zeeb# 287986af23SBjoern A. Zeeb# $FreeBSD$ 29bc4a673fSDevin Teske# 30bc4a673fSDevin Teske############################################################ INCLUDES 317986af23SBjoern A. Zeeb 32bc4a673fSDevin TeskeBSDCFG_SHARE="/usr/share/bsdconfig" 33bc4a673fSDevin Teske. $BSDCFG_SHARE/common.subr || exit 1 34bc4a673fSDevin Teskef_dprintf "%s: loading includes..." "$0" 35bc4a673fSDevin Teskef_include $BSDCFG_SHARE/dialog.subr 36bc4a673fSDevin Teske 37bc4a673fSDevin Teske############################################################ MAIN 387986af23SBjoern A. Zeeb 397986af23SBjoern A. ZeebINTERFACE=$1 407986af23SBjoern A. ZeebIFCONFIG_PREFIX="$2" 413d50f942SNathan Whitehorntest -z "$IFCONFIG_PREFIX" || IFCONFIG_PREFIX="$2 " 427986af23SBjoern A. Zeebcase "${INTERFACE}" in 437986af23SBjoern A. Zeeb"") dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 447986af23SBjoern A. Zeeb --msgbox 'No interface specified for IPv4 configuration.' 0 0 457986af23SBjoern A. Zeeb exit 1 467986af23SBjoern A. Zeeb ;; 477986af23SBjoern A. Zeebesac 487986af23SBjoern A. Zeeb 497986af23SBjoern A. Zeebdialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 507986af23SBjoern A. Zeebif [ $? -eq $DIALOG_OK ]; then 51d63d020eSBjoern A. Zeeb echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/._rc.conf.net 527986af23SBjoern A. Zeeb 537986af23SBjoern A. Zeeb if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 547986af23SBjoern A. Zeeb dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0 55bc4a673fSDevin Teske err=$( dhclient $INTERFACE 2>&1 ) 567986af23SBjoern A. Zeeb if [ $? -ne 0 ]; then 57bc4a673fSDevin Teske f_dprintf "%s" "$err" 587986af23SBjoern A. Zeeb dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0 597986af23SBjoern A. Zeeb exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}" 607986af23SBjoern A. Zeeb fi 617986af23SBjoern A. Zeeb fi 627986af23SBjoern A. Zeeb exit 0 637986af23SBjoern A. Zeebfi 647986af23SBjoern A. Zeeb 657986af23SBjoern A. ZeebIP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'` 667986af23SBjoern A. ZeebNETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'` 677986af23SBjoern A. ZeebROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'` 687986af23SBjoern A. Zeeb 697986af23SBjoern A. Zeebexec 3>&1 707986af23SBjoern A. ZeebIF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ 717986af23SBjoern A. Zeeb 'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \ 727986af23SBjoern A. Zeeb 'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \ 737986af23SBjoern A. Zeeb 'Default Router' 3 0 "$ROUTER" 3 20 16 0 \ 747986af23SBjoern A. Zeeb2>&1 1>&3) 757986af23SBjoern A. Zeebif [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi 767986af23SBjoern A. Zeebexec 3>&- 777986af23SBjoern A. Zeeb 787986af23SBjoern A. Zeebecho $INTERFACE $IF_CONFIG | 797986af23SBjoern A. Zeeb awk -v prefix="$IFCONFIG_PREFIX" '{ 80e01a4776SKevin Lo printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); 817986af23SBjoern A. Zeeb printf("defaultrouter=\"%s\"\n", $4); 82d63d020eSBjoern A. Zeeb }' >> $BSDINSTALL_TMPETC/._rc.conf.net 83*5e1ed71eSDevin Teskeretval=$? 847986af23SBjoern A. Zeeb 85*5e1ed71eSDevin Teskeif [ "$BSDINSTALL_CONFIGCURRENT" ]; then 86d63d020eSBjoern A. Zeeb . $BSDINSTALL_TMPETC/._rc.conf.net 87b5cb9d4fSBjoern A. Zeeb ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE` 88*5e1ed71eSDevin Teske if [ "$defaultrouter" ]; then 897986af23SBjoern A. Zeeb route delete -inet default 907986af23SBjoern A. Zeeb route add -inet default $defaultrouter 91*5e1ed71eSDevin Teske retval=$? 927986af23SBjoern A. Zeeb fi 935b046b47SBjoern A. Zeebfi 947986af23SBjoern A. Zeeb 95*5e1ed71eSDevin Teskeexit $retval 96*5e1ed71eSDevin Teske 97bc4a673fSDevin Teske################################################################################ 98bc4a673fSDevin Teske# END 99bc4a673fSDevin Teske################################################################################ 100