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