Improve the way to deploy onap via proxy
[demo.git] / boot / robot_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 HEAT_CODE_REPO=http://gerrit.onap.org/r/demo.git
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 # Short-term fix to get around MSO to SO name change
21 cp /opt/config/so_ip_addr.txt /opt/config/mso_ip_addr.txt
22
23 # Add host name to /etc/host to avoid warnings in openstack images
24 if [[ $CLOUD_ENV != "rackspace" ]]
25 then
26         echo 127.0.0.1 $(hostname) >> /etc/hosts
27
28         # Allow remote login as root
29         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
30         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
31 fi
32
33 # Set private IP in /etc/network/interfaces manually in the presence of public interface
34 # Some VM images don't add the private interface automatically, we have to do it during the component installation
35 if [[ $CLOUD_ENV == "openstack_nofloat" ]]
36 then
37         LOCAL_IP=$(cat /opt/config/local_ip_addr.txt)
38         CIDR=$(cat /opt/config/oam_network_cidr.txt)
39         BITMASK=$(echo $CIDR | cut -d"/" -f2)
40
41         # Compute the netmask based on the network cidr
42         if [[ $BITMASK == "8" ]]
43         then
44                 NETMASK=255.0.0.0
45         elif [[ $BITMASK == "16" ]]
46         then
47                 NETMASK=255.255.0.0
48         elif [[ $BITMASK == "24" ]]
49         then
50                 NETMASK=255.255.255.0
51         fi
52
53         echo "auto eth1" >> /etc/network/interfaces
54         echo "iface eth1 inet static" >> /etc/network/interfaces
55         echo "    address $LOCAL_IP" >> /etc/network/interfaces
56         echo "    netmask $NETMASK" >> /etc/network/interfaces
57         echo "    mtu $MTU" >> /etc/network/interfaces
58         ifup eth1
59 fi
60
61 # Download dependencies
62 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
63 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
64 apt-get update
65 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates wget openjdk-8-jdk git ntp ntpdate make
66
67 # Download scripts from Nexus
68 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip robot_vm_init.sh > /opt/robot_vm_init.sh
69 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip robot_serv.sh > /opt/robot_serv.sh
70 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip imagetest.sh > /opt/imagetest.sh
71 chmod +x /opt/imagetest.sh
72 chmod +x /opt/robot_vm_init.sh
73 chmod +x /opt/robot_serv.sh
74 mv /opt/robot_serv.sh /etc/init.d
75 update-rc.d robot_serv.sh defaults
76
77 # Download and install docker-engine and docker-compose
78 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial main" | sudo tee /etc/apt/sources.list.d/docker.list
79 apt-get update
80 apt-get install -y linux-image-extra-$(uname -r) linux-image-extra-virtual
81 apt-get install -y --allow-unauthenticated docker-engine
82
83 mkdir /opt/docker
84 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
85 chmod +x /opt/docker/docker-compose
86
87 # 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
88 DNS_FLAG=""
89 if [ -s /opt/config/dns_ip_addr.txt ]
90 then
91         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
92 fi
93 if [ -s /opt/config/external_dns.txt ]
94 then
95         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
96 fi
97 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
98
99 cp /lib/systemd/system/docker.service /etc/systemd/system
100 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
101 if [ $HTTP_PROXY != "no_proxy" ]
102 then
103 cd /opt
104 ./imagetest.sh
105 fi
106 service docker restart
107
108 # DNS IP address configuration
109 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
110 resolvconf -u
111
112 # Clone Gerrit repository
113 mkdir -p /opt/eteshare/logs
114 mkdir -p /opt/eteshare/config
115 cd /opt
116 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO testsuite/properties
117 git clone -b $GERRIT_BRANCH --single-branch $HEAT_CODE_REPO demo
118
119 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
120 if [[ $CLOUD_ENV != "rackspace" ]]
121 then
122         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
123         grub-mkconfig -o /boot/grub/grub.cfg
124         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
125         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
126         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
127         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
128         reboot
129 fi
130
131 # Run docker containers. For openstack Ubuntu 16.04 images this will run as a service after the VM has restarted
132 ./robot_vm_init.sh