A2Billing_1.8.1 ok

Discussion in 'General' started by anthonyfr, Apr 13, 2011.

  1. anthonyfr

    Joined:
    Nov 9, 2010
    Messages:
    21
    Likes Received:
    0
    #!/bin/sh

    DATETAG=`date +%Y%m%d%H%k%M%S`

    echo "This is the Elastix A2Billing 1.8.0 setup/update script"
    echo ""

    # Step1: Removing A2billing Old files
    rm -f -R /var/www/html/a2billing/
    rm -f -R /var/www/html/a2customer/
    rm -f -R /var/lib/asterisk/agi-bin/a2billing.php
    rm -f -R /var/lib/asterisk/agi-bin/libs_a2billing/
    rm -f -R /var/lib/asterisk/agi-bin/lib/
    rm -f -R /etc/asterisk/additional_a2billing_iax.conf
    rm -f -R /etc/asterisk/additional_a2billing_sip.conf
    rm -f /etc/asterisk/a2billing.conf
    rm -f /etc/a2billing.conf
    rm -f -R /var/www/html/agent/
    rm -f -R /var/www/html/common/
    rm -f -R /usr/src/a2billing/

    # Drop the old database (if it exists)
    mysqladmin drop mya2billing -u root -peLaStIx.2oo7


    # Step2: A2billing installation
    echo " Creating work spaces.."

    cd /usr/src
    mkdir a2billing
    cd a2billing
    wget www.asterisk2billing.org/downloads/A2Bi ... 8.0.tar.gz
    tar -xzf Star2Billing-a2billing-v1.9.3-0-g42cdf0f.tar.gz
    chown -R root:root /usr/src/a2billing

    echo " Building the new database and loading new schemas into it.."

    mysql -u root -peLaStIx.2oo7 < /usr/src/a2billing/DataBase/mysql-5.x/a2billing-createdb-user.sql
    mysql mya2billing -u root -peLaStIx.2oo7 < /usr/src/a2billing/DataBase/mysql-5.x/a2billing-schema-v1.4.0.sql

    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.0-to-v1.4.1.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.1-to-v1.4.2.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.2-to-v1.4.3.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.3-to-v1.4.4.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.4-to-v1.4.4.1.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.4.1-to-v1.4.5.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.4.5-to-v1.5.0.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.5.0-to-v1.5.1.sql
    mysql mya2billing -u root -ppassw0rd </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.5.1-to-v1.6.0.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.6.1-to-v1.6.2.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.6.2-to-v1.7.0.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.7.0-to-v1.7.1.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.7.1-to-v1.7.2.sql
    mysql mya2billing -u root -peLaStIx.2oo7 </usr/src/a2billing/DataBase/mysql-5.x/UPDATE-a2billing-v1.7.2-to-v1.8.0.sql




    echo " Configuring the GUIs and some config files.."

    # Step3: A2billing web interfaces installation
    cp -rf /usr/src/a2billing/customer /var/www/html/a2customer
    chmod 777 /var/www/html/a2customer/templates_c
    cp -rf /usr/src/a2billing/agent /var/www/html
    chmod 777 /var/www/html/agent/templates_c
    cp -rf /usr/src/a2billing/admin /var/www/html/a2billing
    chmod 777 /var/www/html/a2billing/templates_c
    cp -Rf /usr/src/a2billing/common /var/www/html

    cp /usr/src/a2billing/AGI/a2billing.php /var/lib/asterisk/agi-bin/
    cp -rf /usr/src/a2billing/common/lib /var/lib/asterisk/agi-bin/
    chmod +x /var/lib/asterisk/agi-bin/a2billing.php
    chown -R asterisk:asterisk /var/lib/asterisk/agi-bin

    # Step4: A2billing configuration files
    cp /usr/src/a2billing/a2billing.conf /etc/asterisk
    chown asterisk:asterisk /etc/asterisk/a2billing.conf
    ln -sf /etc/asterisk/a2billing.conf /etc/a2billing.conf

    echo "Building the new a2billing.conf.."

    sed -i "s/\(port *= *\)\(.*\)/\13306/" /etc/asterisk/a2billing.conf
    sed -i "s/\(user *= *\)\(.*\)/\1a2billinguser/" /etc/asterisk/a2billing.conf
    sed -i "s/\(password *= *\)\(.*\)/\1a2billing/" /etc/asterisk/a2billing.conf
    sed -i "s/\(dbname *= *\)\(.*\)/\1mya2billing/" /etc/asterisk/a2billing.conf

    echo "Building some Music On Hold mp3 directories and setting privileges.."
    mkdir -p /var/lib/asterisk/mohmp3/acc_1
    mkdir -p /var/lib/asterisk/mohmp3/acc_2
    mkdir -p /var/lib/asterisk/mohmp3/acc_3
    mkdir -p /var/lib/asterisk/mohmp3/acc_4
    mkdir -p /var/lib/asterisk/mohmp3/acc_5
    mkdir -p /var/lib/asterisk/mohmp3/acc_6
    mkdir -p /var/lib/asterisk/mohmp3/acc_7
    mkdir -p /var/lib/asterisk/mohmp3/acc_8
    mkdir -p /var/lib/asterisk/mohmp3/acc_9
    mkdir -p /var/lib/asterisk/mohmp3/acc_10
    chmod 777 /var/lib/asterisk/mohmp3/acc_*
    chown -R asterisk:asterisk /var/lib/asterisk/mohmp3/

    echo "Installing extra sounds..."
    # A2billing Extra sounds
    cd /usr/src/a2billing/addons/sounds
    ./install_a2b_sounds.sh

    echo "Creating additionals_a2billing files.."
    # Step6: Asterisk files
    cd /etc/asterisk/
    touch additional_a2billing_iax.conf
    touch additional_a2billing_sip.conf
    touch extensions_a2billing.conf

    echo "#include additional_a2billing_sip.conf" >> /etc/asterisk/sip_custom.conf
    echo "#include additional_a2billing_iax.conf" >> /etc/asterisk/iax_custom.conf
    echo -e >> /etc/asterisk/extensions_custom.conf
    echo "#include extensions_a2billing.conf" >> /etc/asterisk/extensions_custom.conf

    echo "Settings the rights ..."
    # Step7: A2billing file permissions
    chmod 666 /etc/asterisk/additional_a2billing_iax.conf
    chmod 666 /etc/asterisk/additional_a2billing_sip.conf
    chmod 666 /etc/asterisk/extensions_a2billing.conf
    chown -R asterisk:asterisk /etc/asterisk/
    chown -R asterisk:asterisk /var/www/html/common
    chown -R asterisk:asterisk /var/www/html/a2billing
    chown -R asterisk:asterisk /var/www/html/a2customer
    chown -R asterisk:asterisk /var/www/html/agent
    chown -R asterisk:asterisk /var/lib/asterisk/

    echo"Some changes in extensions_custom.conf..please check it out later.."
    echo '
    [macro-dialout-trunk-predial-hook]
    exten => s,1,GotoIf($["${OUT_${DIAL_TRUNK}:4:4}" = "A2B/"]?custom-freepbx-a2billing,${OUTNUM},1:2)
    exten => s,2,MacroExit

    [custom-freepbx-a2billing]
    exten => _X.,1,DeadAGI(a2billing.php|${OUT_${DIAL_TRUNK}:8})
    exten => _X.,n,Hangup()
    ' >> /etc/asterisk/extensions_custom.conf


    echo " The A2Billing needed new contexts .."
    #Add the A2Billing context

    echo "
    [a2billing]
    exten => _X.,1,Answer
    exten => _X.,n,Wait(1)
    exten => _X.,n,deadAGI(a2billing.php|1)
    exten => _X.,n,Hangup

    [a2billing-callback]
    exten => _X.,1,deadAGI(a2billing.php|1|callback)
    exten => _X.,n,Hangup

    [a2billing-cid-callback]
    exten => _X.,1,deadAGI(a2billing.php|1|cid-callback|34) ;last #parameter is the callback area code
    exten => _X.,n,Hangup

    [a2billing-all-callback]
    exten => _X.,1,deadAGI(a2billing.php|1|all-callback|34) ;last #parameter is the callback area code
    exten => _X.,n,Hangup

    [a2billing-did]
    exten => _X.,1,deadAGI(a2billing.php|1|did)
    exten => _X.,2,Hangup

    [a2billing-voucher]
    exten => _X.,1,deadAGI(a2billing.php|1|voucher)
    exten => _X.,n,Hangup

    [custom-a2billing-did]
    exten => _X.,1,deadAGI(a2billing.php|1|did)
    exten => _X.,2,Hangup

    [custom-a2billing]
    exten => _X.,1,deadAGI(a2billing.php|1)
    exten => _X.,n,Hangup

    " >> /etc/asterisk/extensions_a2billing.conf


    echo " Add some custom destinations to FreePBX. Check it out later too.."
    #Agrega algunos custom destinations a FreePBX
    RESULT=`/usr/bin/mysql -uroot -peLaStIx.2oo7 <<SQL

    use asterisk
    INSERT INTO custom_destinations
    (custom_dest, description, notes)
    VALUES ('custom-a2billing,${EXTEN},1', 'A2Billing', '');
    INSERT INTO custom_destinations
    (custom_dest, description, notes)
    VALUES ('custom-a2billing-did,${EXTEN},1', 'A2Billing-DID', '');
    quit
    SQL`


    echo "
    [myasterisk]
    secret = mycode
    deny=0.0.0.0/0.0.0.0
    permit=127.0.0.1/255.255.255.0
    read = system,call,log,verbose,command,agent,user
    write = system,call,log,verbose,command,agent,user
    " >> /etc/asterisk/manager_custom.conf



    echo" Creating the Cronjobs in /var/spool/cron/asterisk"
    # Cronjobs

    echo "
    # Automatically added for A2Billing
    0 * * * * php /usr/src/a2billing/Cronjobs/a2billing_alarm.php
    0 12 * * * php /usr/src/a2billing/Cronjobs/a2billing_archive_data_cront.php
    0 10 21 * * php /usr/src/a2billing/Cronjobs/a2billing_autorefill.php
    #Batch process at 00:20 each day
    20 0 * * * php /usr/src/a2billing/Cronjobs/a2billing_batch_process.php
    #Bill DID usage at 00:00 each day
    0 0 * * * php /usr/src/a2billing/Cronjobs/a2billing_bill_diduse.php
    #Remind users of low balance every day at 06:00
    0 6 * * * php /usr/src/a2billing/Cronjobs/a2billing_check_account.php
    #Generate Invoices at 7am everyday
    #0 7 * * * php /usr/src/a2billing/Cronjobs/a2billing_invoice2_cront.php
    #0 7 * * * php /usr/src/a2billing/Cronjobs/a2billing_invoice_cront.php
    #Check if balance below preset value, and email user if so.
    1 * * * * php /usr/src/a2billing/Cronjobs/a2billing_notify_account.php
    #Charge subscriptions at 06:05 on the 1st of each month
    0 6 1 * * php /usr/src/a2billing/Cronjobs/a2billing_subscription_fee.php
    #Update currencies at 01:00 each day
    0 1 * * * php /usr/src/a2billing/Cronjobs/currencies_update_yahoo.php
    " >> /var/spool/cron/asterisk


    echo"Creating the log files in /var/log/a2billing.."
    # Create Log Files
    # Log files and Permissions

    mkdir -p /var/log/a2billing

    touch /var/log/asterisk/a2billing-daemon-callback.log
    touch /var/log/a2billing/a2billing-daemon-callback.log
    touch /var/log/a2billing/cront_a2b_alarm.log
    touch /var/log/a2billing/cront_a2b_autorefill.log
    touch /var/log/a2billing/cront_a2b_batch_process.log
    touch /var/log/a2billing/cront_a2b_bill_diduse.log
    touch /var/log/a2billing/cront_a2b_subscription_fee.log
    touch /var/log/a2billing/cront_a2b_currency_update.log
    touch /var/log/a2billing/cront_a2b_invoice.log
    touch /var/log/a2billing/cront_a2b_check_account.log
    touch /var/log/a2billing/a2billing_paypal.log
    touch /var/log/a2billing/a2billing_epayment.log
    touch /var/log/a2billing/api_ecommerce_request.log
    touch /var/log/a2billing/api_callback_request.log
    touch /var/log/a2billing/a2billing_agi.log

    chown asterisk:asterisk /var/log/asterisk/a2billing-daemon-callback.log
    chown -R asterisk:asterisk /var/log/a2billing


    # Set up Callback
    echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
    echo "Now installing callback"
    echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"

    echo "Press any key to continue (presione cualquier tecla para continuar)"
    read any



    LOAD_LOC=/usr/src/a2billing

    echo " Installing python tools and sqlalchemy"
    yum -y install python-setuptools.noarch
    yum -y install MySQL-python
    easy_install sqlalchemy


    cd $LOAD_LOC/CallBack/callback-daemon-py
    cp callback_daemon/a2b-callback-daemon.rc /etc/init.d/a2b-callback-daemon
    chmod +x /etc/init.d/a2b-callback-daemon


    echo "Building the callback_daemon from sources.."
    cp dist/callback_daemon-1.0.prod-r1528.tar.gz /tmp
    cd /tmp
    tar xvfz callback_daemon-1.0.prod-r1528.tar.gz
    cd callback_daemon-1.0.prod-r1528

    python setup.py build
    python setup.py bdist_egg
    easy_install dist/callback_daemon-1.0.prod_r1528-py2.4.egg

    echo "Making a bootable callback-daemon "
    chkconfig --add a2b-callback-daemon
    service a2b-callback-daemon start
    chkconfig a2b-callback-daemon on
     

Share This Page