vdhcp and kea hook install
[demo.git] / vnfs / vCPE / scripts / v_dhcp_install.sh
1 #!/bin/bash
2
3 REPO_URL_BLOB=$(cat /opt/config/repo_url_blob.txt)
4 REPO_URL_ARTIFACTS=$(cat /opt/config/repo_url_artifacts.txt)
5 DEMO_ARTIFACTS_VERSION=$(cat /opt/config/demo_artifacts_version.txt)
6 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
7 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
8
9 # Convert Network CIDR to Netmask
10 cdr2mask () {
11         # Number of args to shift, 255..255, first non-255 byte, zeroes
12         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
13         [ $1 -gt 1 ] && shift $1 || shift
14         echo ${1-0}.${2-0}.${3-0}.${4-0}
15 }
16
17 # OpenStack network configuration
18 if [[ $CLOUD_ENV == "openstack" ]]
19 then
20         echo 127.0.0.1 $(hostname) >> /etc/hosts
21
22         # Allow remote login as root
23         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
24         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
25
26         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
27
28         IP=$(cat /opt/config/local_private_ipaddr.txt)
29         BITS=$(cat /opt/config/vdhcp_private_net_cidr.txt | cut -d"/" -f2)
30         NETMASK=$(cdr2mask $BITS)
31         echo "auto eth1" >> /etc/network/interfaces
32         echo "iface eth1 inet static" >> /etc/network/interfaces
33         echo "    address $IP" >> /etc/network/interfaces
34         echo "    netmask $NETMASK" >> /etc/network/interfaces
35         echo "    mtu $MTU" >> /etc/network/interfaces
36
37         IP=$(cat /opt/config/oam_private_ipaddr.txt)
38         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
39         NETMASK=$(cdr2mask $BITS)
40         echo "auto eth2" >> /etc/network/interfaces
41         echo "iface eth2 inet static" >> /etc/network/interfaces
42         echo "    address $IP" >> /etc/network/interfaces
43         echo "    netmask $NETMASK" >> /etc/network/interfaces
44         echo "    mtu $MTU" >> /etc/network/interfaces
45
46         ifup eth1
47         ifup eth2
48 fi
49
50 # Download required dependencies
51 add-apt-repository -y ppa:openjdk-r/ppa
52 apt-get update
53 apt-get install -y wget openjdk-8-jdk apt-transport-https ca-certificates kea-dhcp4-server g++ libcurl4-gnutls-dev libboost-dev kea-dev
54 sleep 1
55
56 #  download the kea hook 
57 cd /opt
58 wget $REPO_URL_ARTIFACTS/org/onap/demo/vnf/vcpe/vdhcp/$DEMO_ARTIFACTS_VERSION/kea-sdnc-notify-mod.tar.gz 
59 tar -zxvf kea-sdnc-notify-mod.tar.gz 
60 mv kea-sdnc-notify-mod  VDHCP
61 rm *.tar.gz
62 cd VDHCP
63 # build.sh takes a minute or two to run
64 ./build.sh
65 mv kea-sdnc-notify.so /usr/local/lib
66
67
68 # Download vDHCP demo code for DHCP Server
69 #cd /opt
70
71 #wget $REPO_URL_BLOB/org.onap.demo/vnfs/vCPE/$INSTALL_SCRIPT_VERSION/v_dhcp_init.sh
72 #wget $REPO_URL_BLOB/org.onap.demo/vnfs/vCPE/$INSTALL_SCRIPT_VERSION/vdhcp.sh
73
74 #chmod +x v_dhcp_init.sh
75 #chmod +x vdhcp.sh
76
77 # Download DHCP config files
78 cd /opt/config
79 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vCPE/$INSTALL_SCRIPT_VERSION/kea-dhcp4.conf
80 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vCPE/$INSTALL_SCRIPT_VERSION/kea-sdnc-notify.conf
81
82 # Configure DHCP
83 mv kea-dhcp4.conf /etc/kea/kea-dhcp4.conf
84 mv kea-sdnc-notify.conf /etc/kea/kea-sdnc-notify.conf
85 sleep 1
86
87 ######################################################################################
88 ### KEA install automatically puts kea-dhcp4-server in /etc/init.d and does update.rc
89 # rc0.d/K01kea-dhcp4-server
90 #rc1.d/K01kea-dhcp4-server
91 #rc2.d/S03kea-dhcp4-server
92 #rc3.d/S03kea-dhcp4-server
93 #rc4.d/S03kea-dhcp4-server
94 #rc5.d/S03kea-dhcp4-server
95 #rc6.d/K01kea-dhcp4-server
96 ######################################################################################
97 # Run instantiation script
98 #cd /opt
99 #mv vdhcp.sh /etc/init.d
100 #update-rc.d vdhcp.sh defaults
101 #./v_dhcp_init.sh