#!/bin/sh # # Installation script for CDR-Stats # # To download official script direct to your server type #wget --no-check-certificate https://github.com/Star2Billing/cdr-stats/raw/master/scripts/install-cdr-stats.sh # Added by alang # Pre-install Notes: # - Checking MySQL is running # - Checking DB name of CDR is asteriskcdrdb # - Checking DB credentials # - Checking Linux Distribution # - Checking SELinux & firewall disabled # # Created by 2011-4-26 # This program support on CentOS 5.8 #Variables #comment out the appropriate line below to install the desired version # # Be sure this URL: https://github.com/Star2Billing/cdr-stats/tarball/$VERSION is available. VERSION=v1.4.0 DATETIME=$(date +"%Y%m%d%H%M%S") KERNELARCH=$(uname -p) #DISTRO='UBUNTU' DISTRO='CENTOS' MYSQLUSER='root' MYSQLPASSWORD='osslab' CDRDB='asteriskcdrdb' # Make sure only root can run our script [ "$(id -u)" != "0" ] && { echo "Abort: This script must be run as root" 1>&2 exit 1 } clear echo "" echo "" echo "This will install CDR-Stats on your server" echo "press any key to continue or CTRL-C to exit" read TEMP # APACHE CONF #APACHE_CONF_DIR="/etc/apache2/sites-enabled/" APACHE_CONF_DIR="/etc/httpd/conf.d/" IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig` IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'` # Disabled SELinux & iptables echo "Disable SELinux & iptables..." setenforce 0 2>/dev/null /etc/init.d/iptables stop #python setup tools echo "Install Dependencies..." case $DISTRO in 'UBUNTU') echo "This installation not support on Ubuntu, aborting the installation..." exit 1 ;; 'CENTOS') # Install EPEP Repo if [ ! -f /etc/yum.repos.d/epel.repo ]; then # Install EPEL Repo cd ~ wget http://download.fedoraproject.org/pub/epel/5/i386/epel-release-5-4.noarch.rpm rpm -ivh epel-release-5-4.noarch.rpm fi #Install Python26 and dependency packages yum -y install python26 python26-devel mysql-devel python26-mod_python #Replace default python with python26 cd /usr/bin mv python python24 ln -s python26 python # fix yum sed -i "s/^\#\!\/usr\/bin\/python/\#\!\/usr\/bin\/python24/" /usr/bin/yum # Install setuptools cd ~ wget http://pypi.python.org/packages/2.6/s/setuptools/setuptools-0.6c11-py2.6.egg#md5=bfa92100bd772d5a213eedd356d64086 sh setuptools-0.6c11-py2.6.egg easy_install mysql-python #install the RPMFORGE Repository if [ ! -f /etc/yum.repos.d/rpmforge.repo ]; then # Install RPMFORGE Repo rpm --import http://apt.sw.be/RPM-GPG-KEY.dag.txt echo ' [rpmforge] name = Red Hat Enterprise $releasever - RPMforge.net - dag mirrorlist = http://apt.sw.be/redhat/el5/en/mirrors-rpmforge enabled = 0 protect = 0 gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag gpgcheck = 1 ' > /etc/yum.repos.d/rpmforge.repo fi yum -y --enablerepo=rpmforge install git-core mercurial #Install PIP easy_install pip ;; esac echo "Install CDR-Stats..." mkdir /usr/share/django_app/ cd /usr/src/ wget --no-check-certificate https://github.com/Star2Billing/cdr-stats/tarball/$VERSION -O cdr-stats-$VERSION.tar.gz mv cdr-stats-$VERSION.tar.gz Star2Billing-cdr-stats-$VERSION.tar.gz tar xvzf Star2Billing-cdr-stats-*.tar.gz rm -rf Star2Billing-cdr-stats-*.tar.gz mv cdr-stats cdr-stats_$DATETIME mv Star2Billing-cdr-stats-* cdr-stats mv /usr/share/django_app/cdr_stats archive_cdr-stats-$DATETIME ln -s /usr/src/cdr-stats/cdr_stats /usr/share/django_app/cdr_stats #Install Cdr-Stats depencencies pip install -r /usr/share/django_app/cdr_stats/requirements.txt # Update Secret Key echo "Update Secret Key..." RANDPASSW=` /dev/null 2>&1 || head -c 50)` sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'$RANDPASSW\'/g" /usr/share/django_app/cdr_stats/settings.py echo "" # Disable Debug sed -i "s/DEBUG = True/DEBUG = False/g" /usr/share/django_app/cdr_stats/settings.py sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g" /usr/share/django_app/cdr_stats/settings.py # Setup settings.py # fix by alang: DB name is asteriskcdrdb sed -i "s/backends.sqlite3/backends.mysql/" /usr/share/django_app/cdr_stats/settings.py sed -i "s/.*'NAME'/ 'NAME': '$CDRDB',#/" /usr/share/django_app/cdr_stats/settings.py sed -i "/'USER'/s/''/'$MYSQLUSER'/" /usr/share/django_app/cdr_stats/settings.py sed -i "/'PASSWORD'/s/''/'$MYSQLPASSWORD'/" /usr/share/django_app/cdr_stats/settings.py sed -i "/'HOST'/s/''/'localhost'/" /usr/share/django_app/cdr_stats/settings.py sed -i "/'PORT'/s/''/'3306'/" /usr/share/django_app/cdr_stats/settings.py # Create the Database echo "Database Creation..." cd /usr/share/django_app/cdr_stats/ #if we use SQLite mkdir database chmod -R 777 database python manage.py syncdb #python manage.py migrate #Collect static files from apps and other locations in a single location. python manage.py collectstatic -l --noinput # prepare Apache echo "Prepare Apache configuration..." # added by alang #case $DISTRO in # 'UBUNTU') # APACHE_USER="www-data" # APACHE_GROUP="www-data" # ;; # 'CENTOS') # APACHE_USER="apache" # APACHE_GROUP="apache" # ;; #esac # fixed by alang echo ' Listen *:9000 DocumentRoot /usr/share/django_app/cdr_stats/ ErrorLog /var/log/err-cdr_stats.log SetHandler mod_python PythonHandler django.core.handlers.modpython PythonPath "[@/usr/share/django_app/cdr_stats/@, @/usr/share/django_app/@] + sys.path" SetEnv DJANGO_SETTINGS_MODULE cdr_stats.settings PythonDebug On SetEnv PYTHON_EGG_CACHE /usr/share/django_app/cdr_stats/.python-eggs SetHandler None ' > $APACHE_CONF_DIR/cdr-stats.conf #correct the above file sed -i "s/@/'/g" $APACHE_CONF_DIR/cdr-stats.conf #Fix permission on python-egg mkdir /usr/share/django_app/cdr_stats/.python-eggs chmod 777 /usr/share/django_app/cdr_stats/.python-eggs case $DISTRO in 'UBUNTU') echo "This installation not support on Ubuntu, aborting the installation..." exit 1 ;; 'CENTOS') service httpd restart chkconfig httpd on ;; esac clear echo "Installation Complete" echo "" echo "" echo "Please log on to CDR-Stats at " echo "http://$IPADDR:9000" echo "the username and password are the ones you entered during this installation." echo "" echo "Thank you for installing CDR-Stats" echo "Yours" echo "The Star2Billing Team" echo "http://www.star2billing.com and http://www.cdr-stats.org/"