]> git.pld-linux.org Git - packages/vzctl.git/blob - pld-add_ip.sh
- x32 rebuild
[packages/vzctl.git] / pld-add_ip.sh
1 #!/bin/bash
2 #  Copyright (C) 2000-2008, 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 #
19 # Adds IP address(es) in a container running SuSE.
20
21 VENET_DEV=venet0
22 IFCFG_DIR=/etc/sysconfig/interfaces/
23 IFCFG=${IFCFG_DIR}/ifcfg-${VENET_DEV}
24 NETFILE=/etc/sysconfig/network
25 HOSTFILE=/etc/hosts
26
27 function 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
41 function get_aliases()
42 {
43         IFNUMLIST=
44
45         [ -f ${IFCFG} ] || return
46         IFNUMLIST=`grep -e "^IPADDR" ${IFCFG} | sed 's/^IPADDR\(.*\)=.*/\1/'`
47 }
48
49 function init_config()
50 {
51
52         mkdir -p ${IFCFG_DIR}
53         echo "DEVICE=venet0
54 ONBOOT=yes
55 BOOTPROTO=static
56 BROADCAST=0.0.0.0
57 NETMASK=255.255.255.255
58 IPADDR=127.0.0.1" > ${IFCFG} ||
59         error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
60
61         put_param $NETFILE NETWORKING yes
62         put_param $NETFILE GATEWAY ${FAKEGATEWAY}
63
64         # setup ipv6
65         setup6_network
66
67         # Set up /etc/hosts
68         if [ ! -f ${HOSTFILE} ]; then
69                 echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
70         fi
71
72 }
73
74 function create_config()
75 {
76         local ip=$1
77         local ifnum=$2
78
79 #LABEL_${ifnum}=${ifnum}" >> ${IFCFG} ||
80         echo "IPADDR${ifnum}=${ip}" >> ${IFCFG} || error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
81 }
82
83 function add_ip()
84 {
85         local ipm
86         local ifnum=0
87         local found
88
89         if [ "x${VE_STATE}" = "xstarting" ]; then
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
99         fi
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
112                         fi
113                 done
114                 if echo ${_IP} | grep -q ':' ; then
115                         setup6_network
116                 fi
117                 create_config ${_IP} ${ifnum}
118         done
119         if [ "x${VE_STATE}" = "xrunning" ]; then
120                 ifdown $VENET_DEV  >/dev/null 2>&1
121                 ifup $VENET_DEV  >/dev/null 2>&1
122         fi
123 }
124
125 add_ip
126
127 exit 0
128 # end of script
This page took 0.0896 seconds and 3 git commands to generate.