4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openvim
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
12 # http://www.apache.org/licenses/LICENSE-2.0
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
20 # For those usages not covered by the Apache License, Version 2.0 please
21 # contact with: nfvlabs@tid.es
24 #ONLY TESTED for Ubuntu 14.10 14.04, CentOS7 and RHEL7
25 #Get needed packages, to run floodlight
28 echo -e "usage: sudo $0 \n Install floodlight v0.9 in ./floodlight-0.90"
31 function install_packages
(){
32 [ -x /usr
/bin
/apt-get
] && apt-get
install -y $
*
33 [ -x /usr
/bin
/yum
] && yum
install -y $
*
35 #check properly installed
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" ]
43 echo "failed to install package '$PACKAGE'. Revise network connectivity and try again"
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
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
59 #Discover Linux distribution
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" ]
67 if ! lsb_release
-rs |
grep -q "14."
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
72 elif [ "$_DISTRO" == "CentOS" ]
75 if ! cat /etc
/redhat-release |
grep -q "7."
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
80 elif [ "$_DISTRO" == "Red" ]
83 if ! cat /etc
/redhat-release |
grep -q "7."
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
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
99 #################################################################
100 ##### UPDATE REPOSITORIES #####
101 #################################################################'
102 [ "$_DISTRO" == "Ubuntu" ] && apt-get update
-y
104 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update
-y
105 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
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"
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'
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'
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
131 pushd .
/floodlight-0.90
132 #pushd ./floodlight-1.1
133 su
$SUDO_USER -c 'ant'
134 export FLOODLIGHT_PATH
=$
(pwd)
138 #################################################################
139 ##### CONFIGURE envioronment #####
140 #################################################################'
142 echo " inserting FLOODLIGHT_PATH at .bashrc"
143 su
$SUDO_USER -c "echo 'export FLOODLIGHT_PATH=\"${FLOODLIGHT_PATH}\"' >> ~/.bashrc"
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"