ea80e47f3102c923967432bad9732a00317a28e7
[demo.git] / boot / aaf_install.sh
1 #!/bin/bash
2
3 # Read configuration files
4 NEXUS_REPO=$(cat /opt/config/nexus_repo.txt)
5 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
6 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
7 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
8 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.txt)
9 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
10 CODE_REPO=$(cat /opt/config/remote_repo.txt)
11
12 # Add host name to /etc/host to avoid warnings in openstack images
13 if [[ $CLOUD_ENV != "rackspace" ]]
14 then
15         echo 127.0.0.1 $(hostname) >> /etc/hosts
16
17         # Allow remote login as root
18         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
19         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
20 fi
21
22 # Set private IP in /etc/network/interfaces manually in the presence of public interface
23 # Some VM images don't add the private interface automatically, we have to do it during the component installation
24 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
25 then
26         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
27         CIDR=$(cat /opt/config/oam_network_cidr.txt)
28         BITMASK=$(echo $CIDR | cut -d"/" -f2)
29
30         # Compute the netmask based on the network cidr
31         if [[ $BITMASK == "8" ]]
32         then
33                 NETMASK=255.0.0.0
34         elif [[ $BITMASK == "16" ]]
35         then
36                 NETMASK=255.255.0.0
37         elif [[ $BITMASK == "24" ]]
38         then
39                 NETMASK=255.255.255.0
40         fi
41
42         echo "auto eth1" >> /etc/network/interfaces
43         echo "iface eth1 inet static" >> /etc/network/interfaces
44         echo "    address $LOCAL_IP" >> /etc/network/interfaces
45         echo "    netmask $NETMASK" >> /etc/network/interfaces
46         echo "    mtu $MTU" >> /etc/network/interfaces
47         ifup eth1
48 fi
49
50 # Download dependencies
51 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
52 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
53 apt-get update
54 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate make maven
55
56 # Download scripts from Nexus
57 curl -k $NEXUS_REPO/org.onap.demo/boot/$ARTIFACTS_VERSION/aaf_vm_init.sh -o /opt/aaf_vm_init.sh
58 curl -k $NEXUS_REPO/org.onap.demo/boot/$ARTIFACTS_VERSION/aaf_serv.sh -o /opt/aaf_serv.sh
59 chmod +x /opt/aaf_vm_init.sh
60 chmod +x /opt/aaf_serv.sh
61 mv /opt/aaf_serv.sh /etc/init.d
62 update-rc.d aaf_serv.sh defaults
63
64 # Download and install docker-engine and docker-compose
65 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | tee /etc/apt/sources.list.d/docker.list
66 apt-get update
67 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
68 apt-get install -y --allow-unauthenticated docker-engine
69
70 mkdir /opt/docker
71 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
72 chmod +x /opt/docker/docker-compose
73
74 # Set the MTU size of docker containers to the minimum MTU size supported by vNICs. OpenStack deployments may need to know the external DNS IP
75 DNS_FLAG=""
76 if [ -s /opt/config/dns_ip_addr.txt ]
77 then
78         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
79 fi
80 if [ -s /opt/config/external_dns.txt ]
81 then
82         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
83 fi
84 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
85
86 cp /lib/systemd/system/docker.service /etc/systemd/system
87 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
88 service docker restart
89
90 # DNS IP address configuration
91 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
92 resolvconf -u
93
94 # Clone Gerrit repository and run docker containers
95 cd /opt
96 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO
97 chmod +x /opt/authz/auth/auth-cass/docker/dinstall.sh
98 chmod +x /opt/authz/auth/auth-cass/docker/backup/backup.sh
99 chmod +x /opt/authz/auth/docker/dbuild.sh
100 chmod +x /opt/authz/auth/docker/drun.sh
101 chmod +x /opt/authz/auth/docker/dstart.sh
102 chmod +x /opt/authz/auth/docker/dstop.sh
103 # d.props is not a startable shell
104 # chmod +x /opt/authz/auth/docker/d.props
105
106 #Update maven settings
107 cat > /usr/share/maven/conf/settings.xml << EOF
108 <?xml version="1.0" encoding="UTF-8"?>
109
110 <!--
111 Licensed to the Apache Software Foundation (ASF) under one
112 or more contributor license agreements.  See the NOTICE file
113 distributed with this work for additional information
114 regarding copyright ownership.  The ASF licenses this file
115 to you under the Apache License, Version 2.0 (the
116 "License"); you may not use this file except in compliance
117 with the License.  You may obtain a copy of the License at
118
119     http://www.apache.org/licenses/LICENSE-2.0
120
121 Unless required by applicable law or agreed to in writing,
122 software distributed under the License is distributed on an
123 "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
124 KIND, either express or implied.  See the License for the
125 specific language governing permissions and limitations
126 under the License.
127 -->
128
129 <!--
130  | This is the configuration file for Maven. It can be specified at two levels:
131  |
132  |  1. User Level. This settings.xml file provides configuration for a single user,
133 |                 and is normally provided in \${user.home}/.m2/settings.xml.
134  |
135  |                 NOTE: This location can be overridden with the CLI option:
136  |
137  |                 -s /path/to/user/settings.xml
138  |
139  |  2. Global Level. This settings.xml file provides configuration for all Maven
140  |                 users on a machine (assuming they're all using the same Maven
141  |                 installation). It's normally provided in
142 |                 \${maven.home}/conf/settings.xml.
143  |
144  |                 NOTE: This location can be overridden with the CLI option:
145  |
146  |                 -gs /path/to/global/settings.xml
147  |
148  | The sections in this sample file are intended to give you a running start at
149  | getting the most out of your Maven installation. Where appropriate, the default
150  | values (values used when the setting is not specified) are provided.
151  |
152  |-->
153 <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
154           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
155           xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 http://maven.apache.org/xsd/settings-1.0.0.xsd">
156   <!-- localRepository
157    | The path to the local repository maven will use to store artifacts.
158    |
159 | Default: \${user.home}/.m2/repository
160   <localRepository>/path/to/local/repo</localRepository>
161   -->
162
163   <!-- interactiveMode
164    | This will determine whether maven prompts you when it needs input. If set to false,
165    | maven will use a sensible default value, perhaps based on some other setting, for
166    | the parameter in question.
167    |
168    | Default: true
169   <interactiveMode>true</interactiveMode>
170   -->
171
172   <!-- offline
173    | Determines whether maven should attempt to connect to the network when executing a build.
174    | This will have an effect on artifact downloads, artifact deployment, and others.
175    |
176    | Default: false
177   <offline>false</offline>
178   -->
179
180   <!-- pluginGroups
181    | This is a list of additional group identifiers that will be searched when resolving plugins by their prefix, i.e.
182    | when invoking a command line like "mvn prefix:goal". Maven will automatically add the group identifiers
183    | "org.apache.maven.plugins" and "org.codehaus.mojo" if these are not already contained in the list.
184    |-->
185   <pluginGroups>
186     <!-- pluginGroup
187      | Specifies a further group identifier to use for plugin lookup.
188     <pluginGroup>com.your.plugins</pluginGroup>
189     -->
190   </pluginGroups>
191
192   <!-- proxies
193    | This is a list of proxies which can be used on this machine to connect to the network.
194    | Unless otherwise specified (by system property or command-line switch), the first proxy
195    | specification in this list marked as active will be used.
196    |-->
197   <proxies>
198     <!-- proxy
199      | Specification for one proxy, to be used in connecting to the network.
200      |
201     <proxy>
202       <id>optional</id>
203       <active>true</active>
204       <protocol>http</protocol>
205       <username>proxyuser</username>
206       <password>proxypass</password>
207       <host>proxy.host.net</host>
208       <port>80</port>
209       <nonProxyHosts>local.net|some.host.com</nonProxyHosts>
210     </proxy>
211     -->
212   </proxies>
213
214   <!-- servers
215    | This is a list of authentication profiles, keyed by the server-id used within the system.
216    | Authentication profiles can be used whenever maven must make a connection to a remote server.
217    |-->
218   <servers>
219     <!-- server
220      | Specifies the authentication information to use when connecting to a particular server, identified by
221      | a unique name within the system (referred to by the 'id' attribute below).
222      |
223      | NOTE: You should either specify username/password OR privateKey/passphrase, since these pairings are
224      |       used together.
225      |
226     <server>
227       <id>deploymentRepo</id>
228       <username>repouser</username>
229       <password>repopwd</password>
230     </server>
231     -->
232
233     <!-- Another sample, using keys to authenticate.
234     <server>
235       <id>siteServer</id>
236       <privateKey>/path/to/private/key</privateKey>
237       <passphrase>optional; leave empty if not used.</passphrase>
238     </server>
239     -->
240   </servers>
241
242   <!-- mirrors
243    | This is a list of mirrors to be used in downloading artifacts from remote repositories.
244    |
245    | It works like this: a POM may declare a repository to use in resolving certain artifacts.
246    | However, this repository may have problems with heavy traffic at times, so people have mirrored
247    | it to several places.
248    |
249    | That repository definition will have a unique id, so we can create a mirror reference for that
250    | repository, to be used as an alternate download site. The mirror site will be the preferred
251    | server for that repository.
252    |-->
253
254   <!-- profiles
255    | This is a list of profiles which can be activated in a variety of ways, and which can modify
256    | the build process. Profiles provided in the settings.xml are intended to provide local machine-
257    | specific paths and repository locations which allow the build to work in the local environment.
258    |
259    | For example, if you have an integration testing plugin - like cactus - that needs to know where
260    | your Tomcat instance is installed, you can provide a variable here such that the variable is
261    | dereferenced during the build process to configure the cactus plugin.
262    |
263    | As noted above, profiles can be activated in a variety of ways. One way - the activeProfiles
264    | section of this document (settings.xml) - will be discussed later. Another way essentially
265    | relies on the detection of a system property, either matching a particular value for the property,
266    | or merely testing its existence. Profiles can also be activated by JDK version prefix, where a
267    | value of '1.4' might activate a profile when the build is executed on a JDK version of '1.4.2_07'.
268    | Finally, the list of active profiles can be specified directly from the command line.
269    |
270    | NOTE: For profiles defined in the settings.xml, you are restricted to specifying only artifact
271    |       repositories, plugin repositories, and free-form properties to be used as configuration
272    |       variables for plugins in the POM.
273    |
274    |-->
275
276
277
278   
279   
280   <profiles>
281       <profile>
282           
283           <id>10_nexus</id>
284           <!--Enable snapshots for the built in central repo to direct -->
285           <!--all requests to nexus via the mirror -->
286           <repositories>
287               <repository>
288                   <id>10_nexus</id>
289                   <url>http://repo.maven.apache.org/maven2/</url>
290                   <releases><enabled>true</enabled></releases>
291                   <snapshots><enabled>true</enabled></snapshots>
292               </repository>
293           </repositories>
294           
295           <pluginRepositories>
296               <pluginRepository>
297                   <id>10_nexus</id>
298                   <url>http://repo.maven.apache.org/maven2/</url>
299                   <releases><enabled>true</enabled></releases>
300                   <snapshots><enabled>true</enabled></snapshots>
301               </pluginRepository>
302           </pluginRepositories>
303           
304       </profile>
305       <profile>
306           <id>20_openecomp-public</id>
307           <repositories>
308               <repository>
309                   <id>20_openecomp-public</id>
310                   <name>20_openecomp-public</name>
311                   <url>https://nexus.onap.org/content/repositories/public/</url>
312                   <releases>
313                       <enabled>true</enabled>
314                       <updatePolicy>daily</updatePolicy>
315                   </releases>
316                   <snapshots>
317                       <enabled>false</enabled>
318                   </snapshots>
319               </repository>
320           </repositories>
321           <pluginRepositories>
322               <pluginRepository>
323                   <id>20_openecomp-public</id>
324                   <name>20_openecomp-public</name>
325                   <url>https://nexus.onap.org/content/repositories/public/</url>
326                   <releases>
327                       <enabled>true</enabled>
328                       <updatePolicy>daily</updatePolicy>
329                   </releases>
330                   <snapshots>
331                       <enabled>false</enabled>
332                   </snapshots>
333               </pluginRepository>
334           </pluginRepositories>
335       </profile>
336       <profile>
337           <id>30_openecomp-staging</id>
338           <repositories>
339               <repository>
340                   <id>30_openecomp-staging</id>
341                   <name>30_openecomp-staging</name>
342                   <url>https://nexus.onap.org/content/repositories/staging/</url>
343                   <releases>
344                       <enabled>true</enabled>
345                       <updatePolicy>daily</updatePolicy>
346                   </releases>
347                   <snapshots>
348                       <enabled>false</enabled>
349                   </snapshots>
350               </repository>
351           </repositories>
352           <pluginRepositories>
353               <pluginRepository>
354                   <id>30_openecomp-staging</id>
355                   <name>30_openecomp-staging</name>
356                   <url>https://nexus.onap.org/content/repositories/staging/</url>
357                   <releases>
358                       <enabled>true</enabled>
359                       <updatePolicy>daily</updatePolicy>
360                   </releases>
361                   <snapshots>
362                       <enabled>false</enabled>
363                   </snapshots>
364               </pluginRepository>
365           </pluginRepositories>
366       </profile>
367       <profile>
368           <id>40_openecomp-release</id>
369           <repositories>
370               <repository>
371                   <id>40_openecomp-release</id>
372                   <name>40_openecomp-release</name>
373                   <url>https://nexus.onap.org/content/repositories/releases/</url>
374                   <releases>
375                       <enabled>true</enabled>
376                       <updatePolicy>daily</updatePolicy>
377                   </releases>
378                   <snapshots>
379                       <enabled>false</enabled>
380                   </snapshots>
381               </repository>
382           </repositories>
383           <pluginRepositories>
384               <pluginRepository>
385                   <id>40_openecomp-release</id>
386                   <name>40_openecomp-release</name>
387                   <url>https://nexus.onap.org/content/repositories/releases/</url>
388                   <releases>
389                       <enabled>true</enabled>
390                       <updatePolicy>daily</updatePolicy>
391                   </releases>
392                   <snapshots>
393                       <enabled>false</enabled>
394                   </snapshots>
395               </pluginRepository>
396           </pluginRepositories>
397       </profile>
398       
399       <profile>
400           <id>50_openecomp-snapshots</id>
401           <repositories>
402               <repository>
403                   <id>50_openecomp-snapshot</id>
404                   <name>50_openecomp-snapshot</name>
405                   <url>https://nexus.onap.org/content/repositories/snapshots/</url>
406                   <releases>
407                       <enabled>false</enabled>
408                   </releases>
409                   <snapshots>
410                       <enabled>true</enabled>
411                   </snapshots>
412               </repository>
413           </repositories>
414           <pluginRepositories>
415               <pluginRepository>
416                   <id>50_openecomp-snapshot</id>
417                   <name>50_openecomp-snapshot</name>
418                   <url>https://nexus.onap.org/content/repositories/snapshots/</url>
419                   <releases>
420                       <enabled>false</enabled>
421                   </releases>
422                   <snapshots>
423                       <enabled>true</enabled>
424                   </snapshots>
425               </pluginRepository>
426           </pluginRepositories>
427       </profile>
428       <profile>
429           <id>60_opendaylight-release</id>
430           <repositories>
431               <repository>
432                   <id>60_opendaylight-mirror</id>
433                   <name>60_opendaylight-mirror</name>
434                   <url>https://nexus.opendaylight.org/content/repositories/public/</url>
435                   <releases>
436                       <enabled>true</enabled>
437                       <updatePolicy>daily</updatePolicy>
438                   </releases>
439                   <snapshots>
440                       <enabled>false</enabled>
441                   </snapshots>
442               </repository>
443           </repositories>
444           <pluginRepositories>
445               <pluginRepository>
446                   <id>60_opendaylight-mirror</id>
447                   <name>60_opendaylight-mirror</name>
448                   <url>https://nexus.opendaylight.org/content/repositories/public/</url>
449                   <releases>
450                       <enabled>true</enabled>
451                       <updatePolicy>daily</updatePolicy>
452                   </releases>
453                   <snapshots>
454                       <enabled>false</enabled>
455                   </snapshots>
456               </pluginRepository>
457           </pluginRepositories>
458       </profile>
459       
460       <profile>
461           <id>70_opendaylight-snapshots</id>
462           <repositories>
463               <repository>
464                   <id>70_opendaylight-snapshot</id>
465                   <name>70_opendaylight-snapshot</name>
466                   <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
467                   <releases>
468                       <enabled>false</enabled>
469                   </releases>
470                   <snapshots>
471                       <enabled>true</enabled>
472                   </snapshots>
473               </repository>
474           </repositories>
475           <pluginRepositories>
476               <pluginRepository>
477                   <id>70_opendaylight-snapshot</id>
478                   <name>70_opendaylight-snapshot</name>
479                   <url>https://nexus.opendaylight.org/content/repositories/opendaylight.snapshot/</url>
480                   <releases>
481                       <enabled>false</enabled>
482                   </releases>
483                   <snapshots>
484                       <enabled>true</enabled>
485                   </snapshots>
486               </pluginRepository>
487           </pluginRepositories>
488       </profile>
489   </profiles>
490   
491   <activeProfiles>
492       <activeProfile>10_nexus</activeProfile>
493       <activeProfile>20_openecomp-public</activeProfile>
494       <activeProfile>30_openecomp-staging</activeProfile>
495       <activeProfile>40_openecomp-release</activeProfile>
496       <activeProfile>50_openecomp-snapshots</activeProfile>
497       <activeProfile>60_opendaylight-release</activeProfile>
498       <activeProfile>70_opendaylight-snapshots</activeProfile>
499
500   </activeProfiles>
501   
502 </settings>
503 EOF
504
505 cd /opt/authz
506 mvn install -Dmaven.test.skip=true
507
508 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
509 if [[ $CLOUD_ENV != "rackspace" ]]
510 then
511         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
512         grub-mkconfig -o /boot/grub/grub.cfg
513         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
514         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
515         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
516         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
517         reboot
518 fi
519
520 cd /opt
521 ./aaf_vm_init.sh