Statistics
| Branch: | Revision:

root / example / instance-image.d / interfaces @ 08abb89f

History | View | Annotate | Download (3.2 kB)

1
#!/bin/bash
2

    
3
# Copyright (C) 2010 Oregon State University
4
#
5
# This program is free software; you can redistribute it and/or modify
6
# it under the terms of the GNU General Public License as published by
7
# the Free Software Foundation; either version 2 of the License, or
8
# (at your option) any later version.
9
#
10
# This program is distributed in the hope that it will be useful, but
11
# WITHOUT ANY WARRANTY; without even the implied warranty of
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
# General Public License for more details.
14
#
15
# You should have received a copy of the GNU General Public License
16
# along with this program; if not, write to the Free Software
17
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18
# 02110-1301, USA.
19
#
20
# This is an example script that configures your network settings after
21
# installation. By default it sets it up to use dhcp.
22

    
23
set -e
24

    
25
. common.sh
26

    
27
if [ "${IMAGE_DEBUG} " = 1 ] ; then
28
    set -x
29
fi
30

    
31
DIG="$(which dig)"
32

    
33
# discover fqdn name using dig
34
if [ -n "$NIC_0_IP" -a -n "${DIG}" ] ; then
35
    FQDN="$(${DIG} -x ${NIC_0_IP} +short | sed -e 's/\.$//')"
36
fi
37

    
38
if [ -z "${TARGET}" -o ! -d "${TARGET}" ] ; then
39
    log_error "Missing target directory"
40
    exit 1
41
fi
42

    
43
if [ -z "${NIC_COUNT}" ] ; then
44
    log_error "Missing NIC_COUNT"
45
    exit 1
46
fi
47

    
48
# Functions
49
debian_setup() {
50
    if [ ! -d "${TARGET}/etc/network" ] ; then
51
        log_error "Missing target network directory"
52
        exit 1
53
    fi
54
    cat > ${TARGET}/etc/network/interfaces << EOF
55
# This file describes the network interfaces available on your system
56
# and how to activate them. For more information, see interfaces(5).
57

    
58
auto lo
59
iface lo inet loopback
60

    
61
auto eth0
62
iface eth0 inet dhcp
63

    
64
EOF
65

    
66
    if [ -n "${FQDN}" ] ; then
67
        echo "${FQDN}" > ${TARGET}/etc/hostname
68
    fi
69
}
70

    
71
redhat_setup() {
72
    if [ ! -d "${TARGET}/etc/sysconfig/network-scripts" ] ; then
73
        log_error "Missing target network directory"
74
        exit 1
75
    fi
76
    cat > ${TARGET}/etc/sysconfig/network-scripts/ifcfg-eth0 << EOF
77
DEVICE=eth0
78
BOOTPROTO=dhcp
79
HWADDR=${NIC_0_MAC^^[a-z]}
80
ONBOOT=yes
81
EOF
82

    
83
    if [ -n "${FQDN}" ] ; then
84
        cat > ${TARGET}/etc/sysconfig/network << EOF
85
NETWORKING=yes
86
HOSTNAME=${FQDN}
87
EOF
88
    else
89
        cat > ${TARGET}/etc/sysconfig/network << EOF
90
NETWORKING=yes
91
EOF
92
    fi
93
}
94

    
95
gentoo_setup() {
96
    if [ ! -f "${TARGET}/etc/conf.d/net" ] ; then
97
        log_error "Missing target network file"
98
        exit 1
99
    fi
100
    cat > ${TARGET}/etc/conf.d/net << EOF
101
config_eth0=( "dhcp" )
102
EOF
103
    chroot ${TARGET} rc-update add net.eth0 default
104

    
105
    if [ -n "${FQDN}" ] ; then
106
        cat > ${TARGET}/etc/conf.d/hostname << EOF
107
HOSTNAME="${FQDN}"
108
EOF
109
    fi
110
}
111

    
112
suse_setup() {
113
    if [ ! -d ${TARGET}/etc/sysconfig/network ] ; then
114
        log_error "Missing target network directory"
115
        exit 1
116
    fi
117
    cat > ${TARGET}/etc/sysconfig/network/ifcfg-eth0 << EOF
118
BOOTPROTO='dhcp4'
119
LLADDR='${NIC_0_MAC^^[a-z]}'
120
STARTMODE='auto'
121
NAME='Ethernet Card 0'
122
EOF
123
    if [ -n "${FQDN}" ] ; then
124
        echo "${FQDN}" > ${TARGET}/etc/HOSTNAME
125
    fi
126
}
127

    
128
# Main
129
get_os_type
130

    
131
if [ "${NIC_COUNT}" -gt 0 -a -n "${OS_TYPE}" ] ; then
132
    ${OS_TYPE}_setup
133
else
134
    log_error "Unsupported OS_TYPE"
135
fi
136

    
137

    
138
exit 0