Improve the way to deploy onap via proxy
[demo.git] / boot / so_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 OPENSTACK_API_KEY=$(cat /opt/config/openstack_api_key.txt)
8 GERRIT_BRANCH=$(cat /opt/config/gerrit_branch.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 so_vm_init.sh > /opt/so_vm_init.sh
66 unzip -p -j /opt/boot-$ARTIFACTS_VERSION.zip so_serv.sh > /opt/so_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/so_vm_init.sh
70 chmod +x /opt/so_serv.sh
71 mv /opt/so_serv.sh /etc/init.d
72 update-rc.d so_serv.sh defaults
73
74 # Download and install docker-engine and docker-compose
75 echo "deb https://apt.dockerproject.org/repo ubuntu-xenial 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 # Clone Gerrit repository
110 cd /opt
111 git clone -b $GERRIT_BRANCH --single-branch $CODE_REPO test_lab
112 SO_ENCRYPTION_KEY=$(cat /opt/test_lab/encryption.key)
113 echo -n "$OPENSTACK_API_KEY" | openssl aes-128-ecb -e -K $SO_ENCRYPTION_KEY -nosalt | xxd -c 256 -p > /opt/config/api_key.txt
114
115 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
116 if [[ $CLOUD_ENV != "rackspace" ]]
117 then
118         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
119         grub-mkconfig -o /boot/grub/grub.cfg
120         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
121         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
122         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
123         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
124         reboot
125 fi
126
127 # Run docker containers. For openstack Ubuntu 16.04 images this will run as a service after the VM has restarted
128 ./so_vm_init.sh