]> git.pld-linux.org Git - packages/vzctl.git/blame - pld-add_ip.sh
- added configuration for ipv6 in /etc/sysconfig/network inside CT
[packages/vzctl.git] / pld-add_ip.sh
CommitLineData
88d20d00 1#!/bin/bash
462cd34c 2# Copyright (C) 2000-2008, Parallels, Inc. All rights reserved.
88d20d00
TP
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#
462cd34c 19# Adds IP address(es) in a container running SuSE.
88d20d00
TP
20
21VENET_DEV=venet0
462cd34c 22IFCFG_DIR=/etc/sysconfig/interfaces/
88d20d00 23IFCFG=${IFCFG_DIR}/ifcfg-${VENET_DEV}
b6e145c1 24NETFILE=/etc/sysconfig/network
88d20d00 25HOSTFILE=/etc/hosts
88d20d00 26
b6e145c1
ŁC
27function setup6_network
28{
29 [ "${IPV6}" != "yes" ] && return 0
30
31 if ! grep -q 'IPV6INIT="yes"' ${IFCFG}; then
32 put_param ${IFCFG} IPV6INIT yes
33 fi
34 if ! grep -q 'IPV6_NETWORKING=yes' ${NETFILE}; then
35 put_param ${NETFILE} IPV6_NETWORKING yes
36 put_param ${NETFILE} IPV6_GLOBALROUTEDEV ${VENET_DEV}
37 NETWORKRESTART=yes
38 fi
39}
40
462cd34c 41function get_aliases()
88d20d00 42{
462cd34c 43 IFNUMLIST=
88d20d00 44
462cd34c
ŁC
45 [ -f ${IFCFG} ] || return
46 IFNUMLIST=`grep -e "^IPADDR" ${IFCFG} | sed 's/^IPADDR\(.*\)=.*/\1/'`
88d20d00
TP
47}
48
462cd34c 49function init_config()
88d20d00 50{
462cd34c 51
88d20d00 52 mkdir -p ${IFCFG_DIR}
462cd34c 53 echo "DEVICE=venet0
88d20d00 54ONBOOT=yes
462cd34c
ŁC
55BOOTPROTO=static
56BROADCAST=0.0.0.0
88d20d00 57NETMASK=255.255.255.255
462cd34c
ŁC
58IPADDR=127.0.0.1" > ${IFCFG} ||
59 error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
88d20d00 60
b6e145c1
ŁC
61 put_param $NETFILE NETWORKING yes
62 put_param $NETFILE GATEWAY ${FAKEGATEWAY}
63
64 # setup ipv6
65 setup6_network
66
88d20d00
TP
67 # Set up /etc/hosts
68 if [ ! -f ${HOSTFILE} ]; then
69 echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
70 fi
b6e145c1 71
44e8ff39
ŁC
72}
73
462cd34c 74function create_config()
88d20d00
TP
75{
76 local ip=$1
77 local ifnum=$2
78
462cd34c
ŁC
79#LABEL_${ifnum}=${ifnum}" >> ${IFCFG} ||
80 echo "IPADDR${ifnum}=${ip}" >> ${IFCFG} || error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
88d20d00
TP
81}
82
462cd34c 83function add_ip()
88d20d00 84{
462cd34c
ŁC
85 local ipm
86 local ifnum=0
87 local found
88d20d00 88
88d20d00 89 if [ "x${VE_STATE}" = "xstarting" ]; then
462cd34c
ŁC
90 if [ -n "${IP_ADDR}" ]; then
91 init_config
92 elif grep -q "^IPADDR" ${IFCFG}; then
93 init_config
94 fi
95 elif [ "x${IPDELALL}" = "xyes" ]; then
96 init_config
97 elif [ ! -f "${IFCFG}" ]; then
98 init_config
88d20d00 99 fi
462cd34c
ŁC
100
101 get_aliases
102 for ipm in ${IP_ADDR}; do
103 ip_conv $ipm
104 found=
105 if grep -q -w "${_IP}" ${IFCFG}; then
106 continue
107 fi
108 while test -z ${found}; do
109 let ifnum++
110 if ! echo "${IFNUMLIST}" | grep -w -q "${ifnum}"; then
111 found=1
88d20d00
TP
112 fi
113 done
462cd34c 114 create_config ${_IP} ${ifnum}
88d20d00 115 done
88d20d00 116 if [ "x${VE_STATE}" = "xrunning" ]; then
462cd34c
ŁC
117 ifdown $VENET_DEV >/dev/null 2>&1
118 ifup $VENET_DEV >/dev/null 2>&1
88d20d00
TP
119 fi
120}
121
122add_ip
462cd34c 123
88d20d00
TP
124exit 0
125# end of script
This page took 0.257942 seconds and 4 git commands to generate.