Improve the way to deploy onap via proxy
[demo.git] / boot / dcae2_install.sh
1 #!/bin/bash
2 #############################################################################
3 #
4 # Copyright (c) 2017 AT&T Intellectual Property. All rights reserved.
5 #
6 # Licensed under the Apache License, Version 2.0 (the "License");
7 # you may not use this file except in compliance with the License.
8 # You may obtain a copy of the License at
9 #        http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #############################################################################
18
19 set -ex 
20
21 # Read configuration files
22 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
23 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
24 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
25 EXTERNAL_DNS=$(cat /opt/config/external_dns.txt)
26 MAC_ADDR=$(cat /opt/config/mac_addr.txt)
27 HTTP_PROXY=$(cat /opt/config/http_proxy.txt)
28 HTTPS_PROXY=$(cat /opt/config/https_proxy.txt)
29
30 if [ $HTTP_PROXY != "no_proxy" ]
31 then
32     export http_proxy=$HTTP_PROXY
33     export https_proxy=$HTTPS_PROXY
34 fi
35
36 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
37
38 if [[ $CLOUD_ENV != "rackspace" ]]
39 then
40         # Add host name to /etc/host to avoid warnings in openstack images
41         echo "127.0.0.1 $(hostname)" >> /etc/hosts
42
43         # Allow remote login as root
44         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
45         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
46 fi
47
48 # Download dependencies
49 #echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
50 #echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
51 apt-get update
52 #apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget make openjdk-8-jdk git ntp ntpdate python python-pip
53 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget git ntp ntpdate python python-pip
54
55 # Download scripts from Nexus
56 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip dcae2_vm_init.sh > /opt/dcae2_vm_init.sh
57 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip dcae2_serv.sh > /opt/dcae2_serv.sh
58 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip imagetest.sh > /opt/imagetest.sh
59 chmod +x /opt/imagetest.sh
60 chmod +x /opt/dcae2_vm_init.sh
61 chmod +x /opt/dcae2_serv.sh
62 mv /opt/dcae2_serv.sh /etc/init.d
63 update-rc.d dcae2_serv.sh defaults
64
65 # Download and install docker-engine and docker-compose
66 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
67 apt-get update
68 apt-get install -y "linux-image-extra-$(uname -r)" linux-image-extra-virtual jq
69 apt-get install -y --allow-unauthenticated docker-engine
70
71 mkdir -p /opt/docker
72 curl -L "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m)" > /opt/docker/docker-compose
73 chmod +x /opt/docker/docker-compose
74
75
76 # Set the MTU size of docker containers to the minimum MTU size supported by vNICs. OpenStack deployments may 
77 # need to know the external DNS IP
78 DNS_FLAG=""
79 if [ -s /opt/config/dns_ip_addr.txt ]
80 then
81         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
82 fi
83 if [ -s /opt/config/external_dns.txt ]
84 then
85         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
86 fi
87 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU --raw-logs -H tcp://0.0.0.0:2376 -H unix:///var/run/docker.sock\"" >> /etc/default/docker
88
89 cp /lib/systemd/system/docker.service /etc/systemd/system
90 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
91 sed -i "/ExecStart/s/$/ -H tcp:\/\/0.0.0.0:2376 --raw-logs/g" /etc/systemd/system/docker.service
92 if [ $HTTP_PROXY != "no_proxy" ]
93 then
94 cd /opt
95 ./imagetest.sh
96 fi
97 systemctl daemon-reload
98 service docker restart
99
100 # add hostname aliases
101 echo "$(cat /opt/config/dcae_ip_addr.txt) consul" >>/etc/hosts
102 echo "$(cat /opt/config/dcae_ip_addr.txt) dockerhost" >>/etc/hosts
103
104 # DNS IP address configuration
105 echo "nameserver $DNS_IP_ADDR" >> /etc/resolvconf/resolv.conf.d/head
106 resolvconf -u
107
108
109 # prepare the configurations needed by DCAEGEN2 installer
110 rm -rf /opt/app/config
111 mkdir -p /opt/app/config
112
113
114 # private key
115 sed -e 's/\\n/\n/g' /opt/config/priv_key | sed -e 's/^[ \t]*//g; s/[ \t]*$//g' > /opt/app/config/key
116 chmod 777 /opt/app/config/key
117
118 # move keystone url file
119 #cp /opt/config/keystone_url.txt /opt/app/config/keystone_url.txt
120
121
122 cd /opt
123 ./dcae2_vm_init.sh