vfirewall usecase for arm64
[demo.git] / vnfs / vFW / scripts / v_sink_install_arm64.sh
1 #!/bin/bash
2
3 INSTALL_SCRIPT_VERSION=$(cat /opt/config/install_script_version.txt)
4 CLOUD_ENV=$(cat /opt/config/cloud_env.txt)
5
6 # Convert Network CIDR to Netmask
7 cdr2mask () {
8         # Number of args to shift, 255..255, first non-255 byte, zeroes
9         set -- $(( 5 - ($1 / 8) )) 255 255 255 255 $(( (255 << (8 - ($1 % 8))) & 255 )) 0 0 0
10         [ $1 -gt 1 ] && shift $1 || shift
11         echo ${1-0}.${2-0}.${3-0}.${4-0}
12 }
13
14 # OpenStack network configuration
15 if [[ $CLOUD_ENV == "openstack" ]]
16 then
17         echo 127.0.0.1 $(hostname) >> /etc/hosts
18
19         # Allow remote login as root
20         mv /root/.ssh/authorized_keys /root/.ssh/authorized_keys.bk
21         cp /home/ubuntu/.ssh/authorized_keys /root/.ssh
22
23         MTU=$(/sbin/ifconfig | grep MTU | sed 's/.*MTU://' | sed 's/ .*//' | sort -n | head -1)
24
25         IP=$(cat /opt/config/vsn_private_ip_0.txt)
26         BITS=$(cat /opt/config/protected_private_net_cidr.txt | cut -d"/" -f2)
27         NETMASK=$(cdr2mask $BITS)
28         echo "auto enp2s0" >> /etc/network/interfaces
29         echo "iface enp2s0 inet static" >> /etc/network/interfaces
30         echo "    address $IP" >> /etc/network/interfaces
31         echo "    netmask $NETMASK" >> /etc/network/interfaces
32         echo "    mtu $MTU" >> /etc/network/interfaces
33
34         IP=$(cat /opt/config/vsn_private_ip_1.txt)
35         BITS=$(cat /opt/config/onap_private_net_cidr.txt | cut -d"/" -f2)
36         NETMASK=$(cdr2mask $BITS)
37         echo "auto enp3s0" >> /etc/network/interfaces
38         echo "iface enp3s0 inet static" >> /etc/network/interfaces
39         echo "    address $IP" >> /etc/network/interfaces
40         echo "    netmask $NETMASK" >> /etc/network/interfaces
41         echo "    mtu $MTU" >> /etc/network/interfaces
42
43         ifup enp2s0
44         ifup enp3s0
45 fi
46
47 # Download required dependencies
48 echo "deb http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
49 echo "deb-src http://ppa.launchpad.net/openjdk-r/ppa/ubuntu $(lsb_release -c -s) main" >>  /etc/apt/sources.list.d/java.list
50 apt-get update
51 apt-get install --allow-unauthenticated -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 enp2s0\"/g" /etc/darkstat/init.cfg
56 /etc/init.d/darkstat start
57
58 # Download scripts for virtual sink
59 cd /opt
60 unzip -p -j /opt/vfw-scripts-$INSTALL_SCRIPT_VERSION.zip v_sink_init.sh > /opt/v_sink_init.sh
61 unzip -p -j /opt/vfw-scripts-$INSTALL_SCRIPT_VERSION.zip vsink.sh > /opt/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