Statistics
| Branch: | Revision:

root / example / instance-image.d / interfaces @ e7a2d1ad

History | View | Annotate | Download (3.1 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
debug set -x
28

    
29
DIG="$(which dig)"
30

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

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

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

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

    
56
auto lo
57
iface lo inet loopback
58

    
59
auto eth0
60
iface eth0 inet dhcp
61

    
62
EOF
63

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

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

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

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

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

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

    
126
# Main
127
get_os_type
128

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

    
135

    
136
exit 0