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 42NIC="$1" 43IP="$2" 44NETMASK="$3" 45DNS="$4" 46GATEWAY="$5" 47MIRRORFETCH="$6" 48IPV6="$7" 49IPV6GATE="$8" 50IPV6DNS="$9" 51 52if [ -z "${NIC}" ] 53then 54 echo "ERROR: Usage enable-net <nic> <ip> <netmask> <dns> <gateway> <ipv6> " \ 55 "<ipv6gateway> <ipv6dns>" 56 exit 150 57fi 58 59if [ "$NIC" = "AUTO-DHCP" ] 60then 61 enable_auto_dhcp 62elif [ "$NIC" = "IPv6-SLAAC" ] 63then 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 85else 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 109fi 110 111case ${MIRRORFETCH} in 112 ON|on|yes|YES) fetch -o /tmp/mirrors-list.txt ${MIRRORLIST} >/dev/null 2>/dev/null;; 113 *) ;; 114esac 115