Refactor ONAP HEAT template config scripts
[demo.git] / heat / ONAP / cloud-config / 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 apt-get update
50 #apt-get install -y apt-transport-https ca-certificates wget make git ntp ntpdate python python-pip
51 apt-get install -y apt-transport-https ca-certificates wget git ntp ntpdate python python-pip
52
53 # Download scripts from Nexus
54 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip dcae2_vm_init.sh > /opt/dcae2_vm_init.sh
55 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip serv.sh > /opt/dcae2_serv.sh
56 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip imagetest.sh > /opt/imagetest.sh
57 chmod +x /opt/imagetest.sh
58 chmod +x /opt/dcae2_vm_init.sh
59 chmod +x /opt/dcae2_serv.sh
60 sed -i "s|cmd=\"\"|cmd=\"./dcae2_vm_init.sh\"|g" /opt/dcae2_serv.sh
61 mv /opt/dcae2_serv.sh /etc/init.d
62 update-rc.d dcae2_serv.sh defaults
63
64 # Download and install docker-engine and docker-compose
65 echo "deb https://apt.dockerproject.org/repo ubuntu-$(lsb_release -cs) main" | sudo 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 jq
68 apt-get install -y --allow-unauthenticated docker-engine
69
70 mkdir -p /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 
75 # need to know the external DNS IP
76 DNS_FLAG=""
77 if [ -s /opt/config/dns_ip_addr.txt ]
78 then
79         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
80 fi
81 if [ -s /opt/config/external_dns.txt ]
82 then
83         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
84 fi
85 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
86
87 cp /lib/systemd/system/docker.service /etc/systemd/system
88 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
89 sed -i "/ExecStart/s/$/ -H tcp:\/\/0.0.0.0:2376 --raw-logs/g" /etc/systemd/system/docker.service
90 if [ $HTTP_PROXY != "no_proxy" ]
91 then
92 cd /opt
93 ./imagetest.sh
94 fi
95 systemctl daemon-reload
96 service docker restart
97
98 # add hostname aliases
99 echo "$(cat /opt/config/dcae_ip_addr.txt) consul" >>/etc/hosts
100 echo "$(cat /opt/config/dcae_ip_addr.txt) dockerhost" >>/etc/hosts
101
102 # DNS IP address configuration
103 echo "nameserver $DNS_IP_ADDR" >> /etc/resolvconf/resolv.conf.d/head
104 resolvconf -u
105
106 # prepare the configurations needed by DCAEGEN2 installer
107 rm -rf /opt/app/config
108 mkdir -p /opt/app/config
109
110 # private key
111 sed -e 's/\\n/\n/g' /opt/config/priv_key | sed -e 's/^[ \t]*//g; s/[ \t]*$//g' > /opt/app/config/key
112 chmod 777 /opt/app/config/key
113
114 cd /opt
115 ./dcae2_vm_init.sh