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 [OPTIONS]"
32 echo -e "Install source code in ./openmano and the needed packages"
34 echo -e " -u USER database admin user. 'root' by default. Prompts if needed"
35 echo -e " -p PASS database admin password to be used or installed.Prompts if needed"
36 echo -e " -q: install in an unattended mode"
37 echo -e " -h: show this help"
40 function install_packages
(){
41 [ -x /usr
/bin
/apt-get
] && apt-get
install -y $
*
42 [ -x /usr
/bin
/yum
] && yum
install -y $
*
44 #check properly installed
47 PACKAGE_INSTALLED
="no"
48 [ -x /usr
/bin
/apt-get
] && dpkg
-l $PACKAGE &>> /dev
/null
&& PACKAGE_INSTALLED
="yes"
49 [ -x /usr
/bin
/yum
] && yum list installed
$PACKAGE &>> /dev
/null
&& PACKAGE_INSTALLED
="yes"
50 if [ "$PACKAGE_INSTALLED" = "no" ]
52 echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" >&2
62 while getopts ":u:p:hiq-:" o
; do
65 export DBUSER
="$OPTARG"
68 export DBPASSWD
="$OPTARG"
69 export DBPASSWD_PARAM
="-p$OPTARG"
73 export DEBIAN_FRONTEND
=noninteractive
79 [ "${OPTARG}" == "help" ] && usage
&& exit 0
80 echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2
84 echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2
88 echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2
98 #check root privileges and non a root user behind
99 [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit -1
100 if [[ -z "$SUDO_USER" ]] ||
[[ "$SUDO_USER" = "root" ]]
102 [[ -z $QUIET_MODE ]] && read -e -p "Install in the root user (y/N)?" KK
103 [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
104 export SUDO_USER
=root
107 #Discover Linux distribution
109 [ -f /etc
/redhat-release
] && _DISTRO
=$
(cat /etc
/redhat-release
2>/dev
/null | cut
-d" " -f1)
110 #if not assuming ubuntu type
111 [ -f /etc
/redhat-release
] || _DISTRO
=$
(lsb_release
-is 2>/dev
/null
)
112 if [ "$_DISTRO" == "Ubuntu" ]
115 if ! lsb_release
-rs |
grep -q "14."
117 [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a '$_RELEASE' type? (y/N)" KK
118 [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
120 elif [ "$_DISTRO" == "CentOS" ]
123 if ! cat /etc
/redhat-release |
grep -q "7."
125 [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK
126 [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
128 elif [ "$_DISTRO" == "Red" ]
131 if ! cat /etc
/redhat-release |
grep -q "7."
133 [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK
134 [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
136 else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ]
137 _DISTRO_DISCOVER
=$_DISTRO
138 [ -x /usr
/bin
/apt-get
] && _DISTRO
="Ubuntu" && _RELEASE
="14"
139 [ -x /usr
/bin
/yum
] && _DISTRO
="CentOS" && _RELEASE
="7"
140 [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK
141 [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1
147 #################################################################
148 ##### UPDATE REPOSITORIES #####
149 #################################################################'
150 [ "$_DISTRO" == "Ubuntu" ] && apt-get update
-y
152 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update
-y
153 [ "$_DISTRO" == "CentOS" ] && sudo yum
install -y epel-release
154 [ "$_DISTRO" == "Red" ] && wget http
://dl.fedoraproject.org
/pub
/epel
/7/x86_64
/e
/epel-release-7-5.noarch.rpm \
155 && sudo rpm
-ivh epel-release-7-5.noarch.rpm
&& sudo yum
install -y epel-release
&& rm -f epel-release-7-5.noarch.rpm
156 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist
160 #################################################################
161 ##### INSTALL REQUIRED PACKAGES #####
162 #################################################################'
163 [ "$_DISTRO" == "Ubuntu" ] && install_packages
"git screen wget mysql-server"
164 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages
"git screen wget mariadb mariadb-server"
166 if [[ "$_DISTRO" == "Ubuntu" ]]
168 #start services. By default CentOS does not start services
169 service mysql start
>> /dev
/null
170 # try to set admin password, ignore if fails
171 [[ -n $DBPASSWD ]] && mysqladmin
-u $DBUSER -s password
$DBPASSWD
174 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
176 #start services. By default CentOS does not start services
177 service mariadb start
179 systemctl
enable mariadb
180 systemctl
enable httpd
181 read -e -p "Do you want to configure mariadb (recommended if not done before) (Y/n)" KK
182 [ "$KK" != "n" -a "$KK" != "no" ] && mysql_secure_installation
184 read -e -p "Do you want to set firewall to grant web access port 80,443 (Y/n)" KK
185 [ "$KK" != "n" -a "$KK" != "no" ] &&
186 firewall-cmd
--permanent --zone=public
--add-service=http
&&
187 firewall-cmd
--permanent --zone=public
--add-service=https
&&
188 firewall-cmd
--reload
191 #check and ask for database user password. Must be done after database installation
192 if [[ -n $QUIET_MODE ]]
194 echo -e "\nCheking database connection and ask for credentials"
195 while ! mysqladmin
-s -u$DBUSER $DBPASSWD_PARAM ping
197 [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)"
198 [ -z "$logintry" ] && echo -e "\nProvide database credentials"
199 read -e -p "database user? ($DBUSER) " DBUSER_
200 [ -n "$DBUSER_" ] && DBUSER
=$DBUSER_
201 read -e -s -p "database password? (Enter for not using password) " DBPASSWD_
202 [ -n "$DBPASSWD_" ] && DBPASSWD
="$DBPASSWD_" && DBPASSWD_PARAM
="-p$DBPASSWD_"
203 [ -z "$DBPASSWD_" ] && DBPASSWD
="" && DBPASSWD_PARAM
=""
209 #################################################################
210 ##### INSTALL PYTHON PACKAGES #####
211 #################################################################'
212 [ "$_DISTRO" == "Ubuntu" ] && install_packages
"python-yaml python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests python-logutils"
213 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages
"PyYAML MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests python-logutils"
215 #The only way to install python-bottle on Centos7 is with easy_install or pip
216 [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install
-U bottle
218 #install openstack client needed for using openstack as a VIM
219 [ "$_DISTRO" == "Ubuntu" ] && install_packages
"python-novaclient python-keystoneclient python-glanceclient python-neutronclient"
220 [ "$_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
223 #################################################################
224 ##### DOWNLOAD SOURCE #####
225 #################################################################'
226 su
$SUDO_USER -c 'git clone https://osm.etsi.org/gerrit/osm/openmano.git openmano'
229 #################################################################
230 ##### CREATE DATABASE #####
231 #################################################################'
232 mysqladmin
-u$DBUSER $DBPASSWD_PARAM -s create mano_db ||
exit 1
234 echo "CREATE USER 'mano'@'localhost' identified by 'manopw';" | mysql
-u$DBUSER $DBPASSWD_PARAM -s ||
! echo "Failed while creating user mano at dabase" ||
exit 1
235 echo "GRANT ALL PRIVILEGES ON mano_db.* TO 'mano'@'localhost';" | mysql
-u$DBUSER $DBPASSWD_PARAM -s ||
! echo "Failed while creating user mano at dabase" ||
exit 1
236 echo " Database 'mano_db' created, user 'mano' password 'manopw'"
238 su
$SUDO_USER -c 'openmano/database_utils/init_mano_db.sh -u mano -p manopw -d mano_db' ||
! echo "Failed while creating user mano at dabase" ||
exit 1
240 if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ]
243 #################################################################
244 ##### CONFIGURE firewalld #####
245 #################################################################'
247 [[ -z $QUIET_MODE ]] && read -e -p "Configure firewalld for openmanod port 9090? (Y/n)" KK
248 if [ "$KK" != "n" -a "$KK" != "no" ]
250 #Creates a service file for openmano
251 echo '<?xml version="1.0" encoding="utf-8"?>
253 <short>openmanod</short>
254 <description>openmanod service</description>
255 <port protocol="tcp" port="9090"/>
256 </service>' > /etc
/firewalld
/services
/openmanod.xml
257 #put proper permissions
258 pushd /etc
/firewalld
/services
> /dev
/null
259 restorecon openmanod.xml
260 chmod 640 openmanod.xml
262 #Add the openmanod service to the default zone permanently and reload the firewall configuration
263 firewall-cmd
--permanent --add-service=openmanod
> /dev
/null
264 firewall-cmd
--reload > /dev
/null
272 #################################################################
273 ##### CONFIGURE OPENMANO CLIENT #####
274 #################################################################'
275 #creates a link at ~/bin
276 su
$SUDO_USER -c 'mkdir -p ${HOME}/bin'
277 su
$SUDO_USER -c 'rm -f ${HOME}/bin/openmano'
278 su
$SUDO_USER -c 'rm -f ${HOME}/bin/service-openmano'
279 su
$SUDO_USER -c 'ln -s ${PWD}/openmano/openmano ${HOME}/bin/openmano'
280 su
$SUDO_USER -c 'ln -s '${PWD}'/openmano/scripts/openmano-report.sh ${HOME}/bin/openmano-report'
281 su
$SUDO_USER -c 'ln -s '${PWD}'/openmano/scripts/service-openmano.sh ${HOME}/bin/service-openmano'
283 #insert /home/<user>/bin in the PATH
284 #skiped because normally this is done authomatically when ~/bin exist
285 #if ! su $SUDO_USER -c 'echo $PATH' | grep -q "${HOME}/bin"
287 # echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc"
288 # su $SUDO_USER -c 'echo "PATH=\$PATH:\${HOME}/bin" >> ~/.bashrc'
290 if [[ $SUDO_USER == root
]]
292 if ! echo $PATH |
grep -q "${HOME}/bin"
294 echo "PATH=\$PATH:\${HOME}/bin" >> ${HOME}/.bashrc
298 #configure arg-autocomplete for this user
299 #in case of minimal instalation this package is not installed by default
300 [[ "$_DISTRO" == "CentOS" ||
"$_DISTRO" == "Red" ]] && yum
install -y bash-completion
301 #su $SUDO_USER -c 'mkdir -p ~/.bash_completion.d'
302 su
$SUDO_USER -c 'activate-global-python-argcomplete --user'
303 if ! su
$SUDO_USER -c 'grep -q bash_completion.d/python-argcomplete.sh ${HOME}/.bashrc'
305 echo " inserting .bash_completion.d/python-argcomplete.sh execution at .bashrc"
306 su
$SUDO_USER -c 'echo ". ${HOME}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc'
310 echo "Done! you may need to logout and login again for loading the configuration"
311 echo " Run './openmano/scripts/service-openmano.sh start' for starting openmano in a screen"