a019e6a0a55760399f5c5a0e5ceb15b6cfb49c59
[demo.git] / vnfs / vCPE / scripts / v_aaa_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_signal_net_ipaddr.txt)
28         BITS=$(cat /opt/config/cpe_signal_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 apt-transport-https ca-certificates g++ libcurl4-gnutls-dev
54 sleep 1
55
56 # Download DHCP config files
57 cd /opt
58 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip v_aaa_init.sh > /opt/v_aaa_init.sh
59 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip v_aaa.sh > /opt/v_aaa.sh
60 chmod +x v_aaa_init.sh
61 chmod +x v_aaa.sh
62 mv v_aaa.sh /etc/init.d
63 update-rc.d v_aaa.sh defaults
64
65 # Download and install FreeRADIUS as AAA server
66 apt-get install -y freeradius
67
68 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
69 if [[ $CLOUD_ENV != "rackspace" ]]
70 then
71         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
72         grub-mkconfig -o /boot/grub/grub.cfg
73         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
74         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
75         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
76         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
77         reboot
78 fi
79
80 ./v_aaa_init.sh