Deleted Added
full compact
netconfig (218799) netconfig (222468)
1#!/bin/sh
2#-
3# Copyright (c) 2011 Nathan Whitehorn
4# All rights reserved.
1#!/bin/sh
2#-
3# Copyright (c) 2011 Nathan Whitehorn
4# All rights reserved.
5# Copyright (c) 2011 The FreeBSD Foundation
6# All rights reserved.
5#
7#
8# Portions of this software were developed by Bjoern Zeeb
9# under sponsorship from the FreeBSD Foundation.
10#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions
8# are met:
9# 1. Redistributions of source code must retain the above copyright
10# notice, this list of conditions and the following disclaimer.
11# 2. Redistributions in binary form must reproduce the above copyright
12# notice, this list of conditions and the following disclaimer in the
13# documentation and/or other materials provided with the distribution.

--- 5 unchanged lines hidden (view full) ---

19# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25# SUCH DAMAGE.
26#
11# Redistribution and use in source and binary forms, with or without
12# modification, are permitted provided that the following conditions
13# are met:
14# 1. Redistributions of source code must retain the above copyright
15# notice, this list of conditions and the following disclaimer.
16# 2. Redistributions in binary form must reproduce the above copyright
17# notice, this list of conditions and the following disclaimer in the
18# documentation and/or other materials provided with the distribution.

--- 5 unchanged lines hidden (view full) ---

24# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30# SUCH DAMAGE.
31#
27# $FreeBSD: head/usr.sbin/bsdinstall/scripts/netconfig 218799 2011-02-18 14:54:34Z nwhitehorn $
32# $FreeBSD: head/usr.sbin/bsdinstall/scripts/netconfig 222468 2011-05-29 21:24:20Z bz $
28
29INTERFACES=""
30DIALOG_TAGS=""
31
32: ${DIALOG_OK=0}
33: ${DIALOG_CANCEL=1}
34: ${DIALOG_HELP=2}
35: ${DIALOG_EXTRA=3}

--- 25 unchanged lines hidden (view full) ---

61 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
62 ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE
63 ifconfig $NEXT_WLAN_IFACE up
64 fi
65 bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0
66 INTERFACE="$NEXT_WLAN_IFACE"
67fi
68
33
34INTERFACES=""
35DIALOG_TAGS=""
36
37: ${DIALOG_OK=0}
38: ${DIALOG_CANCEL=1}
39: ${DIALOG_HELP=2}
40: ${DIALOG_EXTRA=3}

--- 25 unchanged lines hidden (view full) ---

66 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
67 ifconfig $NEXT_WLAN_IFACE create wlandev $INTERFACE
68 ifconfig $NEXT_WLAN_IFACE up
69 fi
70 bsdinstall wlanconfig $NEXT_WLAN_IFACE || exec $0
71 INTERFACE="$NEXT_WLAN_IFACE"
72fi
73
69dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --yesno 'Would you like to use DHCP to configure this interface?' 0 0
70if [ $? -eq $DIALOG_OK ]; then
71 echo ifconfig_$INTERFACE=\"${IFCONFIG_PREFIX}DHCP\" >> $BSDINSTALL_TMPETC/rc.conf.net
74IPV6_AVAIL=0
75IPV4_AVAIL=0
76sysctl -N kern.features.inet6 > /dev/null 2>&1
77case $? in
780) IPV6_AVAIL=1 ;;
79esac
80sysctl -N kern.features.inet > /dev/null 2>&1
81case $? in
820) IPV4_AVAIL=1 ;;
83esac
72
84
73 if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
74 dialog --backtitle 'FreeBSD Installer' --infobox "Acquiring DHCP lease..." 0 0
75 dhclient $INTERFACE 2>> $BSDINSTALL_LOG
76 if [ $? -ne 0 ]; then
77 dialog --backtitle 'FreeBSD Installer' --msgbox "DHCP lease acquisition failed." 0 0
78 exec $0
79 fi
85if [ ${IPV4_AVAIL} -eq 1 ]; then
86 dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
87 --yesno 'Would you like to configure IPv4 for this interface?' 0 0
88 if [ $? -eq $DIALOG_OK ]; then
89 bsdinstall netconfig_ipv4 ${INTERFACE} "${IFCONFIG_PREFIX}" || \
90 exec $0
91 else
92 IPV4_AVAIL=0
80 fi
93 fi
81 exit 0
82fi
94fi
95# In case wlanconfig left an option and we do not support IPv4 we need to write
96# it out on its own. We cannot write it out with IPv6 as that suffix.
97if [ ${IPV4_AVAIL} -eq 0 -a -n ${IFCONFIG_PREFIX} ]; then
98 echo ifconfig_${INTERFACE}=\"${IFCONFIG_PREFIX}\" >> $BSDINSTALL_TMPETC/rc.conf.net
99fi
100if [ ${IPV6_AVAIL} -eq 1 ]; then
101 dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' \
102 --yesno 'Would you like to configure IPv6 for this interface?' 0 0
103 if [ $? -eq $DIALOG_OK ]; then
104 bsdinstall netconfig_ipv6 ${INTERFACE} || exec $0
105 else
106 IPV6_AVAIL=0
107 fi
108fi
83
109
84IP_ADDRESS=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $2); }'`
85NETMASK=`ifconfig $INTERFACE inet | awk '/inet/ {printf("%s\n", $4); }'`
86ROUTER=`netstat -rn -f inet | awk '/default/ {printf("%s\n", $2);}'`
110SEARCH=""
111IP4_1=""
112IP4_2=""
113IP6_1=""
114IP6_2=""
115while read key value; do
116 case "${key}" in
117 search) SEARCH="${value}" ;;
118 nameserver) # is more trick as we have to distinguish v4 and v6
119 case "${value}" in
120 [0-9]*\.[0-9]*\.[0-9]*\.[0-9]*)
121 if [ -z "${IP4_1}" ] ; then
122 IP4_1="${value}"
123 elif [ -z "${IP4_2}" ]; then
124 IP4_2="${value}"
125 fi
126 ;;
127 [0-9A-Fa-f:]*:*)
128 if [ -z "${IP6_1}" ] ; then
129 IP6_1="${value}"
130 elif [ -z "${IP6_2}" ]; then
131 IP6_2="${value}"
132 fi
133 ;;
134 esac
135 ;;
136 # ignore others
137 esac
138done < ${BSDINSTALL_TMPETC}/resolv.conf
87
139
140RESOLV=""
141if [ ${IPV6_AVAIL} -eq 1 -a ${IPV4_AVAIL} -eq 1 ]; then
142 RESOLV="
143 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0
144 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2
145 'IPv6 DNS #1' 2 0 \"${IP6_1}\" 2 16 50 0 0
146 'IPv6 DNS #2' 3 0 \"${IP6_2}\" 3 16 50 0 0
147 'IPv4 DNS #1' 4 0 \"${IP4_1}\" 4 16 16 0 0
148 'IPv4 DNS #2' 5 0 \"${IP4_2}\" 5 16 16 0 0"
149elif [ ${IPV6_AVAIL} -eq 1 ]; then
150 RESOLV="
151 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0
152 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2
153 'IPv6 DNS #1' 2 0 \"${IP6_1}\" 2 16 50 0 0
154 'IPv6 DNS #2' 3 0 \"${IP6_2}\" 3 16 50 0 0"
155elif [ ${IPV4_AVAIL} -eq 1 ]; then
156 RESOLV="
157 'Search' 1 0 \"${SEARCH}\" 1 16 50 0 0
158 'Nameserver' 2 0 \"Nameserver\" 2 16 50 0 2
159 'IPv4 DNS #1' 2 0 \"${IP4_1}\" 2 16 16 0 0
160 'IPv4 DNS #2' 3 0 \"${IP4_2}\" 3 16 16 0 0"
161else
162 exit 0
163fi
164
88exec 3>&1
165exec 3>&1
89IF_CONFIG=$(dialog --backtitle 'FreeBSD Installer' --title 'Network Configuration' --form 'Static Network Interface Configuration' 0 0 0 \
90 'IP Address' 1 0 "$IP_ADDRESS" 1 20 16 0 \
91 'Subnet Mask' 2 0 "$NETMASK" 2 20 16 0 \
92 'Default Router' 3 0 "$ROUTER" 3 20 16 0 \
93 \
94 'Nameserver' 5 0 "" 5 20 16 0 \
95 'Search Domain' 6 0 "" 6 20 20 0 \
166RESOLV=$(echo "${RESOLV}" | xargs dialog --backtitle 'FreeBSD Installer' \
167 --title 'Network Configuration' \
168 --mixedform 'Resovler Configuration' 0 0 0 \
962>&1 1>&3)
97if [ $? -eq $DIALOG_CANCEL ]; then exec $0; fi
98exec 3>&-
99
1692>&1 1>&3)
170if [ $? -eq $DIALOG_CANCEL ]; then exec $0; fi
171exec 3>&-
172
100echo $INTERFACE $IF_CONFIG |
101 awk -v prefix="$IFCONFIG_PREFIX" '{
102 printf("ifconfig_%s=\"%s%s netmask %s\"\n", $1, prefix, $2, $3);
103 printf("defaultrouter=\"%s\"\n", $4);
104 }' >> $BSDINSTALL_TMPETC/rc.conf.net
173echo ${RESOLV} | tr ' ' '\n' | \
174awk '
175BEGIN {
176 search=1
177 printf "search ";
178}
179{
180 if (/^[[:space:]]+$/) {
181 next;
182 }
183 if (/^Nameserver$/) {
184 printf "\n";
185 search=0;
186 next;
187 }
188 if (search > 0) {
189 printf "%s%s", (search > 1) ? "," : "", $1;
190 next;
191 }
192 printf "nameserver %s\n", $1;
193}' > ${BSDINSTALL_TMPETC}/resolv.conf
105
194
106if [ ! -z $BSDINSTALL_CONFIGCURRENT ]; then
107 . $BSDINSTALL_TMPETC/rc.conf.net
108 ifconfig $INTERFACE `eval echo \\\$ifconfig_$INTERFACE`
109 route delete default
110 route add default $defaultrouter
111fi
112
113
114echo $IF_CONFIG |
115 awk '{
116 if ($4 != "")
117 printf("nameserver %s\n", $4);
118 if ($5 != "")
119 printf("search %s\n", $5);
120 }' > $BSDINSTALL_TMPETC/resolv.conf
121