9f48b391dc5babb0da770a6a347fc119f1b78e9b
[demo.git] / vnfs / vLBMS / scripts / v_dns_install.sh
1 #!/bin/bash
2
3 NEXUS_ARTIFACT_REPO=$(cat /opt/config/nexus_artifact_repo.txt)
4 NB_API_VERSION=$(cat /opt/config/nb_api_version.txt)
5 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
6 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
7
8 # Convert Network CIDR to Netmask
9 cdr2mask () {
10         # Number of args to shift, 255..255, first non-255 byte, zeroes
11         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
12         [ $1 -gt 1 ] && shift $1 || shift
13         echo ${1-0}.${2-0}.${3-0}.${4-0}
14 }
15
16 # OpenStack network configuration
17 if [[ $CLOUD_ENV == "openstack" ]]
18 then
19         echo 127.0.0.1 $(hostname) >> /etc/hosts
20
21         # Allow remote login as root
22         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
23         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
24
25         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
26
27         IP=$(cat /opt/config/local_private_ipaddr.txt)
28         BITS=$(cat /opt/config/vlb_private_net_cidr.txt | cut -d"/" -f2)
29         NETMASK=$(cdr2mask $BITS)
30         echo "auto eth1" >> /etc/network/interfaces
31         echo "iface eth1 inet static" >> /etc/network/interfaces
32         echo "    address $IP" >> /etc/network/interfaces
33         echo "    netmask $NETMASK" >> /etc/network/interfaces
34         echo "    mtu $MTU" >> /etc/network/interfaces
35
36         IP=$(cat /opt/config/oam_private_ipaddr.txt)
37         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
38         NETMASK=$(cdr2mask $BITS)
39         echo "auto eth2" >> /etc/network/interfaces
40         echo "iface eth2 inet static" >> /etc/network/interfaces
41         echo "    address $IP" >> /etc/network/interfaces
42         echo "    netmask $NETMASK" >> /etc/network/interfaces
43         echo "    mtu $MTU" >> /etc/network/interfaces
44 fi
45
46 # Download required dependencies
47 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
48 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
49 apt-get update
50 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk bind9 bind9utils bind9-doc apt-transport-https ca-certificates git maven
51 sleep 1
52
53 # Download vDNS demo code for DNS Server
54 cd /opt
55 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip v_dns_init.sh > /opt/v_dns_init.sh
56 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip vdns.sh > /opt/vdns.sh
57 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip set_gre_tunnel.sh > /opt/set_gre_tunnel.sh
58 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip properties.conf > /opt/config/properties.conf
59 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip run_health_vdns.sh > /opt/run_health.sh
60
61 sed -i 's/primary=.*/primary=false/g' /opt/config/properties.conf
62 sed -i 's/vnfc=.*/vnfc=vDNS/g' /opt/config/properties.conf
63
64 # Clone Honeycomb interface for the VNF component
65 mkdir honeycomb-api
66 git init honeycomb-api
67 cd honeycomb-api
68 git remote add origin https://gerrit.onap.org/r/demo.git
69 git config core.sparsecheckout true
70 echo "vnfs/vLBMS/apis" >> .git/info/sparse-checkout
71 git pull --depth=1 origin master
72
73 mkdir ~/.m2
74 cat > ~/.m2/settings.xml << EOF
75 <?xml version="1.0" encoding="UTF-8"?>
76 <!-- vi: set et smarttab sw=2 tabstop=2: -->
77 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
78   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
79   xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
80  
81   <profiles>
82     <profile>
83       <id>fd.io-release</id>
84       <repositories>
85         <repository>
86           <id>fd.io-mirror</id>
87           <name>fd.io-mirror</name>
88           <url>https://nexus.fd.io/content/groups/public/</url>
89           <releases>
90             <enabled>true</enabled>
91             <updatePolicy>never</updatePolicy>
92           </releases>
93           <snapshots>
94             <enabled>false</enabled>
95           </snapshots>
96         </repository>
97       </repositories>
98       <pluginRepositories>
99         <pluginRepository>
100           <id>fd.io-mirror</id>
101           <name>fd.io-mirror</name>
102           <url>https://nexus.fd.io/content/repositories/public/</url>
103           <releases>
104             <enabled>true</enabled>
105             <updatePolicy>never</updatePolicy>
106           </releases>
107           <snapshots>
108             <enabled>false</enabled>
109           </snapshots>
110         </pluginRepository>
111       </pluginRepositories>
112     </profile>
113  
114     <profile>
115       <id>fd.io-snapshots</id>
116       <repositories>
117         <repository>
118           <id>fd.io-snapshot</id>
119           <name>fd.io-snapshot</name>
120           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
121           <releases>
122             <enabled>false</enabled>
123           </releases>
124           <snapshots>
125             <enabled>true</enabled>
126           </snapshots>
127         </repository>
128       </repositories>
129       <pluginRepositories>
130         <pluginRepository>
131           <id>fd.io-snapshot</id>
132           <name>fd.io-snapshot</name>
133           <url>https://nexus.fd.io/content/repositories/fd.io.snapshot/</url>
134           <releases>
135             <enabled>false</enabled>
136           </releases>
137           <snapshots>
138             <enabled>true</enabled>
139           </snapshots>
140         </pluginRepository>
141       </pluginRepositories>
142     </profile>
143     <profile>
144       <id>opendaylight-snapshots</id>
145       <repositories>
146         <repository>
147           <id>opendaylight-snapshot</id>
148           <name>opendaylight-snapshot</name>
149           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
150           <releases>
151             <enabled>false</enabled>
152           </releases>
153           <snapshots>
154             <enabled>true</enabled>
155           </snapshots>
156         </repository>
157       </repositories>
158       <pluginRepositories>
159         <pluginRepository>
160           <id>opendaylight-shapshot</id>
161           <name>opendaylight-snapshot</name>
162           <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
163           <releases>
164             <enabled>false</enabled>
165           </releases>
166           <snapshots>
167             <enabled>true</enabled>
168           </snapshots>
169         </pluginRepository>
170       </pluginRepositories>
171     </profile>
172   </profiles>
173  
174   <activeProfiles>
175     <activeProfile>fd.io-release</activeProfile>
176     <activeProfile>fd.io-snapshots</activeProfile>
177     <activeProfile>opendaylight-snapshots</activeProfile>
178   </activeProfiles>
179 </settings>
180 EOF
181
182 cd /opt/honeycomb-api/vnfs/vLBMS/apis
183 mvn clean install
184
185 sed -i 's/"restconf-binding-address": "127.0.0.1",/"restconf-binding-address": "0.0.0.0",/g' /opt/honeycomb-api/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/target/vlb-vnf-onap-distribution-$NB_API_VERSION-hc/vlb-vnf-onap-distribution-$NB_API_VERSION/config/honeycomb.json
186 sed -i 's/"netconf-tcp-binding-address": "127.0.0.1",/"netconf-tcp-binding-address": "0.0.0.0",/g' /opt/honeycomb-api/vnfs/vLBMS/apis/vlb-vnf-onap-distribution/target/vlb-vnf-onap-distribution-$NB_API_VERSION-hc/vlb-vnf-onap-distribution-$NB_API_VERSION/config/honeycomb.json
187
188 cd /opt
189 chmod +x v_dns_init.sh
190 chmod +x vdns.sh
191 chmod +x set_gre_tunnel.sh
192 chmod +x run_health.sh
193
194 # Download Bind config files
195 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip db_dnsdemo_onap_org > /opt/db_dnsdemo_onap_org
196 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip named.conf.options > /opt/named.conf.options
197 unzip -p -j /opt/vlbms-scripts-$INSTALL_SCRIPT_VERSION.zip named.conf.local > /opt/named.conf.local
198
199 echo "bind9" > service.txt
200
201 # Configure Bind
202 modprobe ip_gre
203 mkdir /etc/bind/zones
204 sed -i "s/OPTIONS=.*/OPTIONS=\"-4 -u bind\"/g" /etc/default/bind9
205 mv db_dnsdemo_onap_org /etc/bind/zones/db.dnsdemo.onap.org
206 mv named.conf.options /etc/bind/
207 mv named.conf.local /etc/bind/
208 sleep 1
209
210 # Run instantiation script
211 mv vdns.sh /etc/init.d
212 update-rc.d vdns.sh defaults
213
214 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
215 if [[ $CLOUD_ENV != "rackspace" ]]
216 then
217         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
218         grub-mkconfig -o /boot/grub/grub.cfg
219         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
220         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
221         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
222         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
223         reboot
224 fi
225
226 ./v_dns_init.sh