-
Notifications
You must be signed in to change notification settings - Fork 2
/
Eth2Bond
executable file
·45 lines (36 loc) · 1.91 KB
/
Eth2Bond
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/bin/bash
# $Id: Eth2Bond,v 1.7 2015/05/12 20:14:36 root Exp $
# This tool will convert ethX interfaces to bondX interfaces.
SYSCFG_DIR=/etc/sysconfig/network-scripts
TMPCFG_DIR=/var/tmp/eth2bond
#DEF_BONDING_OPTS="resend_igmp=2 mode=active-backup miimon=100"
DEF_BONDING_OPTS="mode=active-backup miimon=200"
[ -d ${TMPCFG_DIR} ] || mkdir -pv ${TMPCFG_DIR}
for myeth in ${SYSCFG_DIR}/ifcfg-eth[0-9]*
do
/bin/echo "(II) Processing ${myeth}..."
i="$(basename ${myeth}|sed -e 's/ifcfg.eth//')"
TGT_ETH="${TMPCFG_DIR}/ifcfg-eth${i}"
TGT_BOND="${TMPCFG_DIR}/ifcfg-bond${i}"
SAV_DIR="${TMPCFG_DIR}/eth${i}"
[ -d ${SAV_DIR} ] || mkdir -pv ${SAV_DIR}
/bin/echo "(II) Saved copy of ${myeth} to ${TGT_ETH}_orig"
/bin/cp -pf ${myeth} ${SAV_DIR}/ifcfg-eth${i}.orig
if [ -f ${SYSCFG_DIR}/ifcfg-bond${i} ]; then
echo "(II) ${SYSCFG_DIR}/ifcfg-bond${i} already exists..."
else
/bin/echo "(II) Building ${TGT_ETH} from ${myeth}..."
/bin/egrep '^#' ${myeth} > ${TGT_ETH}
/bin/echo -e "DEVICE=eth${i}\nSLAVE=yes\nMASTER=bond${i}\nTYPE=Ethernet\nNM_CONTROLLED=no\nBOOTPROTO=none" >> ${TGT_ETH}
/bin/egrep "^(NAME|UUID|ARP|ONBOOT|HWADDR|LINKDELAY|ETHTOOL_OPTS|USERCTL)" ${myeth} >> ${TGT_ETH}
/bin/echo "(II) Building ${TGT_BOND} from ${myeth}..."
/bin/echo -e "DEVICE=bond${i}\nTYPE=Bond\nNM_CONTROLLED=no" > ${TGT_BOND}
/bin/egrep "^(MTU|PERSISTENT_DHCLIENT|ONBOOT|IPADDR|NETMASK|NETWORK|GATEWAY|BROADCAST|DNS|PREFIX|DEFROUTE|IPV[46]|DOMAIN|USERCTL|PEERDNS|BOOTPROTO|IPV4_FAILURE_FATAL)" ${myeth} >> ${TGT_BOND}
/bin/echo "BONDING_OPTS=\"${DEF_BONDING_OPTS}\"" >> ${TGT_BOND}
/bin/cat ${TGT_ETH} ${TGT_BOND}|sort -u > ${SAV_DIR}/ifcfg-eth${i}.v1
/bin/cat ${myeth} |sort -u > ${SAV_DIR}/ifcfg-eth${i}.v2
/usr/bin/diff ${SAV_DIR}/ifcfg-eth${i}.v1 ${SAV_DIR}/ifcfg-eth${i}.v2 > ${SAV_DIR}/ifcfg-eth${i}.diff
/bin/cat ${SAV_DIR}/ifcfg-eth${i}.diff
/bin/echo "(II) now run: /bin/mv -fv ${TMPCFG_DIR}/ifcfg* ${SYSCFG_DIR}"
fi
done