1209513Simp#!/bin/sh 2209513Simp#- 3209552Simp# Copyright (c) 2010 iXsystems, Inc. All rights reserved. 4222528Sbz# Copyright (c) 2011 The FreeBSD Foundation 5222528Sbz# All rights reserved. 6209513Simp# 7222528Sbz# Portions of this software were developed by Bjoern Zeeb 8222528Sbz# under sponsorship from the FreeBSD Foundation. 9222528Sbz# 10209513Simp# Redistribution and use in source and binary forms, with or without 11209513Simp# modification, are permitted provided that the following conditions 12209513Simp# are met: 13209513Simp# 1. Redistributions of source code must retain the above copyright 14209513Simp# notice, this list of conditions and the following disclaimer. 15209513Simp# 2. Redistributions in binary form must reproduce the above copyright 16209513Simp# notice, this list of conditions and the following disclaimer in the 17209513Simp# documentation and/or other materials provided with the distribution. 18209513Simp# 19209513Simp# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 20209513Simp# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21209513Simp# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22209513Simp# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 23209513Simp# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24209513Simp# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25209513Simp# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26209513Simp# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27209513Simp# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28209513Simp# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29209513Simp# SUCH DAMAGE. 30209513Simp# 31209513Simp# $FreeBSD$ 32209513Simp 33209513Simp# Script which enables networking with specified options 34209513Simp########################################################################### 35209513Simp 36209513Simp. ${PROGDIR}/backend/functions.sh 37209513Simp. ${PROGDIR}/conf/pc-sysinstall.conf 38209513Simp. ${BACKEND}/functions-networking.sh 39209513Simp. ${BACKEND}/functions-parse.sh 40209513Simp 41209513Simp 42209513SimpNIC="$1" 43209513SimpIP="$2" 44209513SimpNETMASK="$3" 45209513SimpDNS="$4" 46209513SimpGATEWAY="$5" 47209513SimpMIRRORFETCH="$6" 48222528SbzIPV6="$7" 49222528SbzIPV6GATE="$8" 50222528SbzIPV6DNS="$9" 51209513Simp 52209513Simpif [ -z "${NIC}" ] 53209513Simpthen 54222528Sbz echo "ERROR: Usage enable-net <nic> <ip> <netmask> <dns> <gateway> <ipv6> " \ 55222528Sbz "<ipv6gateway> <ipv6dns>" 56209513Simp exit 150 57209513Simpfi 58209513Simp 59209513Simpif [ "$NIC" = "AUTO-DHCP" ] 60209513Simpthen 61209513Simp enable_auto_dhcp 62222528Sbzelif [ "$NIC" = "IPv6-SLAAC" ] 63222528Sbzthen 64222528Sbz enable_auto_slaac 65222528Sbz # In addition, if static values were defined, add them as well. 66222528Sbz # We might not get DNS information from RAs, for example. 67222528Sbz if [ -n "${IPV6}" ]; then 68222528Sbz VAL="" 69222528Sbz get_first_wired_nic 70222528Sbz if [ -n "${VAL}" ]; then 71222528Sbz ifconfig ${VAL} inet6 ${IPV6} alias 72222528Sbz fi 73222528Sbz fi 74222528Sbz # Append only here. 75222528Sbz if [ -n "${IPV6DNS}" ]; then 76222528Sbz echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf 77222528Sbz fi 78222528Sbz # Do not 79222528Sbz if [ -n "${IPV6GATE}" ]; then 80222528Sbz # Check if we have a default route already to not overwrite. 81222528Sbz if ! route -n get -inet6 default > /dev/null 2>&1 ; then 82222528Sbz route add -inet6 default ${IPV6GATE} 83222528Sbz fi 84222528Sbz fi 85209513Simpelse 86209513Simp echo "Enabling NIC: $NIC" 87222528Sbz if [ -n "${IP}" ]; then 88222528Sbz ifconfig ${NIC} inet ${IP} ${NETMASK} 89222528Sbz fi 90222528Sbz if [ -n "${IPV6}" ]; then 91222528Sbz ifconfig ${NIC} inet6 ${IPV6} alias 92222528Sbz fi 93209513Simp 94222528Sbz # Keep default from IPv4-only support times and clear the resolv.conf file. 95222528Sbz : > /etc/resolv.conf 96222528Sbz if [ -n "${DNS}" ]; then 97222528Sbz echo "nameserver ${DNS}" >>/etc/resolv.conf 98222528Sbz fi 99222528Sbz if [ -n "${IPV6DNS}" ]; then 100222528Sbz echo "nameserver ${IPV6DNS}" >>/etc/resolv.conf 101222528Sbz fi 102209513Simp 103222528Sbz if [ -n "${GATE}" ]; then 104222528Sbz route add -inet default ${GATE} 105222528Sbz fi 106222528Sbz if [ -n "${IPV6GATE}" ]; then 107222528Sbz route add -inet6 default ${IPV6GATE} 108222528Sbz fi 109209513Simpfi 110209513Simp 111209513Simpcase ${MIRRORFETCH} in 112211730Simp ON|on|yes|YES) fetch -o /tmp/mirrors-list.txt ${MIRRORLIST} >/dev/null 2>/dev/null;; 113211730Simp *) ;; 114209513Simpesac 115