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