8be71979379939122f1082592d121f9d355b744b
[demo.git] / vnfs / vCPE / scripts / v_web_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_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 apt-transport-https ca-certificates  kea-dhcp4-server g++ libcurl4-gnutls-dev
54 sleep 1
55
56 # Download DHCP config and init files
57 cd /opt
58 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip kea-dhcp4-web.conf > /opt/kea-dhcp4-web.conf
59 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip v_web_init.sh > /opt/v_web_init.sh
60 unzip -p -j /opt/vcpe-scripts-$INSTALL_SCRIPT_VERSION.zip v_web.sh > /opt/v_web.sh
61
62
63
64 # Configure DHCP
65 cp kea-dhcp4-web.conf /etc/kea-dhcp4-server.conf
66 mv kea-dhcp4-web.conf /etc/kea/kea-dhcp4.conf
67
68
69 chmod +x v_web_init.sh
70 chmod +x v_web.sh
71 mv v_web.sh /etc/init.d
72 update-rc.d v_web.sh defaults
73
74 # Install Apache2 web server
75 apt-get update
76 apt install -y apache2
77 mv /var/www/html/index.html /var/www/html/index.html.example
78 cat > /var/www/html/index.html << EOF
79 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
80 <html xmlns="http://www.w3.org/1999/xhtml">
81 <body>
82 <center><h1>Welcome to the vCPE Use Case Web Server!</h1><center>
83 </body>
84 </html>
85 EOF
86
87 # Rename network interface in openstack Ubuntu 16.04 images. Then, reboot the VM to pick up changes
88 if [[ $CLOUD_ENV != "rackspace" ]]
89 then
90         sed -i "s/GRUB_CMDLINE_LINUX=.*/GRUB_CMDLINE_LINUX=\"net.ifnames=0 biosdevname=0\"/g" /etc/default/grub
91         grub-mkconfig -o /boot/grub/grub.cfg
92         sed -i "s/ens[0-9]*/eth0/g" /etc/network/interfaces.d/*.cfg
93         sed -i "s/ens[0-9]*/eth0/g" /etc/udev/rules.d/70-persistent-net.rules
94         echo 'network: {config: disabled}' >> /etc/cloud/cloud.cfg.d/99-disable-network-config.cfg
95         echo "APT::Periodic::Unattended-Upgrade \"0\";" >> /etc/apt/apt.conf.d/10periodic
96         reboot
97 fi
98
99 ./v_web_init.sh