forked from sonic-net/sonic-mgmt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsetup-management-network.sh
executable file
·109 lines (94 loc) · 2.44 KB
/
setup-management-network.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#!/bin/bash
if [[ $(id -u) -ne 0 ]]; then
echo "Root privilege required"
exit
fi
function show_help_and_exit()
{
echo "Usage ${SCRIPT} [options]"
echo " options with (*) must be provided"
echo " -h -? : get this help"
echo " -d : Delete existed bridge"
exit $1
}
DEL_EXISTED_BRIDGE=false
while getopts "h?d" opt; do
case ${opt} in
h|\? )
show_help_and_exit 0
;;
d)
DEL_EXISTED_BRIDGE=true
;;
esac
done
echo "Refreshing apt package lists..."
apt-get update
echo
echo "STEP 1: Checking for j2cli package..."
if ! command -v j2; then
echo "j2cli not found, installing j2cli"
cmd="install --user j2cli==0.3.10"
if ! command -v pip &> /dev/null; then
pip3 $cmd
else
pip $cmd
fi
fi
echo
echo "STEP 2: Checking for bridge-utils package..."
if ! command -v brctl; then
echo "brctl not found, installing bridge-utils"
apt-get install -y bridge-utils
fi
echo
echo "STEP 3: Checking for net-tools package..."
if ! command -v ifconfig; then
echo "ifconfig not found, install net-tools"
apt-get install -y net-tools
fi
echo
echo "STEP 4: Checking for ethtool package..."
if ! command -v ethtool; then
echo "ethtool not found, install ethtool"
apt-get install -y ethtool
fi
echo
echo "STEP 5: Delete existed br1..."
if [ "$DEL_EXISTED_BRIDGE" = true ] && ifconfig br1 >/dev/null 2>&1; then
echo "br1 exists, remove it."
ifconfig br1 down
brctl delbr br1
else
echo "Not delete existed bridge or br1 not exists, skipping..."
fi
echo
echo "STEP 6: Checking if bridge br1 already exists..."
if ! ifconfig br1; then
echo "br1 not found, creating bridge network"
brctl addbr br1
brctl show br1
else
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo
echo " br1 exists, possibly lab server, are you sure you want to continue?"
echo
echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
echo
echo
echo "Please double check and manually configure IP for br1 to avoid breaking lab server connectivity"
exit 0
fi
echo
echo "STEP 7: Configuring br1 interface..."
echo "Assigning 10.250.0.1/24 to br1"
ifconfig br1 10.250.0.1/24
ifconfig br1 inet6 add fec0::1/64
echo "Bringing up br1"
ifconfig br1 up
echo
echo "COMPLETE. Bridge info:"
echo
brctl show br1
echo
ifconfig br1