Retrieve boot scripts from new demo artifact zip
[demo.git] / boot / nbi_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 apt-get update
50 apt-get install --allow-unauthenticated -y apt-transport-https ca-certificates curl git ntp ntpdate make software-properties-common
51
52 # Download scripts from Nexus
53 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip nbi_vm_init.sh > /opt/nbi_vm_init.sh
54 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip nbi_serv.sh > /opt/nbi_serv.sh
55 chmod +x /opt/nbi_vm_init.sh
56 chmod +x /opt/nbi_serv.sh
57 mv /opt/nbi_serv.sh /etc/init.d
58 update-rc.d nbi_serv.sh defaults
59
60 # Download and install docker-engine and docker-compose
61 curl -fsSL https://download.docker.com/linux/ubuntu/gpg | apt-key add -
62 add-apt-repository \
63    "deb [arch=amd64] https://download.docker.com/linux/ubuntu \
64    $(lsb_release -cs) \
65    stable"
66 apt-get update
67 apt-get install -y docker-ce
68
69 mkdir /opt/docker
70 curl -L https://github.com/docker/compose/releases/download/1.9.0/docker-compose-`uname -s`-`uname -m` > /opt/docker/docker-compose
71 chmod +x /opt/docker/docker-compose
72
73 # 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
74 DNS_FLAG=""
75 if [ -s /opt/config/dns_ip_addr.txt ]
76 then
77         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/dns_ip_addr.txt) "
78 fi
79 if [ -s /opt/config/external_dns.txt ]
80 then
81         DNS_FLAG=$DNS_FLAG"--dns $(cat /opt/config/external_dns.txt) "
82 fi
83 echo "DOCKER_OPTS=\"$DNS_FLAG--mtu=$MTU\"" >> /etc/default/docker
84
85 cp /lib/systemd/system/docker.service /etc/systemd/system
86 sed -i "/ExecStart/s/$/ --mtu=$MTU/g" /etc/systemd/system/docker.service
87 service docker restart
88
89 # DNS IP address configuration
90 echo "nameserver "$DNS_IP_ADDR >> /etc/resolvconf/resolv.conf.d/head
91 resolvconf -u
92
93 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
94 if [[ $CLOUD_ENV != "rackspace" ]]
95 then
96         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
97         grub-mkconfig -o /boot/grub/grub.cfg
98         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
99         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
100         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
101         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
102         reboot
103 fi
104
105 # Run docker containers
106 cd /opt
107 ./nbi_vm_init.sh