]> CyberLeo.Net >> Repos - FreeBSD/releng/9.2.git/blob - usr.sbin/pc-sysinstall/backend-query/enable-net.sh
- Copy stable/9 to releng/9.2 as part of the 9.2-RELEASE cycle.
[FreeBSD/releng/9.2.git] / usr.sbin / pc-sysinstall / backend-query / enable-net.sh
1 #!/bin/sh
2 #-
3 # Copyright (c) 2010 iXsystems, Inc.  All rights reserved.
4 # Copyright (c) 2011 The FreeBSD Foundation
5 # All rights reserved.
6 #
7 # Portions of this software were developed by Bjoern Zeeb
8 # under sponsorship from the FreeBSD Foundation.
9 #
10 # Redistribution and use in source and binary forms, with or without
11 # modification, are permitted provided that the following conditions
12 # are met:
13 # 1. Redistributions of source code must retain the above copyright
14 #    notice, this list of conditions and the following disclaimer.
15 # 2. Redistributions in binary form must reproduce the above copyright
16 #    notice, this list of conditions and the following disclaimer in the
17 #    documentation and/or other materials provided with the distribution.
18 #
19 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 # ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 # SUCH DAMAGE.
30 #
31 # $FreeBSD$
32
33 # Script which enables networking with specified options
34 ###########################################################################
35
36 . ${PROGDIR}/backend/functions.sh
37 . ${PROGDIR}/conf/pc-sysinstall.conf
38 . ${BACKEND}/functions-networking.sh
39 . ${BACKEND}/functions-parse.sh
40
41
42 NIC="$1"
43 IP="$2"
44 NETMASK="$3"
45 DNS="$4"
46 GATEWAY="$5"
47 MIRRORFETCH="$6"
48 IPV6="$7"
49 IPV6GATE="$8"
50 IPV6DNS="$9"
51
52 if [ -z "${NIC}" ]
53 then
54   echo "ERROR: Usage enable-net <nic> <ip> <netmask> <dns> <gateway> <ipv6> " \
55         "<ipv6gateway> <ipv6dns>"
56   exit 150
57 fi
58
59 if [ "$NIC" = "AUTO-DHCP" ]
60 then
61   enable_auto_dhcp
62 elif [ "$NIC" = "IPv6-SLAAC" ]
63 then
64   enable_auto_slaac
65   # In addition, if static values were defined, add them as well.
66   # We might not get DNS information from RAs, for example.
67   if [ -n "${IPV6}" ]; then
68     VAL=""
69     get_first_wired_nic
70     if [ -n "${VAL}" ]; then
71       ifconfig ${VAL} inet6 ${IPV6} alias
72     fi
73   fi
74   # Append only here.
75   if [ -n "${IPV6DNS}" ]; then
76     echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf
77   fi
78   # Do not 
79   if [ -n "${IPV6GATE}" ]; then
80     # Check if we have a default route already to not overwrite.
81     if ! route -n get -inet6 default > /dev/null 2>&1 ; then
82       route add -inet6 default ${IPV6GATE}
83     fi
84   fi
85 else
86   echo "Enabling NIC: $NIC"
87   if [ -n "${IP}" ]; then
88     ifconfig ${NIC} inet ${IP} ${NETMASK}
89   fi
90   if [ -n "${IPV6}" ]; then
91     ifconfig ${NIC} inet6 ${IPV6} alias
92   fi
93
94   # Keep default from IPv4-only support times and clear the resolv.conf file.
95   : > /etc/resolv.conf
96   if [ -n "${DNS}" ]; then
97     echo "nameserver ${DNS}" >>/etc/resolv.conf
98   fi
99   if [ -n "${IPV6DNS}" ]; then
100     echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf
101   fi
102
103   if [ -n "${GATE}" ]; then
104     route add -inet default ${GATE}
105   fi
106   if [ -n "${IPV6GATE}" ]; then
107     route add -inet6 default ${IPV6GATE}
108   fi
109 fi
110
111 case ${MIRRORFETCH} in
112   ON|on|yes|YES) fetch -o /tmp/mirrors-list.txt ${MIRRORLIST} >/dev/null 2>/dev/null;;
113   *) ;;
114 esac