slitaz-vz view vz-scripts/proxmox-ovh/slitaz-add_ip.sh @ rev 6

Remove ashism ==
author Pascal Bellard <pascal.bellard@slitaz.org>
date Tue Feb 26 08:27:32 2019 +0100 (2019-02-26)
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=venet0
22 CFGFILE=/etc/network.conf
23 HOSTFILE=/etc/hosts
24 CFG_DIR=/etc/network
25 CFG_DEV_FILE=${CFG_DIR}/ifconfig-${VENET_DEV}
27 function setup_network()
28 {
29 # Set up /etc/hosts
30 if [ ! -f ${HOSTFILE} ]; then
31 echo "127.0.0.1 localhost.localdomain localhost" > $HOSTFILE
32 echo "${IP_ADDR} localhost.localdomain localhost" >> $HOSTFILE
33 fi
35 # Make config directory
36 [ -d $CFG_DIR ] || mkdir -p $CFG_DIR
38 # Set default venet0 for rc.network
39 echo "ONBOOT=yes" > ${CFG_DEV_FILE}:0
40 echo "MODE=static" >> ${CFG_DEV_FILE}:0
41 echo "IP=127.0.0.1" >> ${CFG_DEV_FILE}:0
42 echo "NETMASK=255.255.255.255" >> ${CFG_DEV_FILE}:0
43 echo "BROADCAST=0.0.0.0" >> ${CFG_DEV_FILE}:0
44 }
46 function add_ip()
47 {
48 # In case we are starting CT
49 if [ "x${VE_STATE}" = "xstarting" ]; then
50 setup_network
51 fi
52 if ! grep -q venet0 ${CFGFILE}; then
53 sed -i "s/^INTERFACE.*/INTERFACE=\"${VENET_DEV}\"/" ${CFGFILE}
54 fi
56 # Set default venet0 config
57 sed -i 's/DHCP=.*/DHCP="no"/' ${CFGFILE}
58 sed -i 's/STATIC=.*/STATIC="yes"/' ${CFGFILE}
59 sed -i -e "s/IP=".*"/IP=\"127.0.0.1\"/" ${CFGFILE}
60 sed -i -e "s/NETMASK=".*"/NETMASK=\"255.255.255.255\"/" ${CFGFILE}
62 # Set config IP for venet0 alias.
63 if [ ! -z ${IP_ADDR} ]; then
64 echo "ONBOOT=yes" > ${CFG_DEV_FILE}:0
65 echo "MODE=static" >> ${CFG_DEV_FILE}:0
66 echo "IP=${IP_ADDR}" >> ${CFG_DEV_FILE}:0
67 echo "NETMASK=255.255.255.255" >> ${CFG_DEV_FILE}:0
68 echo "BROADCAST=${IP_ADDR}" >> ${CFG_DEV_FILE}:0
69 fi
71 # Starting the network
72 /etc/init.d/rc.network
74 # Add default route
75 /sbin/route add default ${VENET_DEV}
76 }
78 add_ip
80 exit 0