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