4835c9d84acdeeef56c19dfa398d8df72e23abf1
[demo.git] / vnfs / vCPE / 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/cpe_public_net_ipaddr.txt)
28         BITS=$(cat /opt/config/cpe_public_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_ipaddr.txt)
37         BITS=$(cat /opt/config/oam_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
45         ifup eth1
46         ifup eth2
47 fi
48
49 # Download required dependencies
50 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
51 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
52 apt-get update
53 apt-get install --allow-unauthenticated -y wget openjdk-8-jdk bind9 bind9utils bind9-doc apt-transport-https ca-certificates kea-dhcp4-server g++ libcurl4-gnutls-dev libboost-dev kea-dev
54 sleep 1
55
56 # Download DNS and DHCP config files
57 cd /opt
58 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip kea-dhcp4_no_hook.conf > /opt/kea-dhcp4_no_hook.conf
59 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip v_dns_init.sh > /opt/v_dns_init.sh
60 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip v_dns.sh > /opt/v_dns.sh
61 mv kea-dhcp4_no_hook.conf /etc/kea/kea-dhcp4.conf
62 chmod +x v_dns_init.sh
63 chmod +x v_dns.sh
64 mv v_dns.sh /etc/init.d
65 update-rc.d v_dns.sh defaults
66
67 # Install Bind
68 mkdir /etc/bind/zones
69 sed -i "s/OPTIONS=.*/OPTIONS=\"-4 -u bind\"/g" /etc/default/bind9
70
71 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
72 if [[ $CLOUD_ENV != "rackspace" ]]
73 then
74         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
75         grub-mkconfig -o /boot/grub/grub.cfg
76         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
77         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
78         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
79         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
80         reboot
81 fi
82
83 ./v_dns_init.sh