Skip to content

Commit

Permalink
work in progress on install script / fix landing page install with nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
areski committed Apr 2, 2015
1 parent b37fcd0 commit abe3577
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 99 deletions.
55 changes: 11 additions & 44 deletions install/bash-common-functions.sh
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

91 changes: 40 additions & 51 deletions install/cdr-stats-functions.sh
Expand Up @@ -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 '
<VirtualHost *:80>
DocumentRoot '$INSTALL_DIR_WELCOME'/
DirectoryIndex index.html index.htm index.php index.php4 index.php5
<Directory '$INSTALL_DIR_WELCOME'>
Options Indexes IncludesNOEXEC FollowSymLinks
allow from all
AllowOverride All
allow from all
</Directory>
</VirtualHost>
' > $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..."
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion install/install-all-cdr-stats-freeswitch.sh
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion install/install-cdr-stats-asterisk.sh
Expand Up @@ -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
2 changes: 1 addition & 1 deletion install/install-cdr-stats-backend.sh
Expand Up @@ -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
2 changes: 1 addition & 1 deletion install/install-cdr-stats.sh
Expand Up @@ -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
Expand Down

0 comments on commit abe3577

Please sign in to comment.