wok view vzctl/stuff/slitaz-add_ip.sh @ rev 13593
libmikmod: force /bin/bash
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu Nov 08 10:35:56 2012 +0100 (2012-11-08) |
parents | |
children |
line source
1 #!/bin/bash
2 # Adds IP address(es) in a container running Slitaz.
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 # Copyright (C) 2011 Eric Joseph-Alexandre <erjo@slitaz.org>
19 #
21 VENET_DEV=eth0
22 CFGFILE=/etc/network.conf
24 function add_ip()
25 {
26 if ! grep -q venet0 ${CFGFILE}; then
27 sed -i "s/^INTERFACE.*/INTERFACE=\"${VENET_DEV}\"/" ${CFGFILE}
28 fi
30 if [ ! -z ${IP_ADDR} ]; then
31 sed -i 's/DHCP=.*/DHCP="no"/' ${CFGFILE}
32 sed -i 's/STATIC=.*/STATIC="yes"/' ${CFGFILE}
33 sed -i -e "s/IP=".*"/IP=\"${IP_ADDR}\"/" ${CFGFILE}
34 sed -i -e "s/NETMASK=".*"/NETMASK=\"255.255.255.255\"/" ${CFGFILE}
35 fi
37 # Starting the network
38 /etc/init.d/network.sh
40 # Add default route
41 /sbin/route add default ${VENET_DEV}
42 }
44 add_ip
46 exit 0