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