88c194d0cf45636face60ace69b34c53d640e5e3
[demo.git] / vnfs / vFW / scripts / v_sink_install.sh
1 #!/bin/bash
2
3 REPO_URL_BLOB=$(cat /opt/config/repo_url_blob.txt)
4 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
5 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
6
7 # Convert Network CIDR to Netmask
8 cdr2mask () {
9         # Number of args to shift, 255..255, first non-255 byte, zeroes
10         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
11         [ $1 -gt 1 ] && shift $1 || shift
12         echo ${1-0}.${2-0}.${3-0}.${4-0}
13 }
14
15 # OpenStack network configuration
16 if [[ $CLOUD_ENV == "openstack" ]]
17 then
18         echo 127.0.0.1 $(hostname) >> /etc/hosts
19
20         # Allow remote login as root
21         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
22         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
23
24         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
25
26         IP=$(cat /opt/config/vsn_private_ip_0.txt)
27         BITS=$(cat /opt/config/protected_private_net_cidr.txt | cut -d"/" -f2)
28         NETMASK=$(cdr2mask $BITS)
29         echo "auto eth1" >> /etc/network/interfaces
30         echo "iface eth1 inet static" >> /etc/network/interfaces
31         echo "    address $IP" >> /etc/network/interfaces
32         echo "    netmask $NETMASK" >> /etc/network/interfaces
33         echo "    mtu $MTU" >> /etc/network/interfaces
34
35         IP=$(cat /opt/config/vsn_private_ip_1.txt)
36         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
37         NETMASK=$(cdr2mask $BITS)
38         echo "auto eth2" >> /etc/network/interfaces
39         echo "iface eth2 inet static" >> /etc/network/interfaces
40         echo "    address $IP" >> /etc/network/interfaces
41         echo "    netmask $NETMASK" >> /etc/network/interfaces
42         echo "    mtu $MTU" >> /etc/network/interfaces
43
44         ifup eth1
45         ifup eth2
46 fi
47
48 # Download required dependencies
49 add-apt-repository -y ppa:openjdk-r/ppa
50 apt-get update
51 apt-get install -y make wget openjdk-8-jdk apt-transport-https ca-certificates darkstat
52
53 # Configure and run Darkstat
54 sed -i "s/START_DARKSTAT=.*/START_DARKSTAT=yes/g" /etc/darkstat/init.cfg
55 sed -i "s/INTERFACE=.*/INTERFACE=\"-i eth1\"/g" /etc/darkstat/init.cfg
56 /etc/init.d/darkstat start
57
58 # Download scripts for virtual sink
59 cd /opt
60 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vfw/$INSTALL_SCRIPT_VERSION/v_sink_init.sh
61 wget $REPO_URL_BLOB/org.onap.demo/vnfs/vfw/$INSTALL_SCRIPT_VERSION/vsink.sh
62 chmod +x v_sink_init.sh
63 chmod +x vsink.sh
64
65 # Run instantiation script
66 mv vsink.sh /etc/init.d
67 update-rc.d vsink.sh defaults
68 ./v_sink_init.sh