~ubuntu-branches/debian/sid/vzctl/sid

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Ola Lundqvist
  • Date: 2011-10-17 06:51:28 UTC
  • mfrom: (1.1.8 upstream)
  • Revision ID: james.westby@ubuntu.com-20111017065128-vgdwvq5lei9g4mc7
Tags: 3.0.29.3-1
New upstream release.
Closes: #638072.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/bin/bash
 
2
#  Copyright (C) 2010-2011, Parallels, Inc. All rights reserved.
 
3
#
 
4
#  This program is free software; you can redistribute it and/or modify
 
5
#  it under the terms of the GNU General Public License as published by
 
6
#  the Free Software Foundation; either version 2 of the License, or
 
7
#  (at your option) any later version.
 
8
#
 
9
#  This program is distributed in the hope that it will be useful,
 
10
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
#  GNU General Public License for more details.
 
13
#
 
14
#  You should have received a copy of the GNU General Public License
 
15
#  along with this program; if not, write to the Free Software
 
16
#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
17
#
 
18
# This script configures IP alias(es) inside Funtoo-based CT with
 
19
# OpenRC used as services/startup/shutdown system.
 
20
#
 
21
# Parameters are passed in environment variables.
 
22
# Required parameters:
 
23
#   IP_ADDR       - IP address(es) to add
 
24
#                   (several addresses should be divided by space)
 
25
# Optional parameters:
 
26
#   VE_STATE      - state of CT; could be one of:
 
27
#                     starting | stopping | running | stopped
 
28
#   IPDELALL      - delete all old interfaces
 
29
#
 
30
# Note that modern versions of vzctl runs this script even if there
 
31
# are not venet IPs to add to the CT, which resulted in netif.venet0
 
32
# being created even when venet wasn't enabled for this container.
 
33
# This could indicate an upstream bug.
 
34
 
 
35
VENET_DEV=venet0
 
36
IFCFG=/etc/conf.d/netif.${VENET_DEV}
 
37
SCRIPT=/etc/runlevels/default/netif.${VENET_DEV}
 
38
 
 
39
HOSTFILE=/etc/hosts
 
40
 
 
41
function comment_line_regex()
 
42
{
 
43
        cp -pf ${IFCFG} ${IFCFG}.$$ ||
 
44
                error "Failed to comment ${1}: unable to copy ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
 
45
        sed -e "s/${1}/#${1}/" < ${IFCFG} > ${IFCFG}.$$ &&
 
46
                mv -f ${IFCFG}.$$ ${IFCFG} 2>/dev/null
 
47
        if [ $? -ne 0 ]; then
 
48
                rm -f ${IFCFG}.$$ 2>/dev/null
 
49
                error "Failed to comment ${1}: unable to create ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
 
50
        fi
 
51
}
 
52
 
 
53
function set_rc()
 
54
{
 
55
        [ -f "${SCRIPT}" ] && return 0
 
56
        ln -sf netif.tmpl /etc/init.d/netif.${VENET_DEV}
 
57
        rc-update add netif.${VENET_DEV} default &>/dev/null
 
58
}
 
59
 
 
60
unset_rc()
 
61
{
 
62
        # used for disabling venet if we are using veth and no IPs are specified
 
63
        rc-update del netif.${VENET_DEV} default &>/dev/null
 
64
        rm -f /etc/init.d/netif.${VENET_DEV}
 
65
        rm -f /etc/conf.d/netif.${VENET_DEV}
 
66
        ip link set ${VENET_DEV} down > /dev/null 2>&1
 
67
}
 
68
 
 
69
function init_netconfig()
 
70
{
 
71
        if [ "$IP_ADDR" != "" ]
 
72
        then
 
73
                set_rc
 
74
        else
 
75
                unset_rc
 
76
        fi
 
77
        # Set up /etc/hosts
 
78
        if [ ! -f ${HOSTFILE} ]; then
 
79
                echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
 
80
        fi
 
81
}
 
82
 
 
83
function add_ip()
 
84
{
 
85
        local ipm
 
86
        if [ "x${VE_STATE}" = "xstarting" -o "x${IPDELALL}" = "xyes" ]; then
 
87
                init_netconfig
 
88
                if [ "x${IPDELALL}" = "xyes" ]; then
 
89
                        /etc/init.d/netif.${VENET_DEV} stop >/dev/null 2>&1
 
90
                        return 0
 
91
                fi
 
92
        fi
 
93
 
 
94
        local ips=""
 
95
        if [ "${VENET_DEV}" = "venet0" ]
 
96
        then
 
97
                ips="127.0.0.1/32"
 
98
                put_param "${IFCFG}" "route" "default dev venet0"
 
99
        fi
 
100
        for ipm in ${IP_ADDR}; do
 
101
                ip_conv $ipm
 
102
                ips="$ips $_IP/$_MASK"
 
103
        done
 
104
        put_param "${IFCFG}" "template" "interface"
 
105
        put_param "${IFCFG}" "ipaddrs" "$ips"
 
106
 
 
107
        if [ "x${VE_STATE}" = "xrunning" ]; then
 
108
                # synchronize config files & interfaces
 
109
                /etc/init.d/netif.${VENET_DEV} restart >/dev/null 2>&1
 
110
        fi
 
111
}
 
112
 
 
113
add_ip
 
114
exit 0
 
115
# end of script