~ubuntu-branches/ubuntu/karmic/vzctl/karmic

« back to all changes in this revision

Viewing changes to etc/dists/scripts/redhat-add_ip.sh

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2007-04-10 18:08:16 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070410180816-0uuzj9fnna7gmzxv
Tags: 3.0.16-4
Etch has been released which means that this version can be uploaded
to unstable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/bin/bash
2
 
#  Copyright (C) 2000-2006 SWsoft. All rights reserved.
 
2
#  Copyright (C) 2000-2007 SWsoft. All rights reserved.
3
3
#
4
4
#  This program is free software; you can redistribute it and/or modify
5
5
#  it under the terms of the GNU General Public License as published by
27
27
#                     starting | stopping | running | stopped
28
28
#   IPDELALL      - delete all old interfaces
29
29
#
30
 
CP='/bin/cp -f --preserve=mode,ownership'
31
30
 
32
31
VENET_DEV=venet0
33
32
VENET_DEV_CFG=ifcfg-$VENET_DEV
34
33
 
35
 
FAKEGATEWAY=191.255.255.1
36
 
FAKEGATEWAYNET=191.255.255.0
37
34
 
38
35
IFCFG_DIR=/etc/sysconfig/network-scripts
39
36
IFCFG=${IFCFG_DIR}/ifcfg-${VENET_DEV}
40
37
NETFILE=/etc/sysconfig/network
41
38
HOSTFILE=/etc/hosts
 
39
ROUTE=${IFCFG_DIR}/route-${VENET_DEV}
 
40
NETWORKRESTART=
42
41
 
43
42
function fix_ifup()
44
43
{
58
57
 
59
58
function setup_network()
60
59
{
61
 
        local routefile=/etc/sysconfig/network-scripts/route-${VENET_DEV}
62
 
 
63
60
        # Set up venet0 main interface as 127.0.0.1
64
61
        mkdir -p ${IFCFG_DIR}
65
62
        echo "DEVICE=${VENET_DEV}
69
66
NETMASK=255.255.255.255
70
67
BROADCAST=0.0.0.0" > $IFCFG || error "Can't write to file $IFCFG" $VZ_FS_NO_DISK_SPACE
71
68
 
72
 
        if ! grep -q "${FAKEGATEWAYNET}/24 dev ${VENET_DEV}" ${routefile} 2>/dev/null; then
 
69
        if [ "${IPV6}" = "yes" ]; then
 
70
                echo "IPV6INIT=yes
 
71
IPV6ADDR=::1/128" >> $IFCFG || error "Can't write to file $IFCFG" $VZ_FS_NO_DISK_SPACE
 
72
 
 
73
                put_param ${NETFILE} NETWORKING_IPV6 yes
 
74
                put_param ${NETFILE} IPV6_DEFAULTDEV ${VENET_DEV}
 
75
        fi
 
76
 
 
77
        remove_fake_old_route ${ROUTE}
 
78
        if ! grep -q "${FAKEGATEWAYNET}/24 dev ${VENET_DEV}" ${ROUTE} 2>/dev/null; then
73
79
                echo "${FAKEGATEWAYNET}/24 dev ${VENET_DEV} scope host
74
 
default via ${FAKEGATEWAY}" >> ${routefile} || error "Can't create ${routefile}" ${VZ_FS_NO_DISK_SPACE}
 
80
default via ${FAKEGATEWAY}" >> ${ROUTE} || error "Can't create ${ROUTE}" ${VZ_FS_NO_DISK_SPACE}
75
81
        fi
76
82
        # Set /etc/sysconfig/network
77
83
        put_param $NETFILE NETWORKING yes
96
102
        error "Unable to create interface config file" ${VZ_FS_NO_DISK_SPACE}
97
103
}
98
104
 
 
105
function add_ip6()
 
106
{
 
107
        [ "${IPV6}" != "yes" ] && return
 
108
        if ! grep -qw "$1" ${IFCFG} 2>/dev/null; then
 
109
                add_param ${IFCFG} IPV6ADDR_SECONDARIES "$1/128"
 
110
                NETWORKRESTART=yes
 
111
        fi
 
112
}
 
113
 
99
114
function get_all_aliasid()
100
115
{
101
116
        IFNUM=-1
154
169
{
155
170
        local ip
156
171
        local new_ips 
 
172
        local if_restart=
157
173
 
158
174
        # In case we are starting VE
159
175
        if [ "x${VE_STATE}" = "xstarting" ]; then
160
176
                # Remove all VENET config files
161
 
                rm -f ${IFCFG_DIR}/${VENET_DEV_CFG}:* >/dev/null 2>&1
 
177
                rm -f ${IFCFG} ${IFCFG}:* >/dev/null 2>&1
 
178
        fi
 
179
        if [ ! -f "${IFCFG}" ]; then
162
180
                setup_network
 
181
                if_restart=1
163
182
        fi
164
183
        backup_configs ${IPDELALL}
165
184
        new_ips="${IP_ADDR}"
176
195
                done
177
196
        fi
178
197
        for ip in ${new_ips}; do
179
 
                get_free_aliasid
180
 
                create_config "${ip}" "${IFNUM}"
 
198
                if [ "${ip#*:}" = "${ip}" ]; then
 
199
                        get_free_aliasid
 
200
                        create_config "${ip}" "${IFNUM}"
 
201
                else
 
202
                        if [ "x${IPDELALL}" = "xyes" ]; then
 
203
                                del_param ${IFCFG} IPV6ADDR_SECONDARIES ""
 
204
                        fi
 
205
                        add_ip6 "${ip}"
 
206
                fi
181
207
        done
182
208
        move_configs
183
209
        if [ "x${VE_STATE}" = "xrunning" ]; then
184
210
                # synchronyze config files & interfaces
185
 
                cd /etc/sysconfig/network-scripts && ./ifup-aliases ${VENET_DEV}
 
211
                if [ "${NETWORKRESTART}" = "yes" ]; then 
 
212
                        /etc/init.d/network restart
 
213
                elif [ -n "${if_restart}" ]; then
 
214
                        ifup ${VENET_DEV}
 
215
                else
 
216
                        cd /etc/sysconfig/network-scripts && \
 
217
                                ./ifup-aliases ${VENET_DEV}
 
218
                fi
186
219
        fi
187
220
}
188
221