wok-current diff vzctl/stuff/slitaz-add_ip.sh @ rev 17152

Down disount (2.1.6)
author Pascal Bellard <pascal.bellard@slitaz.org>
date Thu Sep 11 15:41:24 2014 +0200 (2014-09-11)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/vzctl/stuff/slitaz-add_ip.sh	Thu Sep 11 15:41:24 2014 +0200
     1.3 @@ -0,0 +1,46 @@
     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=eth0
    1.25 +CFGFILE=/etc/network.conf
    1.26 +
    1.27 +function add_ip()
    1.28 +{
    1.29 +	if ! grep -q venet0 ${CFGFILE}; then
    1.30 +		sed -i "s/^INTERFACE.*/INTERFACE=\"${VENET_DEV}\"/" ${CFGFILE}
    1.31 +	fi
    1.32 +	
    1.33 +	if [ ! -z ${IP_ADDR} ]; then
    1.34 +		sed -i 's/DHCP=.*/DHCP="no"/' ${CFGFILE}
    1.35 +		sed -i 's/STATIC=.*/STATIC="yes"/' ${CFGFILE}
    1.36 +		sed -i -e "s/IP=".*"/IP=\"${IP_ADDR}\"/" ${CFGFILE}
    1.37 +		sed -i -e "s/NETMASK=".*"/NETMASK=\"255.255.255.255\"/" ${CFGFILE}
    1.38 +	fi
    1.39 +	
    1.40 +	# Starting the network
    1.41 +	/etc/init.d/network.sh
    1.42 +	
    1.43 +	# Add default route
    1.44 +	/sbin/route add default ${VENET_DEV}
    1.45 +}
    1.46 +
    1.47 +add_ip
    1.48 +
    1.49 +exit 0