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