added some missing packages for floodlight installation
[osm/openvim.git] / scripts / install-floodlight.sh
1 #!/bin/bash
2
3 ##
4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
6 # All Rights Reserved.
7 #
8 # Licensed under the Apache License, Version 2.0 (the "License"); you may
9 # not use this file except in compliance with the License. You may obtain
10 # a copy of the License at
11 #
12 # http://www.apache.org/licenses/LICENSE-2.0
13 #
14 # Unless required by applicable law or agreed to in writing, software
15 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
16 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
17 # License for the specific language governing permissions and limitations
18 # under the License.
19 #
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
22 ##
23
24 #ONLY TESTED for Ubuntu 14.10 14.04, CentOS7 and RHEL7
25 #Get needed packages, to run floodlight
26
27 function usage(){
28 echo -e "usage: sudo $0 \n Install floodlight v0.9 in ./floodlight-0.90"
29 }
30
31 function install_packages(){
32 [ -x /usr/bin/apt-get ] && apt-get install -y $*
33 [ -x /usr/bin/yum ] && yum install -y $*
34
35 #check properly installed
36 for PACKAGE in $*
37 do
38 PACKAGE_INSTALLED="no"
39 [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
40 [ -x /usr/bin/yum ] && yum list installed $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes"
41 if [ "$PACKAGE_INSTALLED" = "no" ]
42 then
43 echo "failed to install package '$PACKAGE'. Revise network connectivity and try again"
44 exit -1
45 fi
46 done
47 }
48
49 #check root privileges and non a root user behind
50 [ "$1" == "-h" -o "$1" == "--help" ] && usage && exit 0
51 [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && usage >&2 && exit -1
52 [ -z "$SUDO_USER" -o "$SUDO_USER" = "root" ] && echo "Must be runned with sudo from a non root user" >&2 && usage >&2 && exit -1
53
54 echo "This script will update repositories and Installing FloodLight."
55 echo "It will install Java and other packages, that takes a while to download"
56 read -e -p "Do you agree on download and install FloodLight from http://www.projectfloodlight.org upon the owner license? (y/N)" KK
57 [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && exit 0
58
59 #Discover Linux distribution
60 #try redhat type
61 [ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1)
62 #if not assuming ubuntu type
63 [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null)
64 if [ "$_DISTRO" == "Ubuntu" ]
65 then
66 _RELEASE="14"
67 if ! lsb_release -rs | grep -q "14."
68 then
69 read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a '$_RELEASE' type? (y/N)" KK
70 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
71 fi
72 elif [ "$_DISTRO" == "CentOS" ]
73 then
74 _RELEASE="7"
75 if ! cat /etc/redhat-release | grep -q "7."
76 then
77 read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
78 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
79 fi
80 elif [ "$_DISTRO" == "Red" ]
81 then
82 _RELEASE="7"
83 if ! cat /etc/redhat-release | grep -q "7."
84 then
85 read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
86 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
87 fi
88 else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ]
89 _DISTRO_DISCOVER=$_DISTRO
90 [ -x /usr/bin/apt-get ] && _DISTRO="Ubuntu" && _RELEASE="14"
91 [ -x /usr/bin/yum ] && _DISTRO="CentOS" && _RELEASE="7"
92 read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
93 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
94 fi
95
96
97
98 echo '
99 #################################################################
100 ##### UPDATE REPOSITORIES #####
101 #################################################################'
102 [ "$_DISTRO" == "Ubuntu" ] && apt-get update -y
103
104 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y
105 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
106
107 echo '
108 #################################################################
109 ##### DOWNLOADING AND CONFIGURE FLOODLIGHT #####
110 #################################################################'
111 #Install Java JDK and Ant packages at the VM
112 [ "$_DISTRO" == "Ubuntu" ] && install_packages "build-essential default-jdk ant python-dev screen wget python-argcomplete python-requests python-yaml" #TODO revise if packages are needed apart from ant
113 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_package " ant screen wget python-argcomplete python-requests python-yaml"
114
115 #floodlight 0.9
116 echo "downloading v0.90 from the oficial page"
117 su $SUDO_USER -c 'wget https://github.com/floodlight/floodlight/archive/v0.90.tar.gz'
118 su $SUDO_USER -c 'tar xvzf v0.90.tar.gz'
119 #floodlight 1.1
120 #echo "downloading v1.1 from the oficial page"
121 #su $SUDO_USER -c 'wget https://github.com/floodlight/floodlight/archive/v1.1.tar.gz'
122 #su $SUDO_USER -c 'tar xvzf v01.1.tar.gz'
123
124 #Configure Java environment variables. It is seem that is not needed!!!
125 #export JAVA_HOME=/usr/lib/jvm/default-java" >> /home/${SUDO_USER}/.bashr
126 #export PATH=$PATH:$JAVA_HOME
127 #echo "export JAVA_HOME=/usr/lib/jvm/default-java" >> /home/${SUDO_USER}/.bashrc
128 #echo "export PATH=$PATH:$JAVA_HOME" >> /home/${SUDO_USER}/.bashrc
129
130 #Compile floodlight
131 pushd ./floodlight-0.90
132 #pushd ./floodlight-1.1
133 su $SUDO_USER -c 'ant'
134 export FLOODLIGHT_PATH=$(pwd)
135 popd
136
137 echo '
138 #################################################################
139 ##### CONFIGURE envioronment #####
140 #################################################################'
141 #insert into .bashrc
142 echo " inserting FLOODLIGHT_PATH at .bashrc"
143 su $SUDO_USER -c "echo 'export FLOODLIGHT_PATH=\"${FLOODLIGHT_PATH}\"' >> ~/.bashrc"
144
145 echo
146 echo "Done! you may need to logout and login again for loading the configuration"
147 echo " If your have installed openvim, run './openvim/scripts/service-floodlight.sh start' for starting floodlight in a screen"
148
149
150