From abe3577c2aad117583572b2cd8228e6a70c76a6e Mon Sep 17 00:00:00 2001 From: areski Date: Thu, 2 Apr 2015 14:18:10 +0200 Subject: [PATCH] work in progress on install script / fix landing page install with nginx --- install/bash-common-functions.sh | 55 +++---------- install/cdr-stats-functions.sh | 91 +++++++++------------ install/install-all-cdr-stats-freeswitch.sh | 2 +- install/install-cdr-stats-asterisk.sh | 2 +- install/install-cdr-stats-backend.sh | 2 +- install/install-cdr-stats.sh | 2 +- 6 files changed, 55 insertions(+), 99 deletions(-) diff --git a/install/bash-common-functions.sh b/install/bash-common-functions.sh index ba38a53be..72fd4bd6b 100644 --- a/install/bash-common-functions.sh +++ b/install/bash-common-functions.sh @@ -15,51 +15,31 @@ DATETIME=$(date +"%Y%m%d%H%M%S") KERNELARCH=$(uname -p) +SCRIPT_NOTICE="This install script is only intended to run on Debian 7.X" # Identify Linux Distribution type func_identify_os() { - if [ -f /etc/debian_version ] ; then DIST='DEBIAN' - if [ "$(lsb_release -cs)" != "lucid" ] && [ "$(lsb_release -cs)" != "precise" ]; then - echo "This script is only intended to run on Ubuntu LTS 10.04 / 12.04 or CentOS 6.X" + if [ "$(lsb_release -cs)" != "wheezy" ]; then + echo $SCRIPT_NOTICE exit 255 fi elif [ -f /etc/redhat-release ] ; then DIST='CENTOS' - if [ "$(awk '{print $3}' /etc/redhat-release)" != "6.2" ] && [ "$(awk '{print $3}' /etc/redhat-release)" != "6.3" ] && [ "$(awk '{print $3}' /etc/redhat-release)" != "6.4" ] && [ "$(awk '{print $3}' /etc/redhat-release)" != "6.5" ] ; then - echo "This script is only intended to run on Ubuntu LTS 10.04 / 12.04 or CentOS 6.X" + if [ "$(awk '{print $3}' /etc/redhat-release)" != "6.2" ] && [ "$(awk '{print $3}' /etc/redhat-release)" != "6.3" ] && [ "$(awk '{print $3}' /etc/redhat-release)" != "6.4" ] && [ "$(awk '{print $3}' /etc/redhat-release)" != "6.5" ]; then + echo $SCRIPT_NOTICE exit 255 fi else - echo "This script is only intended to run on Ubuntu LTS 10.04 / 12.04 or CentOS 6.X" + echo $SCRIPT_NOTICE exit 1 fi - - #Prepare settings for installation - case $DIST in - 'DEBIAN') - SCRIPT_VIRTUALENVWRAPPER="/usr/local/bin/virtualenvwrapper.sh" - APACHE_CONF_DIR="/etc/apache2/sites-enabled/" - APACHE_USER="www-data" - APACHE_SERVICE='apache2' - WSGI_ADDITIONAL="" - WSGIApplicationGroup="" - ;; - 'CENTOS') - SCRIPT_VIRTUALENVWRAPPER="/usr/bin/virtualenvwrapper.sh" - APACHE_CONF_DIR="/etc/httpd/conf.d/" - APACHE_USER="apache" - APACHE_SERVICE='httpd' - #WSGI_ADDITIONAL="WSGISocketPrefix run/wsgi" - WSGI_ADDITIONAL="WSGISocketPrefix /var/run/wsgi" - WSGIApplicationGroup="WSGIApplicationGroup %{GLOBAL}" - ;; - esac } + #Function mysql db setting func_get_mysql_database_setting() { if mysql -u$MYSQLUSER -p$MYSQLPASSWORD -P$MYHOSTPORT -h$MYHOST $DATABASENAME -e ";" ; then @@ -140,31 +120,18 @@ func_get_mysql_database_setting_asteriskcdrdb() { } -#Function accept license mplv2 -func_accept_license_mplv2() { +#Function accept license +func_accept_license() { echo "" echo "" - echo "CDR-Stats License MPL V2.0" + echo "CDR-Stats License MPL V2.0 (branch:$BRANCH)" echo "Further information at http://www.cdr-stats.org/support/licensing/" echo "" echo "This Source Code Form is subject to the terms of the Mozilla Public" echo "License, v. 2.0. If a copy of the MPL was not distributed with this file," echo "You can obtain one at http://mozilla.org/MPL/2.0/." echo "" - echo "Copyright (C) 2011-2013 Star2Billing S.L." - echo "" + echo "Copyright (C) 2011-2015 Star2Billing S.L." echo "" - echo "I agree to be bound by the terms of the license - [YES/NO]" - echo "" - read ACCEPT - - while [ "$ACCEPT" != "yes" ] && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ] && [ "$ACCEPT" != "no" ] && [ "$ACCEPT" != "No" ] && [ "$ACCEPT" != "NO" ]; do - echo "I agree to be bound by the terms of the license - [YES/NO]" - read ACCEPT - done - if [ "$ACCEPT" != "yes" ] && [ "$ACCEPT" != "Yes" ] && [ "$ACCEPT" != "YES" ]; then - echo "License rejected !" - exit 0 - fi } diff --git a/install/cdr-stats-functions.sh b/install/cdr-stats-functions.sh index ce376ac1d..0c8f10eaf 100755 --- a/install/cdr-stats-functions.sh +++ b/install/cdr-stats-functions.sh @@ -45,39 +45,35 @@ func_identify_os #Function install the landing page func_install_landing_page() { - mkdir -p $INSTALL_DIR_WELCOME + mkdir -p $WELCOME_DIR # Copy files - cp -r /usr/src/cdr-stats/install/landing-page/* $INSTALL_DIR_WELCOME - + cp -r /usr/src/cdr-stats/install/landing-page/* $WELCOME_DIR echo "" - echo "Add Apache configuration for Welcome page..." - echo ' - - DocumentRoot '$INSTALL_DIR_WELCOME'/ - DirectoryIndex index.html index.htm index.php index.php4 index.php5 - - - Options Indexes IncludesNOEXEC FollowSymLinks - allow from all - AllowOverride All - allow from all - - - - - ' > $APACHE_CONF_DIR/welcome-cdr-stats.conf - + echo "Add Nginx configuration for Welcome page..." + cp -rf /usr/src/cdr-stats/install/nginx/global /etc/nginx/ case $DIST in 'DEBIAN') - mv /etc/apache2/sites-enabled/000-default /tmp/ + cp /usr/src/cdr-stats/install/nginx/sites-available/cdr_stats.conf /etc/nginx/sites-available/ + ln -s /etc/nginx/sites-available/cdr_stats.conf /etc/nginx/sites-enabled/cdr_stats.conf + #Remove default NGINX landing page + rm /etc/nginx/sites-enabled/default + ;; + 'CENTOS') + cp /usr/src/cdr-stats/install/nginx/sites-available/cdr_stats.conf /etc/nginx/conf.d/ + rm /etc/nginx/conf.d/default.conf ;; esac - service $APACHE_SERVICE restart + + cp -rf /usr/src/cdr-stats/install/nginx/global /etc/nginx/ + + #Restart Nginx + service nginx restart #Update Welcome page IP - sed -i "s/LOCALHOST/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR_WELCOME/index.html + sed -i "s/LOCALHOST/$IPADDR:$HTTP_PORT/g" $WELCOME_DIR/index.html } + func_check_dependencies() { echo "" echo "Checking Python dependencies..." @@ -317,18 +313,10 @@ func_backup_prev_install(){ mv $INSTALL_DIR /tmp/old-cdr-stats_$DATETIME echo "Files from $INSTALL_DIR has been moved to /tmp/old-cdr-stats_$DATETIME" - if echo $DB_BACKEND | grep -i "^POSTGRESQL" > /dev/null ; then - if [ `sudo -u postgres psql -qAt --list | egrep '^$DATABASENAME\|' | wc -l` -eq 1 ]; then - echo "Run backup with postgresql..." - sudo -u postgres pg_dump $DATABASENAME > /tmp/old-cdr-stats_$DATETIME.pgsqldump.sql - echo "PostgreSQL Dump of database $DATABASENAME added in /tmp/old-cdr-stats_$DATETIME.pgsqldump.sql" - echo "Press Enter to continue" - read TEMP - fi - elif echo $DB_BACKEND | grep -i "^MYSQL" > /dev/null ; then - echo "Run backup with mysqldump..." - mysqldump -u $MYSQLUSER --password=$MYSQLPASSWORD $DATABASENAME > /tmp/old-cdr-stats_$DATETIME.mysqldump.sql - echo "Mysql Dump of database $DATABASENAME added in /tmp/old-cdr-stats_$DATETIME.mysqldump.sql" + if [ `sudo -u postgres psql -qAt --list | egrep '^$DATABASENAME\|' | wc -l` -eq 1 ]; then + echo "Run backup with postgresql..." + sudo -u postgres pg_dump $DATABASENAME > /tmp/old-cdr-stats_$DATETIME.pgsqldump.sql + echo "PostgreSQL Dump of database $DATABASENAME added in /tmp/old-cdr-stats_$DATETIME.pgsqldump.sql" echo "Press Enter to continue" read TEMP fi @@ -344,32 +332,30 @@ func_install_source(){ rm -rf cdr-stats mkdir /var/log/cdr-stats - case $INSTALL_MODE in - 'CLONE') - git clone -b $BRANCH git://github.com/Star2Billing/cdr-stats.git + git clone -b $BRANCH git://github.com/Star2Billing/cdr-stats.git + cd cdr-stats - #Install Develop / Master - if echo $BRANCH | grep -i "^develop" > /dev/null ; then - cd cdr-stats - git checkout -b develop --track origin/develop - fi - ;; - esac + #Install Develop / Master + if echo $BRANCH | grep -i "^develop" > /dev/null ; then + git checkout -b develop --track origin/develop + fi # Copy files cp -r /usr/src/cdr-stats/cdr_stats $INSTALL_DIR } + #Function to install Python dependencies func_install_pip_deps(){ - #Create and enable virtualenv - #We moved this here cause func_setup_virtualenv also active the virtualenv - func_setup_virtualenv + echo "func_install_pip_deps..." + + #Upgrade pip to latest (1.5) + pip install pip --upgrade + + #For python 2.6 only + pip install importlib - #Install CDR-Stats depencencies - easy_install -U distribute - pip install MySQL-python case $DIST in 'DEBIAN') #pip now only installs stable versions by default, so we need to use --pre option @@ -625,6 +611,9 @@ func_install_frontend(){ #Install Code Source func_install_source + #Create and enable virtualenv + func_setup_virtualenv + #Install Pip Dependencies func_install_pip_deps diff --git a/install/install-all-cdr-stats-freeswitch.sh b/install/install-all-cdr-stats-freeswitch.sh index 409fec18b..f248c987b 100755 --- a/install/install-all-cdr-stats-freeswitch.sh +++ b/install/install-all-cdr-stats-freeswitch.sh @@ -103,7 +103,7 @@ source cdr-stats-functions.sh func_identify_os #Request the user to accept the license -func_accept_license_mplv2 +func_accept_license #Install Landing page func_install_landing_page diff --git a/install/install-cdr-stats-asterisk.sh b/install/install-cdr-stats-asterisk.sh index 88a807bba..017f49a43 100755 --- a/install/install-cdr-stats-asterisk.sh +++ b/install/install-cdr-stats-asterisk.sh @@ -49,7 +49,7 @@ source cdr-stats-functions.sh func_identify_os #Request the user to accept the license -func_accept_license_mplv2 +func_accept_license #run install menu run_menu_cdr_stats_install diff --git a/install/install-cdr-stats-backend.sh b/install/install-cdr-stats-backend.sh index 100657d97..0490459af 100755 --- a/install/install-cdr-stats-backend.sh +++ b/install/install-cdr-stats-backend.sh @@ -49,7 +49,7 @@ source cdr-stats-functions.sh func_identify_os #Request the user to accept the license -func_accept_license_mplv2 +func_accept_license #Install Stanalone backend func_install_standalone_backend diff --git a/install/install-cdr-stats.sh b/install/install-cdr-stats.sh index c3cffd730..f4c470a8d 100755 --- a/install/install-cdr-stats.sh +++ b/install/install-cdr-stats.sh @@ -73,7 +73,7 @@ source cdr-stats-functions.sh func_identify_os #Request the user to accept the license -func_accept_license_mplv2 +func_accept_license #run install menu run_menu_cdr_stats_install