Retrieve boot scripts from new demo artifact zip
[demo.git] / boot / aai_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 AAI_INSTANCE=$(cat /opt/config/aai_instance.txt)
9 MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
10 CODE_REPO=$(cat /opt/config/remote_repo.txt)
11
12 # Add host name to /etc/host to avoid warnings in openstack images
13 if [[ $CLOUD_ENV != "rackspace" ]]
14 then
15         echo 127.0.0.1 $(hostname) >> /etc/hosts
16
17         # Allow remote login as root
18         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
19         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
20 fi
21
22 # Set private IP in /etc/network/interfaces manually in the presence of public interface
23 # Some VM images don't add the private interface automatically, we have to do it during the component installation
24 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
25 then
26         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
27         CIDR=$(cat /opt/config/oam_network_cidr.txt)
28         BITMASK=$(echo $CIDR | cut -d"/" -f2)
29
30         # Compute the netmask based on the network cidr
31         if [[ $BITMASK == "8" ]]
32         then
33                 NETMASK=255.0.0.0
34         elif [[ $BITMASK == "16" ]]
35         then
36                 NETMASK=255.255.0.0
37         elif [[ $BITMASK == "24" ]]
38         then
39                 NETMASK=255.255.255.0
40         fi
41
42         echo "auto eth1" >> /etc/network/interfaces
43         echo "iface eth1 inet static" >> /etc/network/interfaces
44         echo "    address $LOCAL_IP" >> /etc/network/interfaces
45         echo "    netmask $NETMASK" >> /etc/network/interfaces
46         echo "    mtu $MTU" >> /etc/network/interfaces
47         ifup eth1
48 fi
49
50 # Download dependencies
51 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
52 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
53 apt-get update
54 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate make
55
56 # Download scripts from Nexus
57 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip aai_vm_init.sh > /opt/aai_vm_init.sh
58 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip aai_serv.sh > /opt/aai_serv.sh
59 chmod +x /opt/aai_vm_init.sh
60 chmod +x /opt/aai_serv.sh
61 mv /opt/aai_serv.sh /etc/init.d
62 update-rc.d aai_serv.sh defaults
63
64 # Download and install docker-engine and docker-compose
65 echo "deb https://apt.dockerproject.org/repo ubuntu-trusty 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
68 apt-get install -y --allow-unauthenticated docker-engine
69
70 mkdir /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 need to know the external DNS IP
75 DNS_FLAG=""
76 if [ -s /opt/config/dns_ip_addr.txt ]
77 then
78         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
79 fi
80 if [ -s /opt/config/external_dns.txt ]
81 then
82         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
83 fi
84 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
85
86 cp /lib/systemd/system/docker.service /etc/systemd/system
87 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
88 service docker restart
89
90 # DNS IP address configuration
91 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
92 resolvconf -u
93
94 # Run docker containers
95 cd /opt
96 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO
97
98 if [[ $AAI_INSTANCE == "aai_instance_1" ]]
99 then
100         mkdir -p /opt/aai/logroot/AAI-RESOURCES
101         mkdir -p /opt/aai/logroot/AAI-TRAVERSAL
102         mkdir -p /opt/aai/logroot/AAI-ML
103         mkdir -p /opt/aai/logroot/AAI-SDB
104         mkdir -p /opt/aai/logroot/AAI-DRMS
105         mkdir -p /opt/aai/logroot/AAI-UI
106         chown -R 999:999 /opt/aai/logroot/AAI-RESOURCES /opt/aai/logroot/AAI-TRAVERSAL
107
108         sleep 300
109 fi
110
111 ./aai_vm_init.sh