3 # Copyright (c) 2011 Nathan Whitehorn
4 # Copyright (c) 2013-2015 Devin Teske
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
16 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30 ############################################################ INCLUDES
32 BSDCFG_SHARE="/usr/share/bsdconfig"
33 . $BSDCFG_SHARE/common.subr || exit 1
34 f_dprintf "%s: loading includes..." "$0"
35 f_include $BSDCFG_SHARE/dialog.subr
37 ############################################################ MAIN
40 : ${BSDDIALOG_CANCEL=1}
44 test -z "$IFCONFIG_PREFIX" || IFCONFIG_PREFIX="$2 "
45 case "${INTERFACE}" in
46 "") bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' \
47 --msgbox 'No interface specified for IPv4 configuration.' 0 0
52 bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0
53 if [ $? -eq $BSDDIALOG_OK ]; then
54 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
55 # XXX: get interface down otherwise after installation restart
56 # dhclient does not build a new resolv.conf (see PR262262).
57 ifconfig $INTERFACE down
58 ifconfig $INTERFACE up
59 bsddialog --backtitle "$OSNAME Installer" --infobox "Acquiring DHCP lease..." 0 0
60 err=$( pkill -F /var/run/dhclient/dhclient.${INTERFACE}.pid; dhclient $INTERFACE 2>&1 )
63 bsddialog --backtitle "$OSNAME Installer" --msgbox "DHCP lease acquisition failed." 0 0
64 exec $0 ${INTERFACE} "${IFCONFIG_PREFIX}"
67 echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/._rc.conf.net
71 IP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'`
72 NETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'`
73 ROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'`
76 IF_CONFIG=$(bsddialog --backtitle "$OSNAME Installer" --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \
77 'IP Address' 1 1 "$IP_ADDRESS" 1 20 16 0 \
78 'Subnet Mask' 2 1 "$NETMASK" 2 20 16 0 \
79 'Default Router' 3 1 "$ROUTER" 3 20 16 0 \
81 if [ $? -eq $BSDDIALOG_CANCEL ]; then exit 1; fi
84 echo $INTERFACE $IF_CONFIG |
85 awk -v prefix="$IFCONFIG_PREFIX" '{
86 printf("ifconfig_%s=\"%s\inet %s netmask %s\"\n", $1, prefix, $2, $3);
87 printf("defaultrouter=\"%s\"\n", $4);
88 }' >> $BSDINSTALL_TMPETC/._rc.conf.net
91 if [ "$BSDINSTALL_CONFIGCURRENT" ]; then
92 . $BSDINSTALL_TMPETC/._rc.conf.net
94 ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE | sed "s|$2||"`
96 ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE`
98 if [ "$defaultrouter" ]; then
99 route delete -inet default
100 route add -inet default $defaultrouter
107 ################################################################################
109 ################################################################################