-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmodify_instance.sh
executable file
·175 lines (131 loc) · 8.76 KB
/
modify_instance.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#!/bin/bash
#
#Script gets names and MAC addresses of interfaces and adds them into interfaces and udev device manager.
host=$(hostname)
$(sudo chown ubuntu /etc/hosts)
name=$(printf '127.0.0.1 localhost localhost.localdomain %s' "$host")
echo $name > /etc/hosts
$(sudo chown ubuntu /etc/udev/rules.d/70-persistent-net.rules)
$(sudo chown ubuntu /etc/network/interfaces.d/50-cloud-init.cfg)
echo -e "\n# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts" >> /etc/hosts
wget -q -O - https://dl.google.com/linux/linux_signing_key.pub | sudo apt-key add -
sudo apt-get update --fix-missing
sudo apt-get upgrade
sudo apt-get install bind9 bind9utils bind9-doc
sudo apt-get install zabbix-agent
mac_1=$(ifconfig -a | grep -Po 'HWaddr \K.*$' | sed -n -e '1{p;q}')
mac_2=$(ifconfig -a | grep -Po 'HWaddr \K.*$' | sed -n -e '2{p;q}')
mac_3=$(ifconfig -a | grep -Po 'HWaddr \K.*$' | sed -n -e '3{p;q}')
mac_4=$(ifconfig -a | grep -Po 'HWaddr \K.*$' | sed -n -e '4{p;q}')
mac_5=$(ifconfig -a | grep -Po 'HWaddr \K.*$' | sed -n -e '5{p;q}')
mac_6=$(ifconfig -a | grep -Po 'HWaddr \K.*$' | sed -n -e '6{p;q}')
iface_1=$(ifconfig -a | cut -c1-8 | sort | uniq -u | sed -n -e '1{p;q}')
iface_2=$(ifconfig -a | cut -c1-8 | sort | uniq -u | sed -n -e '2{p;q}')
iface_3=$(ifconfig -a | cut -c1-8 | sort | uniq -u | sed -n -e '3{p;q}')
iface_4=$(ifconfig -a | cut -c1-8 | sort | uniq -u | sed -n -e '4{p;q}')
iface_5=$(ifconfig -a | cut -c1-8 | sort | uniq -u | sed -n -e '5{p;q}')
iface_6=$(ifconfig -a | cut -c1-8 | sort | uniq -u | sed -n -e '6{p;q}')
cfg_mgmt=$'\nauto mgmt\niface mgmt inet dhcp'
cfg_net_a=$'\nauto net_a\niface net_a inet dhcp'
cfg_net_b=$'\nauto net_b\niface net_b inet dhcp'
cfg_net_c=$'\nauto net_c\niface net_c inet dhcp'
cfg_net_d=$'\nauto net_d\niface net_d inet dhcp'
if [ $host == 'base' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
rule_net_a=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_a")
rule_net_b=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_4:0:17}" "net_b")
rule_net_c=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_5:0:17}" "net_c")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_6:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_a >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_b >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_c >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_a" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_b" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_c" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'inet-gw' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
rule_net_a=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_a")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_a >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_a" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'mme1' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'mme2' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'mme-lb' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'hss' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'bt' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_2:0:17}" "mgmt")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'dp-switch1' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s"' "${mac_2:0:17}" "mgmt")
rule_net_a=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_a")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_4:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_a >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_a" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'pcrf' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s"' "${mac_2:0:17}" "mgmt")
rule_net_a=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_3:0:17}" "net_a")
rule_net_d=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s" ' "${mac_4:0:17}" "net_d")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_a >> /etc/udev/rules.d/70-persistent-net.rules
echo $rule_net_d >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_a" >> /etc/network/interfaces.d/50-cloud-init.cfg
echo "$cfg_net_d" >> /etc/network/interfaces.d/50-cloud-init.cfg
elif [ $host == 'o5gc-gui' ]
then
rule_mgmt=$(printf 'SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{address}=="%s", NAME="%s"' "${mac_2:0:17}" "mgmt")
echo $rule_mgmt >> /etc/udev/rules.d/70-persistent-net.rules
echo "$cfg_mgmt" >> /etc/network/interfaces.d/50-cloud-init.cfg
else
echo "Hostname does not match with one of 5G hosts. Either check your hostname and add to /etc/hosts/ file or add rules to script for your machine"
fi
echo -e "\nInterfaces were modified. Reboot instance and compare your interfaces with 'ifconfig' and 'ifconfig -a' commands."