4 # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U.
5 # This file is part of openmano
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, source code and configure to run openmano
26 #Ask for database user and password if not provided
28 # $2: database password
31 echo -e "usage: sudo $0 [db-user [db-passwd]]\n Install source code in ./openmano"
34 function install_packages
(){
35 [ -x /usr
/bin
/apt-get
] && apt-get
install -y $
*
36 [ -x /usr
/bin
/yum
] && yum
install -y $
*
38 #check properly installed
41 PACKAGE_INSTALLED
="no"
42 [ -x /usr
/bin
/apt-get
] && dpkg
-l $PACKAGE &>> /dev
/null
&& PACKAGE_INSTALLED
="yes"
43 [ -x /usr
/bin
/yum
] && yum list installed
$PACKAGE &>> /dev
/null
&& PACKAGE_INSTALLED
="yes"
44 if [ "$PACKAGE_INSTALLED" = "no" ]
46 echo "failed to install package '$PACKAGE'. Revise network connectivity and try again"
52 #check root privileges and non a root user behind
53 [ "$1" == "-h" -o "$1" == "--help" ] && usage
&& exit 0
54 [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && usage
>&2 && exit -1
55 [ -z "$SUDO_USER" -o "$SUDO_USER" = "root" ] && echo "Must be runned with sudo from a non root user" >&2 && usage
>&2 && exit -1
58 #Discover Linux distribution
60 [ -f /etc
/redhat-release
] && _DISTRO
=$
(cat /etc
/redhat-release
2>/dev
/null | cut
-d" " -f1)
61 #if not assuming ubuntu type
62 [ -f /etc
/redhat-release
] || _DISTRO
=$
(lsb_release
-is 2>/dev
/null
)
63 if [ "$_DISTRO" == "Ubuntu" ]
66 if ! lsb_release
-rs |
grep -q "14."
68 read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a '$_RELEASE' type? (y/N)" KK
69 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
71 elif [ "$_DISTRO" == "CentOS" ]
74 if ! cat /etc
/redhat-release |
grep -q "7."
76 read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
77 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
79 elif [ "$_DISTRO" == "Red" ]
82 if ! cat /etc
/redhat-release |
grep -q "7."
84 read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
85 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
87 else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ]
88 _DISTRO_DISCOVER
=$_DISTRO
89 [ -x /usr
/bin
/apt-get
] && _DISTRO
="Ubuntu" && _RELEASE
="14"
90 [ -x /usr
/bin
/yum
] && _DISTRO
="CentOS" && _RELEASE
="7"
91 read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
92 [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0
98 #################################################################
99 ##### UPDATE REPOSITORIES #####
100 #################################################################'
101 [ "$_DISTRO" == "Ubuntu" ] && apt-get update
-y
103 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update
-y
104 [ "$_DISTRO" == "CentOS" ] && sudo yum
install -y epel-release
105 [ "$_DISTRO" == "Red" ] && wget http
://dl.fedoraproject.org
/pub
/epel
/7/x86_64
/e
/epel-release-7-5.noarch.rpm \
106 && sudo rpm
-ivh epel-release-7-5.noarch.rpm
&& sudo yum
install -y epel-release
&& rm -f epel-release-7-5.noarch.rpm
107 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
111 #################################################################
112 ##### INSTALL REQUIRED PACKAGES #####
113 #################################################################'
114 [ "$_DISTRO" == "Ubuntu" ] && install_packages
"git screen wget mysql-server"
115 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages
"git screen wget mariadb mariadb-server"
117 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
119 #start services. By default CentOS does not start services
120 service mariadb start
122 systemctl
enable mariadb
123 systemctl
enable httpd
124 read -e -p "Do you want to configure mariadb (recommended if not done before) (Y/n)" KK
125 [ "$KK" != "n" -a "$KK" != "no" ] && mysql_secure_installation
127 read -e -p "Do you want to set firewall to grant web access port 80,443 (Y/n)" KK
128 [ "$KK" != "n" -a "$KK" != "no" ] &&
129 firewall-cmd
--permanent --zone=public
--add-service=http
&&
130 firewall-cmd
--permanent --zone=public
--add-service=https
&&
131 firewall-cmd
--reload
134 #check and ask for database user password. Must be done after database installation
135 [ -n "$1" ] && DBUSER
=$1
136 [ -z "$1" ] && DBUSER
=root
137 [ -n "$2" ] && DBPASSWD
="-p$2"
138 [ -z "$2" ] && DBPASSWD
=""
139 echo -e "\nCheking database connection and ask for credentials"
140 while ! echo "" | mysql
-u$DBUSER $DBPASSWD
142 [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
143 [ -z "$logintry" ] && echo -e "\nProvide database credentials"
144 read -e -p "database user? ($DBUSER) " DBUSER_
145 [ -n "$DBUSER_" ] && DBUSER
=$DBUSER_
146 read -e -s -p "database password? (Enter for not using password) " DBPASSWD_
147 [ -n "$DBPASSWD_" ] && DBPASSWD
="-p$DBPASSWD_"
148 [ -z "$DBPASSWD_" ] && DBPASSWD
=""
153 #################################################################
154 ##### INSTALL PYTHON PACKAGES #####
155 #################################################################'
156 [ "$_DISTRO" == "Ubuntu" ] && install_packages
"python-yaml python-libvirt python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests"
157 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages
"PyYAML libvirt-python MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests"
159 #The only way to install python-bottle on Centos7 is with easy_install or pip
160 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install
-U bottle
162 #install openstack client needed for using openstack as a VIM
163 [ "$_DISTRO" == "Ubuntu" ] && install_packages
"python-novaclient python-keystoneclient python-glanceclient python-neutronclient"
164 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages
"python-devel" && easy_install python-novaclient python-keystoneclient python-glanceclient python-neutronclient
#TODO revise if gcc python-pip is needed
167 #################################################################
168 ##### DOWNLOAD SOURCE #####
169 #################################################################'
170 su
$SUDO_USER -c 'git clone https://osm.etsi.org/gerrit/osm/openmano.git openmano'
173 #################################################################
174 ##### CREATE DATABASE #####
175 #################################################################'
176 mysqladmin
-u$DBUSER $DBPASSWD create mano_db
178 echo "CREATE USER 'mano'@'localhost' identified by 'manopw';" | mysql
-u$DBUSER $DBPASSWD
179 echo "GRANT ALL PRIVILEGES ON mano_db.* TO 'mano'@'localhost';" | mysql
-u$DBUSER $DBPASSWD
181 su
$SUDO_USER -c 'openmano/database_utils/init_mano_db.sh -u mano -p manopw'
183 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
186 #################################################################
187 ##### CONFIGURE firewalld #####
188 #################################################################'
189 read -e -p "Configure firewalld for openmanod port 9090? (Y/n)" KK
190 if [ "$KK" != "n" -a "$KK" != "no" ]
192 #Creates a service file for openmano
193 echo '<?xml version="1.0" encoding="utf-8"?>
195 <short>openmanod</short>
196 <description>openmanod service</description>
197 <port protocol="tcp" port="9090"/>
198 </service>' > /etc
/firewalld
/services
/openmanod.xml
199 #put proper permissions
200 pushd /etc
/firewalld
/services
> /dev
/null
201 restorecon openmanod.xml
202 chmod 640 openmanod.xml
204 #Add the openmanod service to the default zone permanently and reload the firewall configuration
205 firewall-cmd
--permanent --add-service=openmanod
> /dev
/null
206 firewall-cmd
--reload > /dev
/null
214 #################################################################
215 ##### CONFIGURE OPENMANO CLIENT #####
216 #################################################################'
217 #creates a link at ~/bin
218 su
$SUDO_USER -c 'mkdir -p ~/bin'
219 rm -f /home
/${SUDO_USER}/bin
/openmano
220 rm -f /home
/${SUDO_USER}/bin
/service-openmano
221 ln -s ${PWD}/openmano
/openmano
/openmano
/home
/${SUDO_USER}/bin
/openmano
222 ln -s ${PWD}/openmano
/scripts
/openmano-report.sh
/home
/${SUDO_USER}/bin
/openmano-report
223 ln -s ${PWD}/openmano
/scripts
/service-openmano.sh
/home
/${SUDO_USER}/bin
/service-openmano
225 #insert /home/<user>/bin in the PATH
226 #skiped because normally this is done authomatically when ~/bin exist
227 #if ! su $SUDO_USER -c 'echo $PATH' | grep -q "/home/${SUDO_USER}/bin"
229 # echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc"
230 # su $SUDO_USER -c 'echo "PATH=\$PATH:/home/\${USER}/bin" >> ~/.bashrc'
233 #configure arg-autocomplete for this user
234 #in case of minimal instalation this package is not installed by default
235 [[ "$_DISTRO" == "CentOS" ||
"$_DISTRO" == "Red" ]] && yum
install -y bash-completion
236 #su $SUDO_USER -c 'mkdir -p ~/.bash_completion.d'
237 su
$SUDO_USER -c 'activate-global-python-argcomplete --user'
238 if ! grep -q bash_completion.d
/python-argcomplete.sh
/home
/${SUDO_USER}/.bashrc
240 echo " inserting .bash_completion.d/python-argcomplete.sh execution at .bashrc"
241 su
$SUDO_USER -c 'echo ". /home/${USER}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc'
245 echo "Done! you may need to logout and login again for loading the configuration"
246 echo " Run './openmano/scripts/service-openmano.sh start' for starting openmano in a screen"