| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | |
| 3 | ## |
| 4 | # Copyright 2015 Telefónica Investigación y Desarrollo, S.A.U. |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 5 | # This file is part of openvim |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 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 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 24 | #ONLY TESTED for Ubuntu 14.10 14.04 16.04, CentOS7 and RHEL7 |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 25 | #Get needed packages, source code and configure to run openvim |
| 26 | #Ask for database user and password if not provided |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 27 | |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 28 | |
| 29 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 30 | function usage(){ |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 31 | echo -e "usage: sudo $0 [OPTIONS]" |
| 32 | echo -e "Install last stable source code in ./openvim and the needed packages" |
| 33 | echo -e "On a Ubuntu 16.04 it configures openvim as a service" |
| 34 | echo -e " OPTIONS" |
| 35 | echo -e " -u USER: database admin user. 'root' by default. Prompts if needed" |
| 36 | echo -e " -p PASS: database admin password to be used or installed. Prompts if needed" |
| 37 | echo -e " -q --quiet: install in an unattended mode" |
| 38 | echo -e " -h --help: show this help" |
| 39 | echo -e " --develop: install last version for developers, and do not configure as a service" |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 40 | echo -e " --force: makes idenpotent, delete previous installations folders if needed" |
| 41 | echo -e " --noclone: assumes that openvim was cloned previously and that this script is run from the local repo" |
| 42 | echo -e " --no-install-packages: use this option to skip updating and installing the requires packages. This avoid wasting time if you are sure requires packages are present e.g. because of a previous installation" |
| mirabal | d87877c | 2017-03-31 15:15:52 +0200 | [diff] [blame] | 43 | echo -e " --no-db: do not insall mysql server" |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 44 | } |
| 45 | |
| 46 | function install_packages(){ |
| 47 | [ -x /usr/bin/apt-get ] && apt-get install -y $* |
| 48 | [ -x /usr/bin/yum ] && yum install -y $* |
| 49 | |
| 50 | #check properly installed |
| 51 | for PACKAGE in $* |
| 52 | do |
| 53 | PACKAGE_INSTALLED="no" |
| 54 | [ -x /usr/bin/apt-get ] && dpkg -l $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes" |
| 55 | [ -x /usr/bin/yum ] && yum list installed $PACKAGE &>> /dev/null && PACKAGE_INSTALLED="yes" |
| 56 | if [ "$PACKAGE_INSTALLED" = "no" ] |
| 57 | then |
| 58 | echo "failed to install package '$PACKAGE'. Revise network connectivity and try again" |
| 59 | exit -1 |
| 60 | fi |
| 61 | done |
| 62 | } |
| 63 | |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 64 | function db_exists() { |
| 65 | RESULT=`mysqlshow --defaults-extra-file="$2" | grep -v Wildcard | grep -o $1` |
| 66 | if [ "$RESULT" == "$1" ]; then |
| 67 | echo " DB $1 exists" |
| 68 | return 0 |
| 69 | fi |
| 70 | echo " DB $1 does not exist" |
| 71 | return 1 |
| 72 | } |
| 73 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 74 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 75 | GIT_URL=https://osm.etsi.org/gerrit/osm/openvim.git |
| 76 | DBUSER="root" |
| 77 | DBPASSWD="" |
| 78 | DBPASSWD_PARAM="" |
| 79 | QUIET_MODE="" |
| 80 | DEVELOP="" |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 81 | FORCE="" |
| 82 | NOCLONE="" |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 83 | NO_PACKAGES="" |
| mirabal | d87877c | 2017-03-31 15:15:52 +0200 | [diff] [blame] | 84 | NO_DB="" |
| 85 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 86 | while getopts ":u:p:hiq-:" o; do |
| 87 | case "${o}" in |
| 88 | u) |
| 89 | export DBUSER="$OPTARG" |
| 90 | ;; |
| 91 | p) |
| 92 | export DBPASSWD="$OPTARG" |
| 93 | export DBPASSWD_PARAM="-p$OPTARG" |
| 94 | ;; |
| 95 | q) |
| 96 | export QUIET_MODE=yes |
| 97 | export DEBIAN_FRONTEND=noninteractive |
| 98 | ;; |
| 99 | h) |
| 100 | usage && exit 0 |
| 101 | ;; |
| 102 | -) |
| 103 | [ "${OPTARG}" == "help" ] && usage && exit 0 |
| 104 | [ "${OPTARG}" == "develop" ] && DEVELOP="y" && continue |
| mirabal | d87877c | 2017-03-31 15:15:52 +0200 | [diff] [blame] | 105 | [ "${OPTARG}" == "force" ] && FORCE="y" && continue |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 106 | [ "${OPTARG}" == "noclone" ] && NOCLONE="y" && continue |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 107 | [ "${OPTARG}" == "quiet" ] && export QUIET_MODE=yes && export DEBIAN_FRONTEND=noninteractive && continue |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 108 | [ "${OPTARG}" == "no-install-packages" ] && export NO_PACKAGES=yes && continue |
| mirabal | d87877c | 2017-03-31 15:15:52 +0200 | [diff] [blame] | 109 | [ "${OPTARG}" == "no-db" ] && NO_DB="y" && continue |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 110 | echo -e "Invalid option: '--$OPTARG'\nTry $0 --help for more information" >&2 |
| 111 | exit 1 |
| 112 | ;; |
| 113 | \?) |
| 114 | echo -e "Invalid option: '-$OPTARG'\nTry $0 --help for more information" >&2 |
| 115 | exit 1 |
| 116 | ;; |
| 117 | :) |
| 118 | echo -e "Option '-$OPTARG' requires an argument\nTry $0 --help for more information" >&2 |
| 119 | exit 1 |
| 120 | ;; |
| 121 | *) |
| 122 | usage >&2 |
| 123 | exit -1 |
| 124 | ;; |
| 125 | esac |
| 126 | done |
| 127 | |
| 128 | #check root privileges and non a root user behind |
| 129 | [ "$USER" != "root" ] && echo "Needed root privileges" >&2 && exit -1 |
| 130 | if [[ -z "$SUDO_USER" ]] || [[ "$SUDO_USER" = "root" ]] |
| 131 | then |
| 132 | [[ -z $QUIET_MODE ]] && read -e -p "Install in the root user (y/N)?" KK |
| 133 | [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1 |
| 134 | export SUDO_USER=root |
| 135 | fi |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 136 | |
| 137 | #Discover Linux distribution |
| 138 | #try redhat type |
| 139 | [ -f /etc/redhat-release ] && _DISTRO=$(cat /etc/redhat-release 2>/dev/null | cut -d" " -f1) |
| 140 | #if not assuming ubuntu type |
| 141 | [ -f /etc/redhat-release ] || _DISTRO=$(lsb_release -is 2>/dev/null) |
| 142 | if [ "$_DISTRO" == "Ubuntu" ] |
| 143 | then |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 144 | _RELEASE=$(lsb_release -rs) |
| 145 | if [[ ${_RELEASE%%.*} != 14 ]] && [[ ${_RELEASE%%.*} != 16 ]] |
| 146 | then |
| 147 | [[ -z $QUIET_MODE ]] && read -e -p "WARNING! Not tested Ubuntu version. Continue assuming a trusty (14.XX)'? (y/N)" KK |
| 148 | [[ -z $QUIET_MODE ]] && [[ "$KK" != "y" ]] && [[ "$KK" != "yes" ]] && echo "Cancelled" && exit 1 |
| 149 | _RELEASE = 14 |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 150 | fi |
| 151 | elif [ "$_DISTRO" == "CentOS" ] |
| 152 | then |
| 153 | _RELEASE="7" |
| 154 | if ! cat /etc/redhat-release | grep -q "7." |
| 155 | then |
| 156 | read -e -p "WARNING! Not tested CentOS version. Continue assuming a '_RELEASE' type? (y/N)" KK |
| 157 | [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0 |
| 158 | fi |
| 159 | elif [ "$_DISTRO" == "Red" ] |
| 160 | then |
| 161 | _RELEASE="7" |
| 162 | if ! cat /etc/redhat-release | grep -q "7." |
| 163 | then |
| 164 | read -e -p "WARNING! Not tested Red Hat OS version. Continue assuming a '_RELEASE' type? (y/N)" KK |
| 165 | [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0 |
| 166 | fi |
| 167 | else #[ "$_DISTRO" != "Ubuntu" -a "$_DISTRO" != "CentOS" -a "$_DISTRO" != "Red" ] |
| 168 | _DISTRO_DISCOVER=$_DISTRO |
| 169 | [ -x /usr/bin/apt-get ] && _DISTRO="Ubuntu" && _RELEASE="14" |
| 170 | [ -x /usr/bin/yum ] && _DISTRO="CentOS" && _RELEASE="7" |
| 171 | read -e -p "WARNING! Not tested Linux distribution '$_DISTRO_DISCOVER '. Continue assuming a '$_DISTRO $_RELEASE' type? (y/N)" KK |
| 172 | [ "$KK" != "y" -a "$KK" != "yes" ] && echo "Cancelled" && exit 0 |
| 173 | fi |
| 174 | |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 175 | #check if installed as a service |
| 176 | INSTALL_AS_A_SERVICE="" |
| 177 | [[ "$_DISTRO" == "Ubuntu" ]] && [[ ${_RELEASE%%.*} == 16 ]] && [[ -z $DEVELOP ]] && INSTALL_AS_A_SERVICE="y" |
| 178 | |
| 179 | #Next operations require knowing BASEFOLDER |
| 180 | if [[ -z "$NOCLONE" ]]; then |
| 181 | if [[ -n "$INSTALL_AS_A_SERVICE" ]] ; then |
| 182 | OPENVIM_BASEFOLDER=__openvim__${RANDOM} |
| 183 | else |
| 184 | OPENVIM_BASEFOLDER="${PWD}/openvim" |
| 185 | fi |
| 186 | [[ -n "$FORCE" ]] && rm -rf $OPENVIM_BASEFOLDER #make idempotent |
| 187 | else |
| 188 | HERE=$(realpath $(dirname $0)) |
| 189 | OPENVIM_BASEFOLDER=$(dirname $HERE) |
| 190 | fi |
| 191 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 192 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 193 | if [[ -z "$NO_PACKAGES" ]] |
| 194 | then |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 195 | echo ' |
| 196 | ################################################################# |
| 197 | ##### UPDATE REPOSITORIES ##### |
| 198 | #################################################################' |
| 199 | [ "$_DISTRO" == "Ubuntu" ] && apt-get update -y |
| 200 | |
| 201 | [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && yum check-update -y |
| 202 | [ "$_DISTRO" == "CentOS" ] && sudo yum install -y epel-release |
| 203 | [ "$_DISTRO" == "Red" ] && wget http://dl.fedoraproject.org/pub/epel/7/x86_64/e/epel-release-7-5.noarch.rpm \ |
| 204 | && sudo rpm -ivh epel-release-7-5.noarch.rpm && sudo yum install -y epel-release && rm -f epel-release-7-5.noarch.rpm |
| 205 | [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && sudo yum repolist |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 206 | fi |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 207 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 208 | if [[ -z "$NO_PACKAGES" ]] |
| 209 | then |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 210 | echo ' |
| 211 | ################################################################# |
| 212 | ##### INSTALL REQUIRED PACKAGES ##### |
| 213 | #################################################################' |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 214 | [ "$_DISTRO" == "Ubuntu" ] && install_packages "git screen wget mysql-server" |
| 215 | [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "git screen wget mariadb mariadb-server" |
| 216 | |
| 217 | if [[ "$_DISTRO" == "Ubuntu" ]] |
| 218 | then |
| 219 | #start services. By default CentOS does not start services |
| 220 | service mysql start >> /dev/null |
| 221 | # try to set admin password, ignore if fails |
| 222 | [[ -n $DBPASSWD ]] && mysqladmin -u $DBUSER -s password $DBPASSWD |
| 223 | fi |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 224 | |
| 225 | if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] |
| 226 | then |
| 227 | #start services. By default CentOS does not start services |
| 228 | service mariadb start |
| 229 | service httpd start |
| 230 | systemctl enable mariadb |
| 231 | systemctl enable httpd |
| 232 | read -e -p "Do you want to configure mariadb (recomended if not done before) (Y/n)" KK |
| 233 | [ "$KK" != "n" -a "$KK" != "no" ] && mysql_secure_installation |
| 234 | |
| 235 | read -e -p "Do you want to set firewall to grant web access port 80,443 (Y/n)" KK |
| 236 | [ "$KK" != "n" -a "$KK" != "no" ] && |
| 237 | firewall-cmd --permanent --zone=public --add-service=http && |
| 238 | firewall-cmd --permanent --zone=public --add-service=https && |
| 239 | firewall-cmd --reload |
| 240 | fi |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 241 | fi #[[ -z "$NO_PACKAGES" ]] |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 242 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 243 | #check and ask for database user password. Must be done after database installation |
| 244 | if [[ -n $QUIET_MODE ]] |
| 245 | then |
| 246 | echo -e "\nCheking database connection and ask for credentials" |
| tierno | 2594a3a | 2016-10-13 13:11:31 +0000 | [diff] [blame] | 247 | while ! mysqladmin -s -u$DBUSER $DBPASSWD_PARAM status >/dev/null |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 248 | do |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 249 | [ -n "$logintry" ] && echo -e "\nInvalid database credentials!!!. Try again (Ctrl+c to abort)" |
| 250 | [ -z "$logintry" ] && echo -e "\nProvide database credentials" |
| 251 | read -e -p "database user? ($DBUSER) " DBUSER_ |
| 252 | [ -n "$DBUSER_" ] && DBUSER=$DBUSER_ |
| 253 | read -e -s -p "database password? (Enter for not using password) " DBPASSWD_ |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 254 | [ -n "$DBPASSWD_" ] && DBPASSWD="$DBPASSWD_" && DBPASSWD_PARAM="-p$DBPASSWD_" |
| 255 | [ -z "$DBPASSWD_" ] && DBPASSWD="" && DBPASSWD_PARAM="" |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 256 | logintry="yes" |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 257 | done |
| 258 | fi |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 259 | |
| mirabal | d87877c | 2017-03-31 15:15:52 +0200 | [diff] [blame] | 260 | |
| 261 | if [ -z "$NO_DB" ]; then |
| 262 | if [ -n "$QUIET_MODE" ]; then |
| 263 | DB_QUIET='-q' |
| 264 | fi |
| 265 | |
| 266 | echo "!!!! install-db-server.sh: ${OPENVIM_BASEFOLDER}/scripts/install-db-server.sh -u $DBUSER $DBPASSWD_PARAM -n vim_db $DB_QUIET" |
| 267 | ${OPENVIM_BASEFOLDER}/scripts/install-db-server.sh -u $DBUSER $DBPASSWD_PARAM $DB_QUIET || exit 1 |
| 268 | fi |
| 269 | |
| 270 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 271 | if [[ -z "$NO_PACKAGES" ]] |
| 272 | then |
| mirabal | d87877c | 2017-03-31 15:15:52 +0200 | [diff] [blame] | 273 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 274 | echo ' |
| 275 | ################################################################# |
| 276 | ##### INSTALL PYTHON PACKAGES ##### |
| 277 | #################################################################' |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 278 | [ "$_DISTRO" == "Ubuntu" ] && install_packages "python-yaml python-libvirt python-bottle python-mysqldb python-jsonschema python-paramiko python-argcomplete python-requests" |
| 279 | [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && install_packages "PyYAML libvirt-python MySQL-python python-jsonschema python-paramiko python-argcomplete python-requests" |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 280 | |
| 281 | #The only way to install python-bottle on Centos7 is with easy_install or pip |
| 282 | [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] && easy_install -U bottle |
| 283 | |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 284 | fi #[[ -z "$NO_PACKAGES" ]] |
| 285 | |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 286 | if [[ -z $NOCLONE ]]; then |
| 287 | echo ' |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 288 | ################################################################# |
| 289 | ##### DOWNLOAD SOURCE ##### |
| 290 | #################################################################' |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 291 | if [[ -d "${OPENVIM_BASEFOLDER}" ]] |
| 292 | then |
| 293 | if [[ -n "$FORCE" ]] |
| 294 | then |
| 295 | echo "deleting '${OPENVIM_BASEFOLDER}' folder" |
| 296 | rm -rf "$OPENVIM_BASEFOLDER" #make idempotent |
| 297 | elif [[ -z "$QUIET_MODE" ]] |
| 298 | then |
| 299 | read -e -p "${OPENVIM_BASEFOLDER} folder exist, overwrite? (y/N)" KK |
| 300 | if [[ "$KK" == "y" ]] || [[ "$KK" == "yes" ]] |
| 301 | then rm -rf "$OPENVIM_BASEFOLDER" |
| 302 | else |
| 303 | echo "canceled" |
| 304 | exit 1 |
| 305 | fi |
| 306 | else |
| 307 | echo "'${OPENVIM_BASEFOLDER}' folder exist" >&2 && exit 1 |
| 308 | fi |
| 309 | fi |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 310 | |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 311 | |
| 312 | su $SUDO_USER -c "git clone ${GIT_URL} ${OPENVIM_BASEFOLDER}" |
| 313 | su $SUDO_USER -c "cp ${OPENVIM_BASEFOLDER}/.gitignore-common ${OPENVIM_BASEFOLDER}/.gitignore" |
| tierno | 8940f6c | 2016-12-16 11:19:59 +0100 | [diff] [blame] | 314 | [[ -z $DEVELOP ]] && su $SUDO_USER -c "git -C ${OPENVIM_BASEFOLDER} checkout tags/v1.0.2" |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 315 | fi |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 316 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 317 | |
| 318 | |
| 319 | if [ "$_DISTRO" == "CentOS" -o "$_DISTRO" == "Red" ] |
| 320 | then |
| 321 | echo ' |
| 322 | ################################################################# |
| 323 | ##### CONFIGURE firewalld ##### |
| 324 | #################################################################' |
| 325 | read -e -p "Configure firewalld for openvimd port 9080? (Y/n)" KK |
| 326 | if [ "$KK" != "n" -a "$KK" != "no" ] |
| 327 | then |
| 328 | #Creates a service file for openvim |
| 329 | echo '<?xml version="1.0" encoding="utf-8"?> |
| 330 | <service> |
| 331 | <short>openvimd</short> |
| 332 | <description>openvimd service</description> |
| 333 | <port protocol="tcp" port="9080"/> |
| 334 | </service>' > /etc/firewalld/services/openvimd.xml |
| 335 | #put proper permissions |
| 336 | pushd /etc/firewalld/services > /dev/null |
| 337 | restorecon openvim |
| 338 | chmod 640 openvim |
| 339 | popd > /dev/null |
| 340 | #Add the openvim service to the default zone permanently and reload the firewall configuration |
| 341 | firewall-cmd --permanent --add-service=openvim > /dev/null |
| 342 | firewall-cmd --reload > /dev/null |
| 343 | echo "done." |
| 344 | else |
| 345 | echo "skipping." |
| 346 | fi |
| 347 | fi |
| 348 | |
| 349 | echo ' |
| 350 | ################################################################# |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 351 | ##### CONFIGURE openvim CLIENT ##### |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 352 | #################################################################' |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 353 | #creates a link at ~/bin if not configured as a service |
| 354 | if [[ -z "$INSTALL_AS_A_SERVICE" ]] |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 355 | then |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 356 | su $SUDO_USER -c 'mkdir -p ~/bin' |
| 357 | su $SUDO_USER -c 'rm -f ${HOME}/bin/openvim' |
| 358 | su $SUDO_USER -c 'rm -f ${HOME}/bin/openflow' |
| 359 | su $SUDO_USER -c 'rm -f ${HOME}/bin/service-openvim' |
| 360 | su $SUDO_USER -c 'rm -f ${HOME}/bin/initopenvim' |
| 361 | su $SUDO_USER -c 'rm -f ${HOME}/bin/service-floodlight' |
| 362 | su $SUDO_USER -c 'rm -f ${HOME}/bin/service-opendaylight' |
| 363 | su $SUDO_USER -c 'rm -f ${HOME}/bin/get_dhcp_lease.sh' |
| 364 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/openvim' "'${HOME}/bin/openvim' |
| 365 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/openflow' "'${HOME}/bin/openflow' |
| 366 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-openvim.sh' "'${HOME}/bin/service-openvim' |
| 367 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/initopenvim.sh' "'${HOME}/bin/initopenvim' |
| 368 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-floodlight.sh' "'${HOME}/bin/service-floodlight' |
| 369 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/service-opendaylight.sh' "'${HOME}/bin/service-opendaylight' |
| 370 | su $SUDO_USER -c "ln -s '${OPENVIM_BASEFOLDER}/scripts/get_dhcp_lease.sh' "'${HOME}/bin/get_dhcp_lease.sh' |
| 371 | |
| 372 | #insert /home/<user>/bin in the PATH |
| 373 | #skiped because normally this is done authomatically when ~/bin exist |
| 374 | #if ! su $SUDO_USER -c 'echo $PATH' | grep -q "/home/${SUDO_USER}/bin" |
| 375 | #then |
| 376 | # echo " inserting /home/$SUDO_USER/bin in the PATH at .bashrc" |
| 377 | # su $SUDO_USER -c 'echo "PATH=\$PATH:/home/\${USER}/bin" >> ~/.bashrc' |
| 378 | #fi |
| 379 | |
| 380 | if [[ $SUDO_USER == root ]] |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 381 | then |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 382 | if ! echo $PATH | grep -q "${HOME}/bin" |
| 383 | then |
| 384 | echo "PATH=\$PATH:\${HOME}/bin" >> ${HOME}/.bashrc |
| 385 | fi |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 386 | fi |
| 387 | fi |
| 388 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 389 | #configure arg-autocomplete for this user |
| 390 | #in case of minmal instalation this package is not installed by default |
| 391 | [[ "$_DISTRO" == "CentOS" || "$_DISTRO" == "Red" ]] && yum install -y bash-completion |
| 392 | #su $SUDO_USER -c 'mkdir -p ~/.bash_completion.d' |
| 393 | su $SUDO_USER -c 'activate-global-python-argcomplete --user' |
| tierno | 3e9a147 | 2016-09-20 11:05:26 +0000 | [diff] [blame] | 394 | if ! grep -q bash_completion.d/python-argcomplete.sh ${HOME}/.bashrc |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 395 | then |
| 396 | echo " inserting .bash_completion.d/python-argcomplete.sh execution at .bashrc" |
| tierno | 3e9a147 | 2016-09-20 11:05:26 +0000 | [diff] [blame] | 397 | su $SUDO_USER -c 'echo ". ${HOME}/.bash_completion.d/python-argcomplete.sh" >> ~/.bashrc' |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 398 | fi |
| 399 | |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 400 | |
| 401 | |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 402 | if [[ -n "$INSTALL_AS_A_SERVICE" ]] |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 403 | then |
| 404 | echo ' |
| 405 | ################################################################# |
| tierno | 3e9a147 | 2016-09-20 11:05:26 +0000 | [diff] [blame] | 406 | ##### CONFIGURE OPENVIM SERVICE ##### |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 407 | #################################################################' |
| tierno | f7aa8c4 | 2016-09-06 16:43:04 +0200 | [diff] [blame] | 408 | |
| tierno | 36d2263 | 2016-12-16 00:22:32 +0100 | [diff] [blame] | 409 | DELETE_PARAM="" && [[ -z "$NOCLONE" ]] && DELETE_PARAM="-d" |
| 410 | ${OPENVIM_BASEFOLDER}/scripts/install-openvim-service.sh -f ${OPENVIM_BASEFOLDER} ${DELETE_PARAM} |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 411 | # alias service-openvim="service openvim" |
| 412 | # echo 'alias service-openvim="service openvim"' >> ${HOME}/.bashrc |
| 413 | |
| 414 | echo |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 415 | echo |
| 416 | echo "Done! installed at /opt/openvim" |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 417 | echo " Manage server with 'service openvim start|stop|status|...' " |
| 418 | |
| 419 | |
| 420 | else |
| 421 | |
| 422 | echo |
| 423 | echo "Done! you may need to logout and login again for loading client configuration" |
| tierno | 1c84ac0 | 2016-12-07 16:27:21 +0100 | [diff] [blame] | 424 | echo " Run 'service-openvim start' for starting openvim in a screen" |
| tierno | 9a61c6b | 2016-09-08 10:57:02 +0200 | [diff] [blame] | 425 | |
| 426 | fi |