[UCA-15] Allow root access to ONAP VMs
[demo.git] / boot / aai_install.sh
1 #!/bin/bash
2
3 # Read configuration files
4 NEXUS_REPO=$(cat /opt/config/nexus_repo.txt)
5 ARTIFACTS_VERSION=$(cat /opt/config/artifacts_version.txt)
6 DNS_IP_ADDR=$(cat /opt/config/dns_ip_addr.txt)
7 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
8
9 # Add host name to /etc/host to avoid warnings in openstack images
10 if [[ $CLOUD_ENV != "rackspace" ]]
11 then
12         echo 127.0.0.1 $(hostname) >> /etc/hosts
13
14         # Allow remote login as root
15         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
16         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
17 fi
18
19 # Set private IP in /etc/network/interfaces manually in the presence of public interface
20 # Some VM images don't add the private interface automatically, we have to do it during the component installation
21 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
22 then
23         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
24         CIDR=$(cat /opt/config/oam_network_cidr.txt)
25         BITMASK=$(echo $CIDR | cut -d"/" -f2)
26
27         # Compute the netmask based on the network cidr
28         if [[ $BITMASK == "8" ]]
29         then
30                 NETMASK=255.0.0.0
31         elif [[ $BITMASK == "16" ]]
32         then
33                 NETMASK=255.255.0.0
34         elif [[ $BITMASK == "24" ]]
35         then
36                 NETMASK=255.255.255.0
37         fi
38
39         echo "auto eth1" >> /etc/network/interfaces
40         echo "iface eth1 inet static" >> /etc/network/interfaces
41         echo "    address $LOCAL_IP" >> /etc/network/interfaces
42         echo "    netmask $NETMASK" >> /etc/network/interfaces
43         ifup eth1
44 fi
45
46 # Download dependencies
47 add-apt-repository -y ppa:openjdk-r/ppa
48 apt-get update
49 apt-get install -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate
50
51 # Download scripts from Nexus
52 curl -k $NEXUS_REPO/org.openecomp.demo/boot/$ARTIFACTS_VERSION/aai_vm_init.sh -o /opt/aai_vm_init.sh
53 curl -k $NEXUS_REPO/org.openecomp.demo/boot/$ARTIFACTS_VERSION/aai_serv.sh -o /opt/aai_serv.sh
54 chmod +x /opt/aai_vm_init.sh
55 chmod +x /opt/aai_serv.sh
56 mv /opt/aai_serv.sh /etc/init.d
57 update-rc.d aai_serv.sh defaults
58
59 # Download and install docker-engine and docker-compose
60 echo "deb https://apt.dockerproject.org/repo ubuntu-trusty main" | sudo tee /etc/apt/sources.list.d/docker.list
61 apt-get update
62 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
63 apt-get install -y --allow-unauthenticated docker-engine
64
65 mkdir /opt/docker
66 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
67 chmod +x /opt/docker/docker-compose
68
69 # 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
70 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
71
72 if [ -s /opt/config/external_dns.txt ]
73 then
74         echo "DOCKER_OPTS=\"--dns $(cat /opt/config/external_dns.txt) --mtu=$MTU\"" >> /etc/default/docker
75 else
76         echo "DOCKER_OPTS=\"--mtu=$MTU\"" >> /etc/default/docker
77 fi
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 service docker restart
82
83 # DNS IP address configuration
84 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
85 resolvconf -u
86
87 # Run docker containers
88 mkdir -p /opt/openecomp/aai/logs
89 mkdir -p /opt/openecomp/aai/data
90 cd /opt
91 ./aai_vm_init.sh