Retrieve boot scripts from new demo artifact zip
[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
28 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
29
30 if [[ $CLOUD_ENV != "rackspace" ]]
31 then
32         # Add host name to /etc/host to avoid warnings in openstack images
33         echo "127.0.0.1 $(hostname)" >> /etc/hosts
34
35         # Allow remote login as root
36         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
37         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
38 fi
39
40 # Download dependencies
41 #echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
42 #echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
43 apt-get update
44 #apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget make openjdk-8-jdk git ntp ntpdate python python-pip
45 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget git ntp ntpdate python python-pip
46
47 # Download scripts from Nexus
48 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip dcae2_vm_init.sh > /opt/dcae2_vm_init.sh
49 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip dcae2_serv.sh > /opt/dcae2_serv.sh
50 chmod +x /opt/dcae2_vm_init.sh
51 chmod +x /opt/dcae2_serv.sh
52 mv /opt/dcae2_serv.sh /etc/init.d
53 update-rc.d dcae2_serv.sh defaults
54
55 # Download and install docker-engine and docker-compose
56 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
57 apt-get update
58 apt-get install -y "linux-image-extra-$(uname -r)" linux-image-extra-virtual jq
59 apt-get install -y --allow-unauthenticated docker-engine
60
61 mkdir -p /opt/docker
62 curl -L "https://github.com/docker/compose/releases/download/1.9.0/docker-compose-$(uname -s)-$(uname -m)" > /opt/docker/docker-compose
63 chmod +x /opt/docker/docker-compose
64
65
66 # Set the MTU size of docker containers to the minimum MTU size supported by vNICs. OpenStack deployments may 
67 # need to know the external DNS IP
68 DNS_FLAG=""
69 if [ -s /opt/config/dns_ip_addr.txt ]
70 then
71         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
72 fi
73 if [ -s /opt/config/external_dns.txt ]
74 then
75         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
76 fi
77 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
78
79 cp /lib/systemd/system/docker.service /etc/systemd/system
80 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
81 sed -i "/ExecStart/s/$/ -H tcp:\/\/0.0.0.0:2376 --raw-logs/g" /etc/systemd/system/docker.service
82 systemctl daemon-reload
83 service docker restart
84
85 # add hostname aliases
86 echo "$(cat /opt/config/dcae_ip_addr.txt) consul" >>/etc/hosts
87 echo "$(cat /opt/config/dcae_ip_addr.txt) dockerhost" >>/etc/hosts
88
89 # DNS IP address configuration
90 echo "nameserver $DNS_IP_ADDR" >> /etc/resolvconf/resolv.conf.d/head
91 resolvconf -u
92
93
94 # prepare the configurations needed by DCAEGEN2 installer
95 rm -rf /opt/app/config
96 mkdir -p /opt/app/config
97
98
99 # private key
100 sed -e 's/\\n/\n/g' /opt/config/priv_key | sed -e 's/^[ \t]*//g; s/[ \t]*$//g' > /opt/app/config/key
101 chmod 777 /opt/app/config/key
102
103 # move keystone url file
104 #cp /opt/config/keystone_url.txt /opt/app/config/keystone_url.txt
105
106
107 cd /opt
108 ./dcae2_vm_init.sh