8f9f924ffd92e576b553b307c8dbf751f255973e
[demo.git] / vnfs / vLB / scripts / v_dns_install.sh
1 #!/bin/bash
2
3 REPO_URL_ARTIFACTS=$(cat /opt/config/repo_url_artifacts.txt)
4 DEMO_ARTIFACTS_VERSION=$(cat /opt/config/demo_artifacts_version.txt)
5 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
6 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
7
8 # Convert Network CIDR to Netmask
9 cdr2mask () {
10         # Number of args to shift, 255..255, first non-255 byte, zeroes
11         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
12         [ $1 -gt 1 ] && shift $1 || shift
13         echo ${1-0}.${2-0}.${3-0}.${4-0}
14 }
15
16 # OpenStack network configuration
17 if [[ $CLOUD_ENV == "openstack" ]]
18 then
19         echo 127.0.0.1 $(hostname) >> /etc/hosts
20
21         # Allow remote login as root
22         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
23         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
24
25         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
26
27         IP=$(cat /opt/config/local_private_ipaddr.txt)
28         BITS=$(cat /opt/config/vlb_private_net_cidr.txt | cut -d"/" -f2)
29         NETMASK=$(cdr2mask $BITS)
30         echo "auto eth1" >> /etc/network/interfaces
31         echo "iface eth1 inet static" >> /etc/network/interfaces
32         echo "    address $IP" >> /etc/network/interfaces
33         echo "    netmask $NETMASK" >> /etc/network/interfaces
34         echo "    mtu $MTU" >> /etc/network/interfaces
35
36         IP=$(cat /opt/config/oam_private_ipaddr.txt)
37         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
38         NETMASK=$(cdr2mask $BITS)
39         echo "auto eth2" >> /etc/network/interfaces
40         echo "iface eth2 inet static" >> /etc/network/interfaces
41         echo "    address $IP" >> /etc/network/interfaces
42         echo "    netmask $NETMASK" >> /etc/network/interfaces
43         echo "    mtu $MTU" >> /etc/network/interfaces
44 fi
45
46 # Download required dependencies
47 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
48 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
49 apt-get update
50 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk bind9 bind9utils bind9-doc apt-transport-https ca-certificates
51 sleep 1
52
53 # Download vDNS demo code for DNS Server
54 mkdir /opt/FDclient
55 cd /opt
56
57 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip v_dns_init.sh > /opt/v_dns_init.sh
58 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip vdns.sh > /opt/vdns.sh
59 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip dnsclient.sh > /opt/dnsclient.sh
60 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip set_gre_tunnel.sh > /opt/set_gre_tunnel.sh
61 wget $REPO_URL_ARTIFACTS/org/onap/demo/vnf/vlb/dns-client/$DEMO_ARTIFACTS_VERSION/dns-client-$DEMO_ARTIFACTS_VERSION.jar
62
63 mv dns-client-$DEMO_ARTIFACTS_VERSION.jar /opt/FDclient/
64 mv dnsclient.sh /opt/FDclient/
65 mv set_gre_tunnel.sh /opt/FDclient/
66
67 chmod +x v_dns_init.sh
68 chmod +x vdns.sh
69 chmod +x /opt/FDclient/dnsclient.sh
70 chmod +x /opt/FDclient/set_gre_tunnel.sh
71
72 # Download Bind config files
73 cd /opt/config
74 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip db_dnsdemo_onap_org > /opt/db_dnsdemo_onap_org
75 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip named.conf.options > /opt/named.conf.options
76 unzip -p -j /opt/vlb-scripts-$INSTALL_SCRIPT_VERSION.zip named.conf.local > /opt/named.conf.local
77
78 # Configure Bind
79 modprobe ip_gre
80 mkdir /etc/bind/zones
81 sed -i "s/OPTIONS=.*/OPTIONS=\"-4 -u bind\"/g" /etc/default/bind9
82 mv db_dnsdemo_onap_org /etc/bind/zones/db.dnsdemo.onap.org
83 mv named.conf.options /etc/bind/
84 mv named.conf.local /etc/bind/
85 sleep 1
86
87 # Run instantiation script
88 cd /opt
89 mv vdns.sh /etc/init.d
90 update-rc.d vdns.sh defaults
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 ./v_dns_init.sh