1*7986af23SBjoern A. Zeeb#!/bin/sh 2*7986af23SBjoern A. Zeeb#- 3*7986af23SBjoern A. Zeeb# Copyright (c) 2011 Nathan Whitehorn 4*7986af23SBjoern A. Zeeb# All rights reserved. 5*7986af23SBjoern A. Zeeb# 6*7986af23SBjoern A. Zeeb# Redistribution and use in source and binary forms, with or without 7*7986af23SBjoern A. Zeeb# modification, are permitted provided that the following conditions 8*7986af23SBjoern A. Zeeb# are met: 9*7986af23SBjoern A. Zeeb# 1. Redistributions of source code must retain the above copyright 10*7986af23SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer. 11*7986af23SBjoern A. Zeeb# 2. Redistributions in binary form must reproduce the above copyright 12*7986af23SBjoern A. Zeeb# notice, this list of conditions and the following disclaimer in the 13*7986af23SBjoern A. Zeeb# documentation and/or other materials provided with the distribution. 14*7986af23SBjoern A. Zeeb# 15*7986af23SBjoern A. Zeeb# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16*7986af23SBjoern A. Zeeb# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17*7986af23SBjoern A. Zeeb# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18*7986af23SBjoern A. Zeeb# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19*7986af23SBjoern A. Zeeb# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20*7986af23SBjoern A. Zeeb# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21*7986af23SBjoern A. Zeeb# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22*7986af23SBjoern A. Zeeb# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23*7986af23SBjoern A. Zeeb# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24*7986af23SBjoern A. Zeeb# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25*7986af23SBjoern A. Zeeb# SUCH DAMAGE. 26*7986af23SBjoern A. Zeeb# 27*7986af23SBjoern A. Zeeb# $FreeBSD$ 28*7986af23SBjoern A. Zeeb 29*7986af23SBjoern A. Zeeb: ${DIALOG_OK=0} 30*7986af23SBjoern A. Zeeb: ${DIALOG_CANCEL=1} 31*7986af23SBjoern A. Zeeb: ${DIALOG_HELP=2} 32*7986af23SBjoern A. Zeeb: ${DIALOG_EXTRA=3} 33*7986af23SBjoern A. Zeeb: ${DIALOG_ITEM_HELP=4} 34*7986af23SBjoern A. Zeeb: ${DIALOG_ESC=255} 35*7986af23SBjoern A. Zeeb 36*7986af23SBjoern A. ZeebINTERFACE=$1 37*7986af23SBjoern A. ZeebIFCONFIG_PREFIX="$2" 38*7986af23SBjoern A. Zeebcase "${INTERFACE}" in 39*7986af23SBjoern A. Zeeb"") dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 40*7986af23SBjoern A. Zeeb --msgbox 'No interface specified for IPv4 configuration.' 0 0 41*7986af23SBjoern A. Zeeb exit 1 42*7986af23SBjoern A. Zeeb ;; 43*7986af23SBjoern A. Zeebesac 44*7986af23SBjoern A. Zeeb 45*7986af23SBjoern A. Zeebdialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 46*7986af23SBjoern A. Zeebif [ $? -eq $DIALOG_OK ]; then 47*7986af23SBjoern A. Zeeb echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/rc.conf.net 48*7986af23SBjoern A. Zeeb 49*7986af23SBjoern A. Zeeb if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 50*7986af23SBjoern A. Zeeb dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0 51*7986af23SBjoern A. Zeeb dhclient $INTERFACE 2>> $BSDINSTALL_LOG 52*7986af23SBjoern A. Zeeb if [ $? -ne 0 ]; then 53*7986af23SBjoern A. Zeeb dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0 54*7986af23SBjoern A. Zeeb exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}" 55*7986af23SBjoern A. Zeeb fi 56*7986af23SBjoern A. Zeeb fi 57*7986af23SBjoern A. Zeeb exit 0 58*7986af23SBjoern A. Zeebfi 59*7986af23SBjoern A. Zeeb 60*7986af23SBjoern A. ZeebIP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'` 61*7986af23SBjoern A. ZeebNETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'` 62*7986af23SBjoern A. ZeebROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'` 63*7986af23SBjoern A. Zeeb 64*7986af23SBjoern A. Zeebexec 3>&1 65*7986af23SBjoern A. ZeebIF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ 66*7986af23SBjoern A. Zeeb 'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \ 67*7986af23SBjoern A. Zeeb 'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \ 68*7986af23SBjoern A. Zeeb 'Default Router' 3 0 "$ROUTER" 3 20 16 0 \ 69*7986af23SBjoern A. Zeeb2>&1 1>&3) 70*7986af23SBjoern A. Zeebif [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi 71*7986af23SBjoern A. Zeebexec 3>&- 72*7986af23SBjoern A. Zeeb 73*7986af23SBjoern A. Zeebecho $INTERFACE $IF_CONFIG | 74*7986af23SBjoern A. Zeeb awk -v prefix="$IFCONFIG_PREFIX" '{ 75*7986af23SBjoern A. Zeeb printf("ifconfig_%s=\"%s inet %s netmask %s\"\n", $1, prefix, $2, $3); 76*7986af23SBjoern A. Zeeb printf("defaultrouter=\"%s\"\n", $4); 77*7986af23SBjoern A. Zeeb }' >> $BSDINSTALL_TMPETC/rc.conf.net 78*7986af23SBjoern A. Zeeb 79*7986af23SBjoern A. Zeebif [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 80*7986af23SBjoern A. Zeeb . $BSDINSTALL_TMPETC/rc.conf.net 81*7986af23SBjoern A. Zeeb ifconfig $INTERFACE inet `eval echo \\\$ifconfig_$INTERFACE` 82*7986af23SBjoern A. Zeeb route delete -inet default 83*7986af23SBjoern A. Zeeb route add -inet default $defaultrouter 84*7986af23SBjoern A. Zeebfi 85*7986af23SBjoern A. Zeeb 86