slitaz-vz diff vz-scripts/proxmox/slitaz-add_ip.sh @ rev 0
Add scripts fro OpenVZ, proxmox
author | Eric Joseph-Alexandre <erjo@slitaz.org> |
---|---|
date | Tue Nov 01 09:21:01 2011 +0100 (2011-11-01) |
parents | |
children |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/vz-scripts/proxmox/slitaz-add_ip.sh Tue Nov 01 09:21:01 2011 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +#!/bin/bash 1.5 +# Adds IP address(es) in a container running Slitaz. 1.6 +# 1.7 +# This program is free software; you can redistribute it and/or modify 1.8 +# it under the terms of the GNU General Public License as published by 1.9 +# the Free Software Foundation; either version 2 of the License, or 1.10 +# (at your option) any later version. 1.11 +# 1.12 +# This program is distributed in the hope that it will be useful, 1.13 +# but WITHOUT ANY WARRANTY; without even the implied warranty of 1.14 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1.15 +# GNU General Public License for more details. 1.16 +# 1.17 +# You should have received a copy of the GNU General Public License 1.18 +# along with this program; if not, write to the Free Software 1.19 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 1.20 +# 1.21 +# Copyright (C) 2011 Eric Joseph-Alexandre <erjo@slitaz.org> 1.22 +# 1.23 + 1.24 +VENET_DEV=venet0 1.25 +CFGFILE=/etc/network.conf 1.26 +HOSTFILE=/etc/hosts 1.27 +CFG_DIR=/etc/network 1.28 +CFG_DEV_FILE=${CFG_DIR}/ifconfig-${VENET_DEV} 1.29 + 1.30 +function setup_network() 1.31 +{ 1.32 + # Set up /etc/hosts 1.33 + if [ ! -f ${HOSTFILE} ]; then 1.34 + echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE 1.35 + echo "${IP_ADDR} localhost.localdomain localhost" >> $HOSTFILE 1.36 + fi 1.37 + 1.38 + # Make config directory 1.39 + [ -d $CFG_DIR ] || mkdir -p $CFG_DIR 1.40 + 1.41 + # Set default venet0 for rc.network 1.42 + echo "ONBOOT=yes" > ${CFG_DEV_FILE}:0 1.43 + echo "MODE=static" >> ${CFG_DEV_FILE}:0 1.44 + echo "IP=127.0.0.1" >> ${CFG_DEV_FILE}:0 1.45 + echo "NETMASK=255.255.255.255" >> ${CFG_DEV_FILE}:0 1.46 + echo "BROADCAST=0.0.0.0" >> ${CFG_DEV_FILE}:0 1.47 +} 1.48 + 1.49 +function add_ip() 1.50 +{ 1.51 + # In case we are starting CT 1.52 + if [ "x${VE_STATE}" = "xstarting" ]; then 1.53 + setup_network 1.54 + fi 1.55 + if ! grep -q venet0 ${CFGFILE}; then 1.56 + sed -i "s/^INTERFACE.*/INTERFACE=\"${VENET_DEV}\"/" ${CFGFILE} 1.57 + fi 1.58 + 1.59 + # Set default venet0 config 1.60 + sed -i 's/DHCP=.*/DHCP="no"/' ${CFGFILE} 1.61 + sed -i 's/STATIC=.*/STATIC="yes"/' ${CFGFILE} 1.62 + sed -i -e "s/IP=".*"/IP=\"127.0.0.1\"/" ${CFGFILE} 1.63 + sed -i -e "s/NETMASK=".*"/NETMASK=\"255.255.255.255\"/" ${CFGFILE} 1.64 + 1.65 + # Set config IP for venet0 alias. 1.66 + if [ ! -z ${IP_ADDR} ]; then 1.67 + echo "ONBOOT=yes" > ${CFG_DEV_FILE}:0 1.68 + echo "MODE=static" >> ${CFG_DEV_FILE}:0 1.69 + echo "IP=${IP_ADDR}" >> ${CFG_DEV_FILE}:0 1.70 + echo "NETMASK=255.255.255.255" >> ${CFG_DEV_FILE}:0 1.71 + echo "BROADCAST=${IP_ADDR}" >> ${CFG_DEV_FILE}:0 1.72 + fi 1.73 + 1.74 + # Starting the network 1.75 + /etc/init.d/rc.network 1.76 + 1.77 + # Add default route 1.78 + /sbin/route add default ${VENET_DEV} 1.79 +} 1.80 + 1.81 +add_ip 1.82 + 1.83 +exit 0