]> git.pld-linux.org Git - packages/vzctl.git/blob - pld-add_ip.sh
- lost curly bracket, removed set -x
[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 #ROUTES=${IFCFG_DIR}/ifroute-${VENET_DEV}
25 HOSTFILE=/etc/hosts
26
27 function get_aliases()
28 {
29         IFNUMLIST=
30
31         [ -f ${IFCFG} ] || return
32         IFNUMLIST=`grep -e "^IPADDR" ${IFCFG} | sed 's/^IPADDR\(.*\)=.*/\1/'`
33 }
34
35 function init_config()
36 {
37
38         mkdir -p ${IFCFG_DIR}
39         echo "DEVICE=venet0
40 ONBOOT=yes
41 BOOTPROTO=static
42 BROADCAST=0.0.0.0
43 NETMASK=255.255.255.255
44 IPADDR=127.0.0.1" > ${IFCFG} ||
45         error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
46
47         # Set up /etc/hosts
48         if [ ! -f ${HOSTFILE} ]; then
49                 echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
50         fi
51 }
52
53 function create_config()
54 {
55         local ip=$1
56         local ifnum=$2
57
58 #LABEL_${ifnum}=${ifnum}" >> ${IFCFG} ||
59         echo "IPADDR${ifnum}=${ip}" >> ${IFCFG} || error "Can't write to file ${IFCFG}" ${VZ_FS_NO_DISK_SPACE}
60 }
61
62 function add_ip()
63 {
64         local ipm
65         local ifnum=0
66         local found
67
68         if [ "x${VE_STATE}" = "xstarting" ]; then
69                 if [ -n "${IP_ADDR}" ]; then
70                         init_config
71                 elif grep -q "^IPADDR" ${IFCFG}; then
72                         init_config
73                 fi
74         elif [ "x${IPDELALL}" = "xyes" ]; then
75                 init_config
76         elif [ ! -f "${IFCFG}" ]; then
77                 init_config
78         fi
79
80         get_aliases
81         for ipm in ${IP_ADDR}; do
82                 ip_conv $ipm
83                 found=
84                 if grep -q -w "${_IP}" ${IFCFG}; then
85                         continue
86                 fi
87                 while test -z ${found}; do
88                         let ifnum++
89                         if ! echo "${IFNUMLIST}" | grep -w -q "${ifnum}"; then
90                                 found=1
91                         fi
92                 done
93                 create_config ${_IP} ${ifnum}
94         done
95         if [ "x${VE_STATE}" = "xrunning" ]; then
96                 ifdown $VENET_DEV  >/dev/null 2>&1
97                 ifup $VENET_DEV  >/dev/null 2>&1
98         fi
99 }
100
101 add_ip
102
103 exit 0
104 # end of script
This page took 0.084747 seconds and 4 git commands to generate.