1222468Sbz#!/bin/sh 2222468Sbz#- 3222468Sbz# Copyright (c) 2011 Nathan Whitehorn 4263956Sdteske# Copyright (c) 2013 Devin Teske 5222468Sbz# All rights reserved. 6222468Sbz# 7222468Sbz# Redistribution and use in source and binary forms, with or without 8222468Sbz# modification, are permitted provided that the following conditions 9222468Sbz# are met: 10222468Sbz# 1. Redistributions of source code must retain the above copyright 11222468Sbz# notice, this list of conditions and the following disclaimer. 12222468Sbz# 2. Redistributions in binary form must reproduce the above copyright 13222468Sbz# notice, this list of conditions and the following disclaimer in the 14222468Sbz# documentation and/or other materials provided with the distribution. 15222468Sbz# 16222468Sbz# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17222468Sbz# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18222468Sbz# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19222468Sbz# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20222468Sbz# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21222468Sbz# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22222468Sbz# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23222468Sbz# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24222468Sbz# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25222468Sbz# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26222468Sbz# SUCH DAMAGE. 27222468Sbz# 28222468Sbz# $FreeBSD$ 29263956Sdteske# 30263956Sdteske############################################################ INCLUDES 31222468Sbz 32263956SdteskeBSDCFG_SHARE="/usr/share/bsdconfig" 33263956Sdteske. $BSDCFG_SHARE/common.subr || exit 1 34263956Sdteskef_dprintf "%s: loading includes..." "$0" 35263956Sdteskef_include $BSDCFG_SHARE/dialog.subr 36222468Sbz 37263956Sdteske############################################################ MAIN 38263956Sdteske 39222468SbzINTERFACE=$1 40222468SbzIFCONFIG_PREFIX="$2" 41225612Snwhitehorntest -z "$IFCONFIG_PREFIX" || IFCONFIG_PREFIX="$2 " 42222468Sbzcase "${INTERFACE}" in 43222468Sbz"") dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \ 44222468Sbz --msgbox 'No interface specified for IPv4 configuration.' 0 0 45222468Sbz exit 1 46222468Sbz ;; 47222468Sbzesac 48222468Sbz 49222468Sbzdialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0 50222468Sbzif [ $? -eq $DIALOG_OK ]; then 51222619Sbz echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/._rc.conf.net 52222468Sbz 53222468Sbz if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 54222468Sbz dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0 55263956Sdteske err=$( dhclient $INTERFACE 2>&1 ) 56222468Sbz if [ $? -ne 0 ]; then 57263956Sdteske f_dprintf "%s" "$err" 58222468Sbz dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0 59222468Sbz exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}" 60222468Sbz fi 61222468Sbz fi 62222468Sbz exit 0 63222468Sbzfi 64222468Sbz 65222468SbzIP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'` 66222468SbzNETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'` 67222468SbzROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'` 68222468Sbz 69222468Sbzexec 3>&1 70222468SbzIF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \ 71222468Sbz 'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \ 72222468Sbz 'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \ 73222468Sbz 'Default Router' 3 0 "$ROUTER" 3 20 16 0 \ 74222468Sbz2>&1 1>&3) 75222468Sbzif [ $? -eq $DIALOG_CANCEL ]; then exit 1; fi 76222468Sbzexec 3>&- 77222468Sbz 78222468Sbzecho $INTERFACE $IF_CONFIG | 79222468Sbz awk -v prefix="$IFCONFIG_PREFIX" '{ 80263956Sdteske printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3); 81222468Sbz printf("defaultrouter=\"%s\"\n", $4); 82222619Sbz }' >> $BSDINSTALL_TMPETC/._rc.conf.net 83222468Sbz 84222468Sbzif [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then 85222619Sbz . $BSDINSTALL_TMPETC/._rc.conf.net 86224470Sbz ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE` 87225429Sbz if [ -n "${defaultrouter}" ]; then 88225429Sbz route delete -inet default 89225429Sbz route add -inet default $defaultrouter 90225429Sbz fi 91222468Sbzfi 92222468Sbz 93263956Sdteske################################################################################ 94263956Sdteske# END 95263956Sdteske################################################################################ 96