-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathhwdet-mgmt.sh
executable file
·55 lines (42 loc) · 1.46 KB
/
hwdet-mgmt.sh
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
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# debug flag
set -x
# freeRtr base installation
# remove $TRG if you want to uninstall freeRtr
# This is the only adherence of freeRtr on the filesystem
TRG=/rtr
RUN_DIR=$TRG/run
CONF_DIR=$RUN_DIR/conf
# Detect eth0 network context allocated by Docker bridge
ETH0_MAC=`cat /sys/class/net/eth0/address`
HOSTNAME=`hostname`
IPv4=$(hostname -i | awk '{for(i=1;i<=NF;i++) if($i ~ /^[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+$/) {print $i; exit}}')
IPv6=$(hostname -i | awk '{for(i=1;i<=NF;i++) if($i ~ /^[0-9a-fA-F:]+$/) {print $i; exit}}')
# Identify the end of freeRtr hw|sw file
HW_PENULTIMATE_LINE=`wc -l ${CONF_DIR}/rtr-hw.txt | awk '{print $1}'`
SW_PENULTIMATE_LINE=`wc -l ${CONF_DIR}/rtr-sw.txt | awk '{print $1}'`
# Insert management interface information
# to rtr-hw.txt
# And set it to ethernet255
# (Arbitrary choice ! Please change it if it bothers you !)
sed -i "${HW_PENULTIMATE_LINE}i\\
proc ifc255.sh ${CONF_DIR}/pcapInt.bin eth0 22552 127.0.0.1 22551 127.0.0.1\\
int eth255 eth ${ETH0_MAC} 127.0.0.1 22551 127.0.0.1 22552\
" $CONF_DIR/rtr-hw.txt
# Insert management interface information
# to rtr-sw.txt
sed -i "${SW_PENULTIMATE_LINE}i\\
hostname ${HOSTNAME}\\
interface ethernet255\\
vrf forwarding OOB\\
ipv4 address ${IPv4} /24\\
ipv6 address ${IPv6} /64\\
no shutdown\\
exit\\
do write\
" $CONF_DIR/rtr-sw.txt
# flush docker eth0 config
# so that freeRtr management connectivity
# will take precedence over Linux container
ip addr flush dev eth0
exit 0