remove django-tastypie for install check

#!/bin/bash
#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#

#
# To download and run the script on your server :
#
# >> Install with Master script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/master/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#
# >> Install with develop script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/develop/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#
# >> Install with callcenter script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/callcenter/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#

#Set branch to install develop / master / callcenter
BRANCH="callcenter"

DATETIME=$(date +"%Y%m%d%H%M%S")
INSTALL_DIR='/usr/share/newfies'
LUA_DIR='/usr/share/newfies-lua'
INSTALL_DIR_WELCOME='/var/www/newfies'
DATABASENAME='newfies_dialer_db'
DB_USERSALT=`</dev/urandom tr -dc 0-9| (head -c $1 > /dev/null 2>&1 || head -c 5)`
DB_USERNAME="newfies_dialer_$DB_USERSALT"
DB_PASSWORD=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 20)`
DB_HOSTNAME='localhost'
DB_PORT='5432'
FS_INSTALLED_PATH='/usr/local/freeswitch'
NEWFIES_USER='newfies_dialer'
CELERYD_USER='celery'
CELERYD_GROUP='celery'
NEWFIES_ENV='newfies-dialer'
HTTP_PORT='8008'

#Django bug https://code.djangoproject.com/ticket/16017
export LANG="en_US.UTF-8"

# Identify Linux Distribution type
func_identify_os() {
    if [ -f /etc/debian_version ] ; then
        DIST='DEBIAN'
        if [ "$(lsb_release -cs)" != "precise" ]; then
            echo "This script is only intended to run on Ubuntu LTS 12.04 or CentOS 6.X"
            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" ] ; then
            echo "This script is only intended to run on Ubuntu LTS 12.04 or CentOS 6.X"
            exit 255
        fi
    else
        echo "This script is only intended to run on Ubuntu LTS 12.04 or CentOS 6.X"
        exit 1
    fi
}

#Function accept_license
func_accept_license() {
    clear
    echo ""
    echo "Newfies-Dialer License MPL V2.0"
    echo "Further information at http://www.newfies-dialer.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 ""
    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
}

#Function install the landing page
func_install_landing_page() {
    mkdir -p $INSTALL_DIR_WELCOME
    # Copy files
    cp -r /usr/src/newfies-dialer/install/landing-page/* $INSTALL_DIR_WELCOME
    echo ""
    echo "Add Nginx configuration for Welcome page..."
    cp -rf /usr/src/newfies-dialer/install/nginx/global /etc/nginx/
    case $DIST in
        'DEBIAN')
            cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-available/
            ln -s /etc/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-enabled/newfies_dialer.conf
            #Remove default NGINX landing page
            rm /etc/nginx/sites-enabled/default
        ;;
        'CENTOS')
            cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer.conf /etc/nginx/conf.d/
            rm /etc/nginx/conf.d/default.conf
        ;;
    esac

    cp -rf /usr/src/newfies-dialer/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
}

func_check_dependencies() {
    echo ""
    echo "Checking Python dependencies..."
    echo ""

    #Check South
    grep_pip=`pip freeze| grep South`
    if echo $grep_pip | grep -i "South" > /dev/null ; then
        echo "OK : South installed..."
    else
        echo "Error : South not installed..."
        exit 1
    fi

    #Check Django
    grep_pip=`pip freeze| grep Django`
    if echo $grep_pip | grep -i "Django" > /dev/null ; then
        echo "OK : Django installed..."
    else
        echo "Error : Django not installed..."
        exit 1
    fi

    #Check celery
    grep_pip=`pip freeze| grep celery`
    if echo $grep_pip | grep -i "celery" > /dev/null ; then
        echo "OK : celery installed..."
    else
        echo "Error : celery not installed..."
        exit 1
    fi

    echo ""
    echo "Python dependencies successfully installed!"
    echo ""
}

#Configure Firewall
func_iptables_configuration() {
    #add http port
    iptables -I INPUT 2 -p tcp -m state --state NEW -m tcp --dport $HTTP_PORT -j ACCEPT
    iptables -I INPUT 3 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

    service iptables save
}

#Fuction to create the virtual env
func_setup_virtualenv() {
    echo "This will install virtualenv & virtualenvwrapper"
    echo "and create a new virtualenv : $NEWFIES_ENV"

    pip install virtualenv
    pip install virtualenvwrapper

    #Prepare settings for installation
    case $DIST in
        'DEBIAN')
            SCRIPT_VIRTUALENVWRAPPER="/usr/local/bin/virtualenvwrapper.sh"
        ;;
        'CENTOS')
            SCRIPT_VIRTUALENVWRAPPER="/usr/bin/virtualenvwrapper.sh"
        ;;
    esac

    # Enable virtualenvwrapper
    chk=`grep "virtualenvwrapper" ~/.bashrc|wc -l`
    if [ $chk -lt 1 ] ; then
        echo "Set Virtualenvwrapper into bash"
        echo "export WORKON_HOME=/usr/share/virtualenvs" >> ~/.bashrc
        echo "source $SCRIPT_VIRTUALENVWRAPPER" >> ~/.bashrc
    fi

    # Setup virtualenv
    export WORKON_HOME=/usr/share/virtualenvs
    source $SCRIPT_VIRTUALENVWRAPPER

    mkvirtualenv $NEWFIES_ENV
    workon $NEWFIES_ENV

    echo "Virtualenv $NEWFIES_ENV created and activated"
}

#Function to install Dependencies
func_install_dependencies(){

    #python setup tools
    echo "Install Dependencies and python modules..."

    case $DIST in
        'DEBIAN')
            export LANGUAGE=en_US.UTF-8
            export LANG=en_US.UTF-8
            export LC_ALL=en_US.UTF-8
            locale-gen en_US.UTF-8
            dpkg-reconfigure locales

            apt-get -y install python-software-properties
            add-apt-repository -y ppa:chris-lea/node.js
            apt-get update
            apt-get -y remove apache2.2-common apache2
            apt-get -y install --reinstall language-pack-en

            apt-get -y install python-setuptools python-dev build-essential
            apt-get -y install nginx supervisor
            apt-get -y install git-core mercurial gawk cmake
            apt-get -y install python-pip python-dev
            # for audiofile convertion
            apt-get -y install libsox-fmt-mp3 libsox-fmt-all mpg321 ffmpeg
            # install Node & npm
            apt-get -y install nodejs

            # postgresql
            apt-get -y install postgresql-9.1 postgresql-contrib-9.1
            apt-get -y install libpq-dev
            # start postgresql
            /etc/init.d/postgresql start

            #Lua Deps
            apt-get -y install liblua5.1-sql-postgres-dev
            #needed by lua-curl
            apt-get -y install libcurl4-openssl-dev

            #Memcached
            apt-get -y install memcached
            #Luarocks
            apt-get -y install luarocks luasocket
            luarocks install luasql-postgres PGSQL_INCDIR=/usr/include/postgresql/

        ;;
        'CENTOS')
            yum -y groupinstall "Development Tools"
            yum -y install git sudo cmake
            yum -y install python-setuptools python-tools python-devel mercurial memcached
            yum -y install mlocate vim git wget
            yum -y install policycoreutils-python
            easy_install pip

            #Install Supervisor
            pip install supervisor

            # install Node & npm
            yum -y --enablerepo=epel install npm

            #Audio File Conversion
            yum -y --enablerepo=rpmforge install sox sox-devel ffmpeg ffmpeg-devel mpg123 mpg123-devel libmad libmad-devel libid3tag libid3tag-devel lame lame-devel flac-devel libvorbis-devel
            cd /usr/src/

            #Install SOX for MP3 support
            SOXVERSION=14.4.1
            rm -rf sox
            wget http://switch.dl.sourceforge.net/project/sox/sox/$SOXVERSION/sox-$SOXVERSION.tar.gz
            tar zxf sox-$SOXVERSION.tar.gz
            rm -rf sox-$SOXVERSION.tar.gz
            mv sox-$SOXVERSION sox
            cd sox
            ./configure --bindir=/usr/bin/
            make -s
            make install
            cd /usr/src

            #Install, configure and start nginx
            yum -y install --enablerepo=epel nginx
            chkconfig --levels 235 nginx on
            service nginx start

            #Install & Start PostgreSQL 9.1
            #CentOs
            rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm
            #Redhad
            #rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-redhat91-9.1-5.noarch.rpm
            yum -y install postgresql91-server postgresql91-devel
            chkconfig --levels 235 postgresql-9.1 on
            service postgresql-9.1 initdb
            ln -s /usr/pgsql-9.1/bin/pg_config /usr/bin
            ln -s /var/lib/pgsql/9.1/data /var/lib/pgsql
            ln -s /var/lib/pgsql/9.1/backups /var/lib/pgsql
            sed -i "s/ident/md5/g" /var/lib/pgsql/data/pg_hba.conf
            sed -i "s/ident/md5/g" /var/lib/pgsql/9.1/data/pg_hba.conf
            service postgresql-9.1 restart

            # Install Lua & luarocks
            cd /usr/src
            yum -y install readline-devel
            LUAVERSION=lua-5.1.5
            rm -rf lua
            wget http://www.lua.org/ftp/$LUAVERSION.tar.gz
            tar zxf $LUAVERSION.tar.gz
            rm -rf $LUAVERSION.tar.gz
            mv $LUAVERSION lua
            cd lua
            make linux
            make install
            cd /usr/src

            #Install Luarocks
            cd /usr/src
            LUAROCKSVERSION=luarocks-2.0.12
            rm -rf luarocks
            wget http://luarocks.org/releases/$LUAROCKSVERSION.tar.gz
            tar zxf $LUAROCKSVERSION.tar.gz
            rm -rf $LUAROCKSVERSION.tar.gz
            mv $LUAROCKSVERSION luarocks
            cd luarocks
            ./configure
            make
            make install
            cd /usr/src

            luarocks install luasql-postgres PGSQL_DIR=/usr/pgsql-9.1/
        ;;
    esac

    # install Bower
    npm install -g bower

    #Install Lua dependencies
    luarocks install luasocket
    luarocks install lualogging
    luarocks install loop
    luarocks install md5
    luarocks install luafilesystem
    luarocks install luajson 1.3.2-1
    luarocks install inspect
    luarocks install redis-lua
    luarocks install lua-cmsgpack
    #Issue with last version of lpeg - lua libs/tag_replace.lua will seg fault
    #Pin the version 0.10.2-1
    luarocks remove lpeg --force
    luarocks install http://luarocks.org/repositories/rocks/lpeg-0.10.2-1.rockspec

    #Lua curl
    cd /usr/src/
    rm -rf lua-curl-master
    wget https://github.com/msva/lua-curl/archive/master.zip -O lua-curl.zip
    unzip lua-curl.zip
    cd lua-curl-master
    cmake . && make install
    #add cURL.so to lua libs
    cp cURL.so /usr/local/lib/lua/5.1/

    #Create Newfies User
    echo ""
    echo "Create Newfies-Dialer User/Group : $NEWFIES_USER"
    useradd $NEWFIES_USER --user-group --system --no-create-home
}

#Function to install Python dependencies
func_install_pip_deps(){

    #Install Newfies-Dialer depencencies
    easy_install -U distribute
    #pip now only installs stable versions by default, so we need to use --pre option
    pip install --pre pytz
    #For python 2.6 only
    pip install importlib

    echo "Install basic requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/basic-requirements.txt | grep -v \#)
    do
        pip install $line
    done
    echo "Install Django requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/django-requirements.txt | grep -v \#)
    do
        pip install $line
    done

    #Install Python ESL / this needs to be done within the virtualenv
    cd /usr/src/freeswitch/libs/esl
    make pymod-install

    #Check Python dependencies
    func_check_dependencies

    echo "**********"
    echo "PIP Freeze"
    echo "**********"
    pip freeze
}

#Function to prepare settings_local.py
func_prepare_settings(){

    #Copy settings_local.py into newfies dir
    cp /usr/src/newfies-dialer/install/conf/settings_local.py $INSTALL_DIR

    #Update Secret Key
    echo "Update Secret Key..."
    RANDPASSW=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 50)`
    sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'$RANDPASSW\'/g"  $INSTALL_DIR/settings.py
    echo ""

    #Disable Debug
    sed -i "s/DEBUG = True/DEBUG = False/g"  $INSTALL_DIR/settings_local.py
    sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g"  $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/DATABASENAME/$DATABASENAME/"  $INSTALL_DIR/settings_local.py
    sed -i "s/DB_USERNAME/$DB_USERNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PASSWORD/$DB_PASSWORD/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_HOSTNAME/$DB_HOSTNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PORT/$DB_PORT/" $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/newfiesdb/$DATABASENAME/"  $LUA_DIR/libs/settings.lua
    sed -i "s/newfiesuser/$DB_USERNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/password/$DB_PASSWORD/" $LUA_DIR/libs/settings.lua
    sed -i "s/127.0.0.1/$DB_HOSTNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/5432/$DB_PORT/" $LUA_DIR/libs/settings.lua

    #ODBC
    cp /usr/src/newfies-dialer/install/odbc/odbc.ini /etc/odbc.ini
    #Setup odbc.ini for POSTGRESQL
    sed -i "s/DATABASENAME/$DATABASENAME/" /etc/odbc.ini
    sed -i "s/DB_USERNAME/$DB_USERNAME/" /etc/odbc.ini
    sed -i "s/DB_PASSWORD/$DB_PASSWORD/" /etc/odbc.ini
    sed -i "s/DB_HOSTNAME/$DB_HOSTNAME/" /etc/odbc.ini
    sed -i "s/DB_PORT/$DB_PORT/" /etc/odbc.ini

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "We have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    ##Update Freeswitch XML CDR
    #NEWFIES_CDR_API='api\/v1\/store_cdr\/'
    #CDR_API_URL="http:\/\/$IPADDR:$HTTP_PORT\/$NEWFIES_CDR_API"
    #cd "$FS_INSTALLED_PATH/conf/autoload_configs/"
    #sed -i "s/NEWFIES_API_STORE_CDR/$CDR_API_URL/g" xml_cdr.conf.xml
    #
    ##Update API username and password
    #sed -i "s/APIUSERNAME/$APIUSERNAME/g" xml_cdr.conf.xml
    #sed -i "s/APIPASSWORD/$APIPASSWORD/g" xml_cdr.conf.xml

    #Update Authorize local IP
    sed -i "s/SERVER_IP_PORT/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR/settings_local.py
    sed -i "s/#'SERVER_IP',/'$IPADDR',/g" $INSTALL_DIR/settings_local.py
    sed -i "s/SERVER_IP/$IPADDR/g" $INSTALL_DIR/settings_local.py

    case $DIST in
        'DEBIAN')
            #Get TZ
            ZONE=$(head -1 /etc/timezone)
        ;;
        'CENTOS')
            #Get TZ
            . /etc/sysconfig/clock
            echo ""
            echo "We will now add port $HTTP_PORT  and port 80 to your Firewall"
            echo "Press Enter to continue or CTRL-C to exit"
            read TEMP

            func_iptables_configuration

            #Selinux to allow apache to access this directory
            chcon -Rv --type=httpd_sys_content_t /usr/share/virtualenvs/newfies-dialer/
            chcon -Rv --type=httpd_sys_content_t /usr/share/newfies/usermedia
            semanage port -a -t http_port_t -p tcp $HTTP_PORT
            #Allowing Apache to access Redis port
            semanage port -a -t http_port_t -p tcp 6379
        ;;
    esac

    #Set Timezone in settings_local.py
    sed -i "s@Europe/Madrid@$ZONE@g" $INSTALL_DIR/settings_local.py
}

#Configure Logs files and logrotate
func_prepare_logger() {

    #Following lines is for apache logs
    touch /var/log/newfies/newfies-django.log
    touch /var/log/newfies/newfies-django-db.log
    touch /var/log/newfies/gunicorn_newfies_dialer.log
    chown -R $NEWFIES_USER:$NEWFIES_USER /var/log/newfies

    echo "Install Logrotate..."
    # First delete to avoid error when running the script several times.
    rm /etc/logrotate.d/newfies_dialer
    touch /etc/logrotate.d/newfies_dialer
    echo '
    /var/log/newfies/*.log {
        daily
        rotate 10
        size = 50M
        missingok
        compress
    }
    '  >> /etc/logrotate.d/newfies_dialer

    logrotate /etc/logrotate.d/newfies_dialer
}

#function to get the source of Newfies
func_install_source(){

    #get Newfies-Dialer
    echo "Install Newfies-Dialer..."
    cd /usr/src/
    rm -rf newfies-dialer
    mkdir /var/log/newfies

    git clone git://github.com/Star2Billing/newfies-dialer.git
    cd newfies-dialer

    #Install branch develop / callcenter
    if echo $BRANCH | grep -i "^develop" > /dev/null ; then
        git checkout -b develop --track origin/develop
    fi
    if echo $BRANCH | grep -i "^callcenter" > /dev/null ; then
        git checkout -b callcenter --track origin/callcenter
    fi

    #Copy files
    cp -r /usr/src/newfies-dialer/newfies $INSTALL_DIR
    cp -r /usr/src/newfies-dialer/lua $LUA_DIR
    cd $LUA_DIR/libs/
    wget --no-check-certificate https://raw.github.com/areski/lua-acapela/$BRANCH/acapela.lua

    #Upload audio files
    mkdir -p /usr/share/newfies/usermedia/upload/audiofiles
    chown -R $NEWFIES_USER:$NEWFIES_USER /usr/share/newfies/usermedia
}

#Create PGSQL
func_create_pgsql_database(){

    # Create the Database
    echo "We will remove existing Database"
    echo "Press Enter to continue"
    read TEMP
    echo "sudo -u postgres dropdb $DATABASENAME"
    sudo -u postgres dropdb $DATABASENAME
    # echo "Remove Existing Database if exists..."
    #if [ `sudo -u postgres psql -qAt --list | egrep $DATABASENAME | wc -l` -eq 1 ]; then
    #     echo "sudo -u postgres dropdb $DATABASENAME"
    #     sudo -u postgres dropdb $DATABASENAME
    # fi
    echo "Create Database..."
    echo "sudo -u postgres createdb $DATABASENAME"
    sudo -u postgres createdb $DATABASENAME

    #CREATE ROLE / USER
    echo "Create Postgresql user $DB_USERNAME"
    #echo "sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME"
    #sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME
    echo "sudo -u postgres psql --command=\"create user $DB_USERNAME with password 'XXXXXXXXXXXX';\""
    sudo -u postgres psql --command="CREATE USER $DB_USERNAME with password '$DB_PASSWORD';"

    echo "Grant all privileges to user..."
    sudo -u postgres psql --command="GRANT ALL PRIVILEGES on database $DATABASENAME to $DB_USERNAME;"
}

#NGINX / SUPERVISOR
func_config_start_nginx_supervisor(){
    #Configure and Start supervisor
    case $DIST in
        'DEBIAN')
            cp /usr/src/newfies-dialer/install/supervisor/gunicorn_newfies_dialer.conf /etc/supervisor/conf.d/
        ;;
        'CENTOS')
            cp /usr/src/newfies-dialer/install/supervisor/supervisord /etc/init.d/supervisor
            chmod +x /etc/rc.d/init.d/supervisor
            chkconfig --levels 235 supervisor on
            echo_supervisord_conf > /etc/supervisord.conf
            cat /usr/src/newfies-dialer/install/supervisor/gunicorn_newfies_dialer.conf >> /etc/supervisord.conf
            mkdir /var/log/supervisor/
        ;;
    esac
    /etc/init.d/supervisor force-stop
    /etc/init.d/supervisor start
}

#Function to install Frontend
func_install_frontend(){

    echo ""
    echo ""
    echo "This script will install Newfies-Dialer"
    echo "======================================="
    echo ""

    if [ -d "$INSTALL_DIR" ]; then
        # Newfies-Dialer is already installed
        clear
        echo ""
        echo "We detect an existing Newfies-Dialer Installation"
        echo "if you continue the existing installation will be removed!"
        echo ""
        echo "Press Enter to continue or CTRL-C to exit"
        read TEMP

        mkdir /tmp/old-newfies-dialer_$DATETIME
        mv $INSTALL_DIR /tmp/old-newfies-dialer_$DATETIME
        mkdir /tmp/old-lua-newfies-dialer_$DATETIME
        mv $LUA_DIR /tmp/old-lua-newfies-dialer_$DATETIME
        echo "Files from $INSTALL_DIR has been moved to /tmp/old-newfies-dialer_$DATETIME and /tmp/old-lua-newfies-dialer_$DATETIME"

        if [ `sudo -u postgres psql -qAt --list | egrep '^$DATABASENAME\|' | wc -l` -eq 1 ]; then
            echo ""
            echo "Run backup with postgresql..."
            sudo -u postgres pg_dump $DATABASENAME > /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql
            echo "PostgreSQL Dump of database $DATABASENAME added in /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql"
            echo "Press Enter to continue"
            read TEMP
        fi
    fi

    #Install Depedencies
    func_install_dependencies

    #Install Celery & redis-server
    func_install_redis_server

    #Create and enable virtualenv
    func_setup_virtualenv

    #Install Code Source
    func_install_source

    #Install PIP dependencies
    func_install_pip_deps

    #Prepare the settings
    func_prepare_settings

    func_create_pgsql_database

    #Prepare Django DB / Migrate / Create User ...
    cd $INSTALL_DIR/
    python manage.py syncdb --noinput
    python manage.py migrate

    #Load Countries Dialcode
    #python manage.py load_country_dialcode
    wget https://raw.github.com/areski/django-sms-gateway/master/sms/fixtures/example_gateways.json
    python manage.py loaddata example_gateways.json
    rm example_gateways.json

    clear
    echo ""
    echo "Create a super admin user..."
    python manage.py createsuperuser

    echo "Install Bower deps"
    python manage.py bower_install -- --allow-root

    echo "Collects the static files"
    python manage.py collectstatic --noinput

    #NGINX / SUPERVISOR
    func_config_start_nginx_supervisor

    # * * LOGROTATE * *
    func_prepare_logger

    echo ""
    echo "*****************************************************************"
    echo "Congratulations, Newfies-Dialer Web Application is now installed!"
    echo "*****************************************************************"
    echo ""
    echo "Please log on to Newfies-Dialer at "
    echo "http://$IPADDR:$HTTP_PORT"
    echo "the username and password are the ones you entered during this installation."
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Function to install backend
func_install_backend() {
    echo ""
    echo ""
    echo "This will install Newfies-Dialer Backend, Celery & Redis on your server"
    echo "Press Enter to continue or CTRL-C to exit"
    read TEMP

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "we have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    #Create directory for pid file
    mkdir -p /var/run/celery

    #Install Celery & redis-server
    func_install_redis_server

    #Memcache installation
    #pip install python-memcached

    echo "Configure Celery..."
    case $DIST in
        'DEBIAN')
            # Add init-scripts
            cp /usr/src/newfies-dialer/install/celery-init/debian/etc/default/newfies-celeryd /etc/default/
            cp /usr/src/newfies-dialer/install/celery-init/debian/etc/init.d/newfies-celeryd /etc/init.d/
            # Configure init-scripts
            sed -i "s/CELERYD_USER='celery'/CELERYD_USER='$CELERYD_USER'/g"  /etc/default/newfies-celeryd
            sed -i "s/CELERYD_GROUP='celery'/CELERYD_GROUP='$CELERYD_GROUP'/g"  /etc/default/newfies-celeryd
            chmod +x /etc/default/newfies-celeryd
            chmod +x /etc/init.d/newfies-celeryd

            /etc/init.d/newfies-celeryd restart
            cd /etc/init.d; update-rc.d newfies-celeryd defaults 99

            #Check permissions on /dev/shm to ensure that celery can start and run for openVZ.
            DIR="/dev/shm"
            echo "Checking the permissions for $dir"
            stat $DIR
            if [ `stat -c "%a" $DIR` -ge 777 ] ; then
                echo "$DIR has Read Write permissions."
            else
                echo "$DIR has no read write permissions."
                chmod -R 777 /dev/shm
                if [ `grep -i /dev/shm /etc/fstab | wc -l` -eq 0 ]; then
                    echo "Adding fstab entry to set permissions /dev/shm"
                    echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> /etc/fstab
                fi
            fi
        ;;
        'CENTOS')
            # Add init-scripts
            cp /usr/src/newfies-dialer/install/celery-init/centos/etc/default/newfies-celeryd /etc/default/
            cp /usr/src/newfies-dialer/install/celery-init/centos/etc/init.d/newfies-celeryd /etc/init.d/
            # Configure init-scripts
            sed -i "s/CELERYD_USER='celery'/CELERYD_USER='$CELERYD_USER'/g"  /etc/default/newfies-celeryd
            sed -i "s/CELERYD_GROUP='celery'/CELERYD_GROUP='$CELERYD_GROUP'/g"  /etc/default/newfies-celeryd

            chmod +x /etc/init.d/newfies-celeryd
            /etc/init.d/newfies-celeryd restart

            chkconfig --add newfies-celeryd
            chkconfig --level 2345 newfies-celeryd on
        ;;
    esac

    #Install Python ESL / those lines doesn't work in install-freeswitch.sh
    cd /usr/src/freeswitch/libs/esl
    make pymod-install

    #Restart FreeSWITCH to find the startup-script
    /etc/init.d/freeswitch restart

    echo ""
    echo "**************************************************************"
    echo "Congratulations, Newfies-Dialer Backend is now installed!"
    echo "**************************************************************"
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Install recent version of redis-server
func_install_redis_server() {
    echo "Install Redis-server ..."
    case $DIST in
        'DEBIAN')
            apt-get -y install redis-server
            /etc/init.d/redis-server restart
        ;;
        'CENTOS')
            yum -y --enablerepo=epel install redis
            chkconfig --add redis
            chkconfig --level 2345 redis on
            /etc/init.d/redis start
        ;;
    esac
}

#!/bin/bash
#
# Newfies-Dialer License
# http://www.newfies-dialer.org
#
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.
#
# Copyright (C) 2011-2013 Star2Billing S.L.
#
# The Initial Developer of the Original Code is
# Arezqui Belaid <info@star2billing.com>
#

#
# To download and run the script on your server :
#
# >> Install with Master script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/master/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#
# >> Install with develop script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/develop/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#
# >> Install with callcenter script :
# cd /usr/src/ ; rm install-newfies.sh ; wget --no-check-certificate https://raw.github.com/Star2Billing/newfies-dialer/callcenter/install/install-newfies.sh ; chmod +x install-newfies.sh ; ./install-newfies.sh
#

#Set branch to install develop / master / callcenter
BRANCH="callcenter"

DATETIME=$(date +"%Y%m%d%H%M%S")
INSTALL_DIR='/usr/share/newfies'
LUA_DIR='/usr/share/newfies-lua'
INSTALL_DIR_WELCOME='/var/www/newfies'
DATABASENAME='newfies_dialer_db'
DB_USERSALT=`</dev/urandom tr -dc 0-9| (head -c $1 > /dev/null 2>&1 || head -c 5)`
DB_USERNAME="newfies_dialer_$DB_USERSALT"
DB_PASSWORD=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 20)`
DB_HOSTNAME='localhost'
DB_PORT='5432'
FS_INSTALLED_PATH='/usr/local/freeswitch'
NEWFIES_USER='newfies_dialer'
CELERYD_USER='celery'
CELERYD_GROUP='celery'
NEWFIES_ENV='newfies-dialer'
HTTP_PORT='8008'

#Django bug https://code.djangoproject.com/ticket/16017
export LANG="en_US.UTF-8"

# Identify Linux Distribution type
func_identify_os() {
    if [ -f /etc/debian_version ] ; then
        DIST='DEBIAN'
        if [ "$(lsb_release -cs)" != "precise" ]; then
            echo "This script is only intended to run on Ubuntu LTS 12.04 or CentOS 6.X"
            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" ] ; then
            echo "This script is only intended to run on Ubuntu LTS 12.04 or CentOS 6.X"
            exit 255
        fi
    else
        echo "This script is only intended to run on Ubuntu LTS 12.04 or CentOS 6.X"
        exit 1
    fi
}

#Function accept_license
func_accept_license() {
    clear
    echo ""
    echo "Newfies-Dialer License MPL V2.0"
    echo "Further information at http://www.newfies-dialer.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 ""
    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
}

#Function install the landing page
func_install_landing_page() {
    mkdir -p $INSTALL_DIR_WELCOME
    # Copy files
    cp -r /usr/src/newfies-dialer/install/landing-page/* $INSTALL_DIR_WELCOME
    echo ""
    echo "Add Nginx configuration for Welcome page..."
    cp -rf /usr/src/newfies-dialer/install/nginx/global /etc/nginx/
    case $DIST in
        'DEBIAN')
            cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-available/
            ln -s /etc/nginx/sites-available/newfies_dialer.conf /etc/nginx/sites-enabled/newfies_dialer.conf
            #Remove default NGINX landing page
            rm /etc/nginx/sites-enabled/default
        ;;
        'CENTOS')
            cp /usr/src/newfies-dialer/install/nginx/sites-available/newfies_dialer.conf /etc/nginx/conf.d/
            rm /etc/nginx/conf.d/default.conf
        ;;
    esac

    cp -rf /usr/src/newfies-dialer/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
}

func_check_dependencies() {
    echo ""
    echo "Checking Python dependencies..."
    echo ""

    #Check South
    grep_pip=`pip freeze| grep South`
    if echo $grep_pip | grep -i "South" > /dev/null ; then
        echo "OK : South installed..."
    else
        echo "Error : South not installed..."
        exit 1
    fi

    #Check Django
    grep_pip=`pip freeze| grep Django`
    if echo $grep_pip | grep -i "Django" > /dev/null ; then
        echo "OK : Django installed..."
    else
        echo "Error : Django not installed..."
        exit 1
    fi

    #Check celery
    grep_pip=`pip freeze| grep celery`
    if echo $grep_pip | grep -i "celery" > /dev/null ; then
        echo "OK : celery installed..."
    else
        echo "Error : celery not installed..."
        exit 1
    fi

    #Check django-tastypie
    grep_pip=`pip freeze| grep django-tastypie`
    if echo $grep_pip | grep -i "django-tastypie" > /dev/null ; then
        echo "OK : django-tastypie installed..."
    else
        echo "Error : django-tastypie not installed..."
        exit 1
    fi

    echo ""
    echo "Python dependencies successfully installed!"
    echo ""
}

#Configure Firewall
func_iptables_configuration() {
    #add http port
    iptables -I INPUT 2 -p tcp -m state --state NEW -m tcp --dport $HTTP_PORT -j ACCEPT
    iptables -I INPUT 3 -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT

    service iptables save
}

#Fuction to create the virtual env
func_setup_virtualenv() {
    echo "This will install virtualenv & virtualenvwrapper"
    echo "and create a new virtualenv : $NEWFIES_ENV"

    pip install virtualenv
    pip install virtualenvwrapper

    #Prepare settings for installation
    case $DIST in
        'DEBIAN')
            SCRIPT_VIRTUALENVWRAPPER="/usr/local/bin/virtualenvwrapper.sh"
        ;;
        'CENTOS')
            SCRIPT_VIRTUALENVWRAPPER="/usr/bin/virtualenvwrapper.sh"
        ;;
    esac

    # Enable virtualenvwrapper
    chk=`grep "virtualenvwrapper" ~/.bashrc|wc -l`
    if [ $chk -lt 1 ] ; then
        echo "Set Virtualenvwrapper into bash"
        echo "export WORKON_HOME=/usr/share/virtualenvs" >> ~/.bashrc
        echo "source $SCRIPT_VIRTUALENVWRAPPER" >> ~/.bashrc
    fi

    # Setup virtualenv
    export WORKON_HOME=/usr/share/virtualenvs
    source $SCRIPT_VIRTUALENVWRAPPER

    mkvirtualenv $NEWFIES_ENV
    workon $NEWFIES_ENV

    echo "Virtualenv $NEWFIES_ENV created and activated"
}

#Function to install Dependencies
func_install_dependencies(){

    #python setup tools
    echo "Install Dependencies and python modules..."

    case $DIST in
        'DEBIAN')
            export LANGUAGE=en_US.UTF-8
            export LANG=en_US.UTF-8
            export LC_ALL=en_US.UTF-8
            locale-gen en_US.UTF-8
            dpkg-reconfigure locales

            apt-get -y install python-software-properties
            add-apt-repository -y ppa:chris-lea/node.js
            apt-get update
            apt-get -y remove apache2.2-common apache2
            apt-get -y install --reinstall language-pack-en

            apt-get -y install python-setuptools python-dev build-essential
            apt-get -y install nginx supervisor
            apt-get -y install git-core mercurial gawk cmake
            apt-get -y install python-pip python-dev
            # for audiofile convertion
            apt-get -y install libsox-fmt-mp3 libsox-fmt-all mpg321 ffmpeg
            # install Node & npm
            apt-get -y install nodejs

            # postgresql
            apt-get -y install postgresql-9.1 postgresql-contrib-9.1
            apt-get -y install libpq-dev
            # start postgresql
            /etc/init.d/postgresql start

            #Lua Deps
            apt-get -y install liblua5.1-sql-postgres-dev
            #needed by lua-curl
            apt-get -y install libcurl4-openssl-dev

            #Memcached
            apt-get -y install memcached
            #Luarocks
            apt-get -y install luarocks luasocket
            luarocks install luasql-postgres PGSQL_INCDIR=/usr/include/postgresql/

        ;;
        'CENTOS')
            yum -y groupinstall "Development Tools"
            yum -y install git sudo cmake
            yum -y install python-setuptools python-tools python-devel mercurial memcached
            yum -y install mlocate vim git wget
            yum -y install policycoreutils-python
            easy_install pip

            #Install Supervisor
            pip install supervisor

            # install Node & npm
            yum -y --enablerepo=epel install npm

            #Audio File Conversion
            yum -y --enablerepo=rpmforge install sox sox-devel ffmpeg ffmpeg-devel mpg123 mpg123-devel libmad libmad-devel libid3tag libid3tag-devel lame lame-devel flac-devel libvorbis-devel
            cd /usr/src/

            #Install SOX for MP3 support
            SOXVERSION=14.4.1
            rm -rf sox
            wget http://switch.dl.sourceforge.net/project/sox/sox/$SOXVERSION/sox-$SOXVERSION.tar.gz
            tar zxf sox-$SOXVERSION.tar.gz
            rm -rf sox-$SOXVERSION.tar.gz
            mv sox-$SOXVERSION sox
            cd sox
            ./configure --bindir=/usr/bin/
            make -s
            make install
            cd /usr/src

            #Install, configure and start nginx
            yum -y install --enablerepo=epel nginx
            chkconfig --levels 235 nginx on
            service nginx start

            #Install & Start PostgreSQL 9.1
            #CentOs
            rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-centos91-9.1-4.noarch.rpm
            #Redhad
            #rpm -ivh http://yum.pgrpms.org/9.1/redhat/rhel-6-x86_64/pgdg-redhat91-9.1-5.noarch.rpm
            yum -y install postgresql91-server postgresql91-devel
            chkconfig --levels 235 postgresql-9.1 on
            service postgresql-9.1 initdb
            ln -s /usr/pgsql-9.1/bin/pg_config /usr/bin
            ln -s /var/lib/pgsql/9.1/data /var/lib/pgsql
            ln -s /var/lib/pgsql/9.1/backups /var/lib/pgsql
            sed -i "s/ident/md5/g" /var/lib/pgsql/data/pg_hba.conf
            sed -i "s/ident/md5/g" /var/lib/pgsql/9.1/data/pg_hba.conf
            service postgresql-9.1 restart

            # Install Lua & luarocks
            cd /usr/src
            yum -y install readline-devel
            LUAVERSION=lua-5.1.5
            rm -rf lua
            wget http://www.lua.org/ftp/$LUAVERSION.tar.gz
            tar zxf $LUAVERSION.tar.gz
            rm -rf $LUAVERSION.tar.gz
            mv $LUAVERSION lua
            cd lua
            make linux
            make install
            cd /usr/src

            #Install Luarocks
            cd /usr/src
            LUAROCKSVERSION=luarocks-2.0.12
            rm -rf luarocks
            wget http://luarocks.org/releases/$LUAROCKSVERSION.tar.gz
            tar zxf $LUAROCKSVERSION.tar.gz
            rm -rf $LUAROCKSVERSION.tar.gz
            mv $LUAROCKSVERSION luarocks
            cd luarocks
            ./configure
            make
            make install
            cd /usr/src

            luarocks install luasql-postgres PGSQL_DIR=/usr/pgsql-9.1/
        ;;
    esac

    # install Bower
    npm install -g bower

    #Install Lua dependencies
    luarocks install luasocket
    luarocks install lualogging
    luarocks install loop
    luarocks install md5
    luarocks install luafilesystem
    luarocks install luajson 1.3.2-1
    luarocks install inspect
    luarocks install redis-lua
    luarocks install lua-cmsgpack
    #Issue with last version of lpeg - lua libs/tag_replace.lua will seg fault
    #Pin the version 0.10.2-1
    luarocks remove lpeg --force
    luarocks install http://luarocks.org/repositories/rocks/lpeg-0.10.2-1.rockspec

    #Lua curl
    cd /usr/src/
    rm -rf lua-curl-master
    wget https://github.com/msva/lua-curl/archive/master.zip -O lua-curl.zip
    unzip lua-curl.zip
    cd lua-curl-master
    cmake . && make install
    #add cURL.so to lua libs
    cp cURL.so /usr/local/lib/lua/5.1/

    #Create Newfies User
    echo ""
    echo "Create Newfies-Dialer User/Group : $NEWFIES_USER"
    useradd $NEWFIES_USER --user-group --system --no-create-home
}

#Function to install Python dependencies
func_install_pip_deps(){

    #Install Newfies-Dialer depencencies
    easy_install -U distribute
    #pip now only installs stable versions by default, so we need to use --pre option
    pip install --pre pytz
    #For python 2.6 only
    pip install importlib

    echo "Install basic requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/basic-requirements.txt | grep -v \#)
    do
        pip install $line
    done
    echo "Install Django requirements..."
    for line in $(cat /usr/src/newfies-dialer/install/requirements/django-requirements.txt | grep -v \#)
    do
        pip install $line
    done

    #Install Python ESL / this needs to be done within the virtualenv
    cd /usr/src/freeswitch/libs/esl
    make pymod-install

    #Check Python dependencies
    func_check_dependencies

    echo "**********"
    echo "PIP Freeze"
    echo "**********"
    pip freeze
}

#Function to prepare settings_local.py
func_prepare_settings(){

    #Copy settings_local.py into newfies dir
    cp /usr/src/newfies-dialer/install/conf/settings_local.py $INSTALL_DIR

    #Update Secret Key
    echo "Update Secret Key..."
    RANDPASSW=`</dev/urandom tr -dc A-Za-z0-9| (head -c $1 > /dev/null 2>&1 || head -c 50)`
    sed -i "s/^SECRET_KEY.*/SECRET_KEY = \'$RANDPASSW\'/g"  $INSTALL_DIR/settings.py
    echo ""

    #Disable Debug
    sed -i "s/DEBUG = True/DEBUG = False/g"  $INSTALL_DIR/settings_local.py
    sed -i "s/TEMPLATE_DEBUG = DEBUG/TEMPLATE_DEBUG = False/g"  $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/DATABASENAME/$DATABASENAME/"  $INSTALL_DIR/settings_local.py
    sed -i "s/DB_USERNAME/$DB_USERNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PASSWORD/$DB_PASSWORD/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_HOSTNAME/$DB_HOSTNAME/" $INSTALL_DIR/settings_local.py
    sed -i "s/DB_PORT/$DB_PORT/" $INSTALL_DIR/settings_local.py

    #Setup settings_local.py for POSTGRESQL
    sed -i "s/newfiesdb/$DATABASENAME/"  $LUA_DIR/libs/settings.lua
    sed -i "s/newfiesuser/$DB_USERNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/password/$DB_PASSWORD/" $LUA_DIR/libs/settings.lua
    sed -i "s/127.0.0.1/$DB_HOSTNAME/" $LUA_DIR/libs/settings.lua
    sed -i "s/5432/$DB_PORT/" $LUA_DIR/libs/settings.lua

    #ODBC
    cp /usr/src/newfies-dialer/install/odbc/odbc.ini /etc/odbc.ini
    #Setup odbc.ini for POSTGRESQL
    sed -i "s/DATABASENAME/$DATABASENAME/" /etc/odbc.ini
    sed -i "s/DB_USERNAME/$DB_USERNAME/" /etc/odbc.ini
    sed -i "s/DB_PASSWORD/$DB_PASSWORD/" /etc/odbc.ini
    sed -i "s/DB_HOSTNAME/$DB_HOSTNAME/" /etc/odbc.ini
    sed -i "s/DB_PORT/$DB_PORT/" /etc/odbc.ini

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "We have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    ##Update Freeswitch XML CDR
    #NEWFIES_CDR_API='api\/v1\/store_cdr\/'
    #CDR_API_URL="http:\/\/$IPADDR:$HTTP_PORT\/$NEWFIES_CDR_API"
    #cd "$FS_INSTALLED_PATH/conf/autoload_configs/"
    #sed -i "s/NEWFIES_API_STORE_CDR/$CDR_API_URL/g" xml_cdr.conf.xml
    #
    ##Update API username and password
    #sed -i "s/APIUSERNAME/$APIUSERNAME/g" xml_cdr.conf.xml
    #sed -i "s/APIPASSWORD/$APIPASSWORD/g" xml_cdr.conf.xml

    #Update Authorize local IP
    sed -i "s/SERVER_IP_PORT/$IPADDR:$HTTP_PORT/g" $INSTALL_DIR/settings_local.py
    sed -i "s/#'SERVER_IP',/'$IPADDR',/g" $INSTALL_DIR/settings_local.py
    sed -i "s/SERVER_IP/$IPADDR/g" $INSTALL_DIR/settings_local.py

    case $DIST in
        'DEBIAN')
            #Get TZ
            ZONE=$(head -1 /etc/timezone)
        ;;
        'CENTOS')
            #Get TZ
            . /etc/sysconfig/clock
            echo ""
            echo "We will now add port $HTTP_PORT  and port 80 to your Firewall"
            echo "Press Enter to continue or CTRL-C to exit"
            read TEMP

            func_iptables_configuration

            #Selinux to allow apache to access this directory
            chcon -Rv --type=httpd_sys_content_t /usr/share/virtualenvs/newfies-dialer/
            chcon -Rv --type=httpd_sys_content_t /usr/share/newfies/usermedia
            semanage port -a -t http_port_t -p tcp $HTTP_PORT
            #Allowing Apache to access Redis port
            semanage port -a -t http_port_t -p tcp 6379
        ;;
    esac

    #Set Timezone in settings_local.py
    sed -i "s@Europe/Madrid@$ZONE@g" $INSTALL_DIR/settings_local.py
}

#Configure Logs files and logrotate
func_prepare_logger() {

    #Following lines is for apache logs
    touch /var/log/newfies/newfies-django.log
    touch /var/log/newfies/newfies-django-db.log
    touch /var/log/newfies/gunicorn_newfies_dialer.log
    chown -R $NEWFIES_USER:$NEWFIES_USER /var/log/newfies

    echo "Install Logrotate..."
    # First delete to avoid error when running the script several times.
    rm /etc/logrotate.d/newfies_dialer
    touch /etc/logrotate.d/newfies_dialer
    echo '
    /var/log/newfies/*.log {
        daily
        rotate 10
        size = 50M
        missingok
        compress
    }
    '  >> /etc/logrotate.d/newfies_dialer

    logrotate /etc/logrotate.d/newfies_dialer
}

#function to get the source of Newfies
func_install_source(){

    #get Newfies-Dialer
    echo "Install Newfies-Dialer..."
    cd /usr/src/
    rm -rf newfies-dialer
    mkdir /var/log/newfies

    git clone git://github.com/Star2Billing/newfies-dialer.git
    cd newfies-dialer

    #Install branch develop / callcenter
    if echo $BRANCH | grep -i "^develop" > /dev/null ; then
        git checkout -b develop --track origin/develop
    fi
    if echo $BRANCH | grep -i "^callcenter" > /dev/null ; then
        git checkout -b callcenter --track origin/callcenter
    fi

    #Copy files
    cp -r /usr/src/newfies-dialer/newfies $INSTALL_DIR
    cp -r /usr/src/newfies-dialer/lua $LUA_DIR
    cd $LUA_DIR/libs/
    wget --no-check-certificate https://raw.github.com/areski/lua-acapela/$BRANCH/acapela.lua

    #Upload audio files
    mkdir -p /usr/share/newfies/usermedia/upload/audiofiles
    chown -R $NEWFIES_USER:$NEWFIES_USER /usr/share/newfies/usermedia
}

#Create PGSQL
func_create_pgsql_database(){

    # Create the Database
    echo "We will remove existing Database"
    echo "Press Enter to continue"
    read TEMP
    echo "sudo -u postgres dropdb $DATABASENAME"
    sudo -u postgres dropdb $DATABASENAME
    # echo "Remove Existing Database if exists..."
    #if [ `sudo -u postgres psql -qAt --list | egrep $DATABASENAME | wc -l` -eq 1 ]; then
    #     echo "sudo -u postgres dropdb $DATABASENAME"
    #     sudo -u postgres dropdb $DATABASENAME
    # fi
    echo "Create Database..."
    echo "sudo -u postgres createdb $DATABASENAME"
    sudo -u postgres createdb $DATABASENAME

    #CREATE ROLE / USER
    echo "Create Postgresql user $DB_USERNAME"
    #echo "sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME"
    #sudo -u postgres createuser --no-createdb --no-createrole --no-superuser $DB_USERNAME
    echo "sudo -u postgres psql --command=\"create user $DB_USERNAME with password 'XXXXXXXXXXXX';\""
    sudo -u postgres psql --command="CREATE USER $DB_USERNAME with password '$DB_PASSWORD';"

    echo "Grant all privileges to user..."
    sudo -u postgres psql --command="GRANT ALL PRIVILEGES on database $DATABASENAME to $DB_USERNAME;"
}

#NGINX / SUPERVISOR
func_config_start_nginx_supervisor(){
    #Configure and Start supervisor
    case $DIST in
        'DEBIAN')
            cp /usr/src/newfies-dialer/install/supervisor/gunicorn_newfies_dialer.conf /etc/supervisor/conf.d/
        ;;
        'CENTOS')
            cp /usr/src/newfies-dialer/install/supervisor/supervisord /etc/init.d/supervisor
            chmod +x /etc/rc.d/init.d/supervisor
            chkconfig --levels 235 supervisor on
            echo_supervisord_conf > /etc/supervisord.conf
            cat /usr/src/newfies-dialer/install/supervisor/gunicorn_newfies_dialer.conf >> /etc/supervisord.conf
            mkdir /var/log/supervisor/
        ;;
    esac
    /etc/init.d/supervisor force-stop
    /etc/init.d/supervisor start
}

#Function to install Frontend
func_install_frontend(){

    echo ""
    echo ""
    echo "This script will install Newfies-Dialer"
    echo "======================================="
    echo ""

    if [ -d "$INSTALL_DIR" ]; then
        # Newfies-Dialer is already installed
        clear
        echo ""
        echo "We detect an existing Newfies-Dialer Installation"
        echo "if you continue the existing installation will be removed!"
        echo ""
        echo "Press Enter to continue or CTRL-C to exit"
        read TEMP

        mkdir /tmp/old-newfies-dialer_$DATETIME
        mv $INSTALL_DIR /tmp/old-newfies-dialer_$DATETIME
        mkdir /tmp/old-lua-newfies-dialer_$DATETIME
        mv $LUA_DIR /tmp/old-lua-newfies-dialer_$DATETIME
        echo "Files from $INSTALL_DIR has been moved to /tmp/old-newfies-dialer_$DATETIME and /tmp/old-lua-newfies-dialer_$DATETIME"

        if [ `sudo -u postgres psql -qAt --list | egrep '^$DATABASENAME\|' | wc -l` -eq 1 ]; then
            echo ""
            echo "Run backup with postgresql..."
            sudo -u postgres pg_dump $DATABASENAME > /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql
            echo "PostgreSQL Dump of database $DATABASENAME added in /tmp/old-newfies-dialer_$DATETIME.pgsqldump.sql"
            echo "Press Enter to continue"
            read TEMP
        fi
    fi

    #Install Depedencies
    func_install_dependencies

    #Install Celery & redis-server
    func_install_redis_server

    #Create and enable virtualenv
    func_setup_virtualenv

    #Install Code Source
    func_install_source

    #Install PIP dependencies
    func_install_pip_deps

    #Prepare the settings
    func_prepare_settings

    func_create_pgsql_database

    #Prepare Django DB / Migrate / Create User ...
    cd $INSTALL_DIR/
    python manage.py syncdb --noinput
    python manage.py migrate

    #Load Countries Dialcode
    #python manage.py load_country_dialcode
    wget https://raw.github.com/areski/django-sms-gateway/master/sms/fixtures/example_gateways.json
    python manage.py loaddata example_gateways.json
    rm example_gateways.json

    clear
    echo ""
    echo "Create a super admin user..."
    python manage.py createsuperuser

    echo "Install Bower deps"
    python manage.py bower_install -- --allow-root

    echo "Collects the static files"
    python manage.py collectstatic --noinput

    #NGINX / SUPERVISOR
    func_config_start_nginx_supervisor

    # * * LOGROTATE * *
    func_prepare_logger

    echo ""
    echo "*****************************************************************"
    echo "Congratulations, Newfies-Dialer Web Application is now installed!"
    echo "*****************************************************************"
    echo ""
    echo "Please log on to Newfies-Dialer at "
    echo "http://$IPADDR:$HTTP_PORT"
    echo "the username and password are the ones you entered during this installation."
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Function to install backend
func_install_backend() {
    echo ""
    echo ""
    echo "This will install Newfies-Dialer Backend, Celery & Redis on your server"
    echo "Press Enter to continue or CTRL-C to exit"
    read TEMP

    IFCONFIG=`which ifconfig 2>/dev/null||echo /sbin/ifconfig`
    IPADDR=`$IFCONFIG eth0|gawk '/inet addr/{print $2}'|gawk -F: '{print $2}'`
    if [ -z "$IPADDR" ]; then
        clear
        echo "we have not detected your IP address automatically, please enter it manually"
        read IPADDR
    fi

    #Create directory for pid file
    mkdir -p /var/run/celery

    #Install Celery & redis-server
    func_install_redis_server

    #Memcache installation
    #pip install python-memcached

    echo "Configure Celery..."
    case $DIST in
        'DEBIAN')
            # Add init-scripts
            cp /usr/src/newfies-dialer/install/celery-init/debian/etc/default/newfies-celeryd /etc/default/
            cp /usr/src/newfies-dialer/install/celery-init/debian/etc/init.d/newfies-celeryd /etc/init.d/
            # Configure init-scripts
            sed -i "s/CELERYD_USER='celery'/CELERYD_USER='$CELERYD_USER'/g"  /etc/default/newfies-celeryd
            sed -i "s/CELERYD_GROUP='celery'/CELERYD_GROUP='$CELERYD_GROUP'/g"  /etc/default/newfies-celeryd
            chmod +x /etc/default/newfies-celeryd
            chmod +x /etc/init.d/newfies-celeryd

            /etc/init.d/newfies-celeryd restart
            cd /etc/init.d; update-rc.d newfies-celeryd defaults 99

            #Check permissions on /dev/shm to ensure that celery can start and run for openVZ.
            DIR="/dev/shm"
            echo "Checking the permissions for $dir"
            stat $DIR
            if [ `stat -c "%a" $DIR` -ge 777 ] ; then
                echo "$DIR has Read Write permissions."
            else
                echo "$DIR has no read write permissions."
                chmod -R 777 /dev/shm
                if [ `grep -i /dev/shm /etc/fstab | wc -l` -eq 0 ]; then
                    echo "Adding fstab entry to set permissions /dev/shm"
                    echo "none /dev/shm tmpfs rw,nosuid,nodev,noexec 0 0" >> /etc/fstab
                fi
            fi
        ;;
        'CENTOS')
            # Add init-scripts
            cp /usr/src/newfies-dialer/install/celery-init/centos/etc/default/newfies-celeryd /etc/default/
            cp /usr/src/newfies-dialer/install/celery-init/centos/etc/init.d/newfies-celeryd /etc/init.d/
            # Configure init-scripts
            sed -i "s/CELERYD_USER='celery'/CELERYD_USER='$CELERYD_USER'/g"  /etc/default/newfies-celeryd
            sed -i "s/CELERYD_GROUP='celery'/CELERYD_GROUP='$CELERYD_GROUP'/g"  /etc/default/newfies-celeryd

            chmod +x /etc/init.d/newfies-celeryd
            /etc/init.d/newfies-celeryd restart

            chkconfig --add newfies-celeryd
            chkconfig --level 2345 newfies-celeryd on
        ;;
    esac

    #Install Python ESL / those lines doesn't work in install-freeswitch.sh
    cd /usr/src/freeswitch/libs/esl
    make pymod-install

    #Restart FreeSWITCH to find the startup-script
    /etc/init.d/freeswitch restart

    echo ""
    echo "**************************************************************"
    echo "Congratulations, Newfies-Dialer Backend is now installed!"
    echo "**************************************************************"
    echo ""
    echo "Thank you for installing Newfies-Dialer"
    echo "Yours"
    echo "The Star2Billing Team"
    echo "http://www.star2billing.com and http://www.newfies-dialer.org/"
    echo ""
    echo "**************************************************************"
    echo ""
}

#Install recent version of redis-server
func_install_redis_server() {
    echo "Install Redis-server ..."
    case $DIST in
        'DEBIAN')
            apt-get -y install redis-server
            /etc/init.d/redis-server restart
        ;;
        'CENTOS')
            yum -y --enablerepo=epel install redis
            chkconfig --add redis
            chkconfig --level 2345 redis on
            /etc/init.d/redis start
        ;;
    esac
}


add script to make it simpler to build and compile under docker

#!/usr/bin/env bash

# friendly names for arguments
IMAGE=$1
FLAVOR=$2
VERSION=$3

# abort on error
set -e

# print usage if no argument supplied
if [ -z "$IMAGE" ] || [ -z "$FLAVOR" ]; then
    echo -e "Compiles RStudio inside a Docker container."
    echo -e "Usage: docker-compile image-name flavor-name [version]\n"
    echo -e "Valid images:\n"
    ls -f docker/jenkins/Dockerfile.* | sed -e 's/.*Dockerfile.//'
    echo -e "\nValid flavors:\n"
    echo -e "desktop"
    echo -e "server"
    exit 1
fi

# make sure we're running from the directory of this script, and infer the
# name of the repository
cd "$(dirname ${BASH_SOURCE[0]})"
REPO=$(basename $(pwd))

# check to see if there's already a built image
IMAGEID=`docker images $REPO:$IMAGE --format "{{.ID}}"`
if [ -z "$IMAGEID" ]; then
    echo "No image found for $REPO:$IMAGE; building..."
    docker build --tag "$REPO:$IMAGE" --file "docker/jenkins/Dockerfile.$IMAGE" .
else
    echo "Using image $IMAGEID for $REPO:$IMAGE."
fi

# infer the package extension from the image name
if [ "${IMAGE:0:6}" = "centos" ]; then
    PACKAGE=RPM
    INSTALLER=yum
else
    PACKAGE=DEB
    INSTALLER=debian
fi

if [ -n "$VERSION" ]; then
    SPLIT=(${VERSION//\./ })
    ENV="RSTUDIO_VERSION_MAJOR=${SPLIT[0]} RSTUDIO_VERSION_MINOR=${SPLIT[1]} RSTUDIO_VERSION_PATCH=${SPLIT[2]}"
fi

echo $IMAGE $FLAVOR $VERSION $PACKAGE $INSTALLER $ENV

# run compile step
# docker run -v $(pwd):/src --user jenkins $REPO:$IMAGE bash -c "cd /src/dependencies/linux && ./install-dependencies-$INSTALLER --exclude-qt-sdk && cd /src/package/linux && ./make-$FLAVOR-package $PACKAGE"

error: pathspec 'docker-compile.sh' did not match any file(s) known to git


Update install.sh

Update install.sh

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/hipages/travis-tools.git/'


Added in output for clarity.  Added in routine to allow execution without sudo

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/wfarn/scratchpad.git/'


Add Plasma with bspwm script

Add Plasma with bspwm script

This is the last commit I will make regarding Plasma with bspwm
support. This script is required to start Plasma with bspwm, although
it is much better to run KDE applications from bspwm instead.

error: pathspec '.config/plasma-workspace/env/set_window_manager.sh' did not match any file(s) known to git


Generate traffic against the data testrequest endpoint

#!/bin/bash

DURATION=$1
HOST=$2

NOW=$(date +%s)
END_TIME=$(expr ${NOW} + ${DURATION} \* 60)

echo Running until ${END_TIME}

while [[ $(date +%s) -lt ${END_TIME} ]]; do
    RES=$(curl -q ${HOST}:5000/datadog/testrequest 2>/dev/null | wc -c)
    if [[ $? == 0 ]]; then
        echo "Got a ${RES} character response"
    else
        echo "Unable to fetch from ${HOST}"
    fi
done

error: pathspec 'jenkins/send_testrequest_traffic.sh' did not match any file(s) known to git


Add lint script.

Add lint script.

#!/bin/bash

./node_modules/.bin/jshint $(find ./lib ./scripts -type f -name "*.js") --config jshint.json

error: pathspec 'scripts/lint.sh' did not match any file(s) known to git


Add experimental make.sh

Add experimental make.sh

#!/bin/sh
set -e
set -x

echo "Experimental cross platform build with mono and go cross-compile"

rm -rf output
rm -rf packages

GOPATH=$PWD/diego-release  GOOS=windows GOARCH=amd64  go build -o diego-sshd.exe github.com/cloudfoundry-incubator/diego-ssh/cmd/sshd

nuget restore
xbuild /p:TargetFrameworkVersion="v4.5"

bsdtar -czvf windows_app_lifecycle.tgz --exclude log -C Builder/bin . -C ../../Launcher/bin . -C ../../Healthcheck/bin . -C ../.. ./diego-sshd.exe

error: pathspec 'scripts/make.sh' did not match any file(s) known to git


Change footnote from landscape-sysinfo

Change footnote from landscape-sysinfo

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/devster31/vvv-packer.git/'


Updated script to build 64 bits binaries.

git-svn-id: 9b02ef3cc6e2caea22b87a5733e6bc2a64edb058@1430 4e206d99-4929-0410-ac5d-dfc041789085

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Polyfructol/Fire.git/'


chown after fromdos

chown after fromdos

fromdos seem to reset file ownership to root.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/MainNerve/NetforceDefender.git/'


dev tools: Stage the copyright block to make diffs smaller.

#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice, this list of conditions
#    and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice, this list of
#    conditions and the following disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
#    may be used to endorse or promote products derived from this software without specific prior
#    written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------

emulate -LR zsh

# Argument parsing.
if (( $# != 3 )) || [[ $1 == -* ]]; then
  print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME"
  print -r -- >&2 ""
  print -r -- >&2 "Generate highlighters/HIGHLIGHTER/test-data/BASENAME.zsh based on the"
  print -r -- >&2 "current highlighting of BUFFER."
  exit 1
fi
buffer=$1
ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 )
fname=${0:A:h:h}/highlighters/$2/test-data/${3%.zsh}.zsh

# Load the main script.
. ${0:A:h:h}/zsh-syntax-highlighting.zsh

# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style
_zsh_highlight_add_highlight()
{
  region_highlight+=("$1 $2 $3")
}

# Copyright block
year="`LC_ALL=C date +%Y`"
if ! read -q "?Set copyright year to $year? "; then
  year="YYYY"
fi
exec >$fname
<$0 sed -n -e '1,/^$/p' | sed -e "s/2[0-9][0-9][0-9]/${year}/"
echo ""
# Assumes stdout is line-buffered
git add -- $fname

# Buffer
print -n 'BUFFER='
print -r -- ${(qq)buffer}
echo ""

# Expectations
print 'expected_region_highlight=('
() {
  local i
  local PREBUFFER
  local BUFFER

  PREBUFFER=""
  BUFFER="$buffer"
  region_highlight=()
  _zsh_highlight

  for ((i=1; i<=${#region_highlight}; i++)); do
    local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} )
    integer start=$highlight_zone[1] end=$highlight_zone[2]
    if (( start < end )) # region_highlight ranges are half-open
    then
      (( --end )) # convert to closed range, like expected_region_highlight
      (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed
    fi
    printf "  %s # %s\n" ${(qq):-"$start $end $highlight_zone[3]"} $BUFFER[start,end]
  done
}
print ')'

#!/usr/bin/env zsh
# -------------------------------------------------------------------------------------------------
# Copyright (c) 2016 zsh-syntax-highlighting contributors
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
#  * Redistributions of source code must retain the above copyright notice, this list of conditions
#    and the following disclaimer.
#  * Redistributions in binary form must reproduce the above copyright notice, this list of
#    conditions and the following disclaimer in the documentation and/or other materials provided
#    with the distribution.
#  * Neither the name of the zsh-syntax-highlighting contributors nor the names of its contributors
#    may be used to endorse or promote products derived from this software without specific prior
#    written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
# OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
# -------------------------------------------------------------------------------------------------
# -*- mode: zsh; sh-indentation: 2; indent-tabs-mode: nil; sh-basic-offset: 2; -*-
# vim: ft=zsh sw=2 ts=2 et
# -------------------------------------------------------------------------------------------------

emulate -LR zsh

# Argument parsing.
if (( $# != 3 )) || [[ $1 == -* ]]; then
  print -r -- >&2 "$0: usage: $0 BUFFER HIGHLIGHTER BASENAME"
  print -r -- >&2 ""
  print -r -- >&2 "Generate highlighters/HIGHLIGHTER/test-data/BASENAME.zsh based on the"
  print -r -- >&2 "current highlighting of BUFFER."
  exit 1
fi
buffer=$1
ZSH_HIGHLIGHT_HIGHLIGHTERS=( $2 )
fname=${0:A:h:h}/highlighters/$2/test-data/${3%.zsh}.zsh
exec 3>&1
exec >$fname
git add -N $fname

# Load the main script.
. ${0:A:h:h}/zsh-syntax-highlighting.zsh

# Overwrite _zsh_highlight_add_highlight so we get the key itself instead of the style
_zsh_highlight_add_highlight()
{
  region_highlight+=("$1 $2 $3")
}

# Copyright block
<$0 sed -n -e '1,/^$/p' | sed -e 's/2[0-9][0-9][0-9]/YYYY/'
echo ""

# Buffer
print -n 'BUFFER='
print -r -- ${(qq)buffer}
echo ""

# Expectations
print 'expected_region_highlight=('
() {
  local i
  local PREBUFFER
  local BUFFER

  PREBUFFER=""
  BUFFER="$buffer"
  region_highlight=()
  _zsh_highlight

  for ((i=1; i<=${#region_highlight}; i++)); do
    local -a highlight_zone; highlight_zone=( ${(z)region_highlight[$i]} )
    integer start=$highlight_zone[1] end=$highlight_zone[2]
    if (( start < end )) # region_highlight ranges are half-open
    then
      (( --end )) # convert to closed range, like expected_region_highlight
      (( ++start, ++end )) # region_highlight is 0-indexed; expected_region_highlight is 1-indexed
    fi
    printf "  %s # %s\n" ${(qq):-"$start $end $highlight_zone[3]"} $BUFFER[start,end]
  done
}
print ')'

exec >&3
year="`LC_ALL=C date +%Y`"
if read -q "?Set copyright year to $year? "; then
  <$fname >$fname.t sed s/YYYY/$year/ &&
    mv $fname.t $fname
fi


Added monGrowth.sh.

Added monGrowth.sh.

#!/bin/sh
################################################################################
## Name:		monGroth.sh
## Author:		FOXX (frozenfoxx@github.com)
## Date:		05/13/2009
## Description:		Quick script for monitoring growth of a partition.
################################################################################

## awk version
##For Solaris
AWK=/usr/xpg4/bin/awk
##For others
#AWK=/usr/bin/nawk

## Variables
SEARCHTEXT=$1
OUTPUTFILE=$2

case "$SEARCHTEXT" in
'')
        echo "Usage:  monGrowth.sh <text to monitor in df -h> <tracking file>"
        echo ""
        ;;
*)
	## Grab interesting lines with grep from file system mountpoints,
	##  and print to a CSV file the date, the mount point, used space, and remain. space.
        (df -h |grep "$SEARCHTEXT") | $AWK -v datevar="`date`" '{print datevar "," $6 "," $3 "," $4 }' >> $OUTPUTFILE
        ;;
esac
exit 0

error: pathspec 'sh/monGrowth.sh' did not match any file(s) known to git


add mssql

add mssql

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/hachihub/ubuntu-init.git/'


angstrom personal feed script: s/staging/sysroots/

#!/bin/sh
# MIT Licensed
# Initial version by Graeme 'XorA' Gregory, Further changes by Koen Kooi

# Run this from inside ${DEPLOY_DIR} e.g. tmp/deploy/glibc/

# Angstrom webserver
REMOTEM=http://www.angstrom-distribution.org

# Feed dir we want to upload to
REMOTED=feeds/unstable/ipk/$(basename $PWD)

# create upload dir
mkdir -p upload-queue || true

# Find and delete morgue dirs, we don't need them
echo "Deleting morgue directories"
find ipk/ -name "morgue" -exec rm -rf \{\} \;

# Copy symlink packages to an upload queue
echo "Symlink packages to upload queue"
find ipk/ -name "*.ipk" -exec ln -sf ${PWD}/\{\} upload-queue/ \;

# Find file already present on webserver
echo "Getting file list from server"
wget $REMOTEM/$REMOTED/unsorted/files-sorted -O files-remote
ls upload-queue/ | grep -v morgue > files-local

# Check for files already present on webserver
echo "Checking for duplicates"
cat files-remote files-local | sort | uniq -u >files-uniq
cat files-uniq files-local | sort | uniq -d > files-trans

rm -f upload-queue/bigbuck*

# Clean out stale packages
if [ -d personal-feed ] ; then
	rm -rf personal-feed
fi

mkdir -p personal-feed

# Copy over non-duplicate files
echo "Starting rsync..."
rsync -vz --partial --copy-links --progress --files-from=files-trans upload-queue/ personal-feed/

echo "Generating index for your personal feed..."
( cd personal-feed ; PATH=$PATH:$(find ../../../sysroots/$(uname -m)* -name "ipkg-make-index" | sed s:/ipkg-make-index::g) ipkg-make-index -p Packages -m . >& /dev/null )

# Clean up temporary files
echo "Removing upload queue"
rm -rf files-remote files-local files-uniq files-trans upload-queue

echo "Your personal feed is now ready at ${PWD}/personal-feed"

#!/bin/sh
# MIT Licensed
# Initial version by Graeme 'XorA' Gregory, Further changes by Koen Kooi

# Run this from inside ${DEPLOY_DIR} e.g. tmp/deploy/glibc/

# Angstrom webserver
REMOTEM=http://www.angstrom-distribution.org

# Feed dir we want to upload to
REMOTED=feeds/unstable/ipk/$(basename $PWD)

# create upload dir
mkdir -p upload-queue || true

# Find and delete morgue dirs, we don't need them
echo "Deleting morgue directories"
find ipk/ -name "morgue" -exec rm -rf \{\} \;

# Copy symlink packages to an upload queue
echo "Symlink packages to upload queue"
find ipk/ -name "*.ipk" -exec ln -sf ${PWD}/\{\} upload-queue/ \;

# Find file already present on webserver
echo "Getting file list from server"
wget $REMOTEM/$REMOTED/unsorted/files-sorted -O files-remote
ls upload-queue/ | grep -v morgue > files-local

# Check for files already present on webserver
echo "Checking for duplicates"
cat files-remote files-local | sort | uniq -u >files-uniq
cat files-uniq files-local | sort | uniq -d > files-trans

rm -f upload-queue/bigbuck*

# Clean out stale packages
if [ -d personal-feed ] ; then
	rm -rf personal-feed
fi

mkdir -p personal-feed

# Copy over non-duplicate files
echo "Starting rsync..."
rsync -vz --partial --copy-links --progress --files-from=files-trans upload-queue/ personal-feed/

echo "Generating index for your personal feed..."
( cd personal-feed ; PATH=$PATH:$(find ../../../staging/$(uname -m)* -name "ipkg-make-index" | sed s:/ipkg-make-index::g) ipkg-make-index -p Packages -m . >& /dev/null )

# Clean up temporary files
echo "Removing upload queue"
rm -rf files-remote files-local files-uniq files-trans upload-queue

echo "Your personal feed is now ready at ${PWD}/personal-feed"


added job to process dbpedia

added job to process dbpedia

#!/bin/bash
REDUCERS=${1:-20}
hadoop fs -rm -r /user/roman/ngrams_dbpedia_counts
hadoop jar /opt/cloudera/parcels/CDH/lib/hadoop-mapreduce/hadoop-streaming.jar \
  -Dmapreduce.framework.name=yarn \
  -Dmapreduce.job.contract=false \
  -Dmapreduce.job.reduces=$REDUCERS \
  -files mapper_dbpedia_uri_counts.py,reducer_generic.py,dbpedia.dbm \
  -mapper mapper_dbpedia_uri_counts.py \
  -reducer reducer_generic.py \
  -input /user/roman/ngrams_dbpedia/ -output /user/roman/ngrams_dbpedia_counts

error: pathspec 'mapreduce/dbpedia_uri_counts_job.sh' did not match any file(s) known to git


tool,sched_event_parser.sh : add it

tool,sched_event_parser.sh : add it

#!/bin/bash

if [ ! "$1" ]; then
	echo "invalid arguments"
	exit 1
fi

mkdir -p output

# grep only sched_switch event
cat $1 | grep sched_switch > output/$1.sched_switch
# make it as list separated by blank
cat output/$1.sched_switch | sed 's/: / /g;s/=/ /g;s/ > //g' | tr -s " " | sed 's/^ //g' > output/$1.formatted
# create data list for checking cpu usage
cat output/$1.formatted | cut -d' ' -f4,7,9,15,17 > output/$1.raw.cpuusage

#get column(assume that kernel use fixed width)
cat output/$1.sched_switch | cut -c'-21' | tr -s " " > output/$1.column_current-taskpid
cat output/$1.sched_switch | cut -c'24-28' | tr -s " " > output/$1.column_cpu
cat output/$1.sched_switch | cut -c'34-46' | tr -s " " > output/$1.column_timestamp
cat output/$1.sched_switch | cut -d':' -f2 | tr -s " " > output/$1.column_eventname
cat output/$1.sched_switch | cut -c'62-' | sed 's/prev_comm=//g;s/prev_pid=/,/g;s/prev_prio=/,/g;s/prev_state=/,/g;s/==> next_comm=/,/g;s/next_pid=/,/g;s/next_prio=/,/g' | sed 's/ ,/,/g' > output/$1.sched_switch.formatted
cat output/$1.sched_switch.formatted | cut -d',' -f1 | sed 's/ //g' > output/$1.column_currname
cat output/$1.sched_switch.formatted | cut -d',' -f2 > output/$1.column_currpid
cat output/$1.sched_switch.formatted | cut -d',' -f3 > output/$1.column_currprio
cat output/$1.sched_switch.formatted | cut -d',' -f4 > output/$1.column_currstate
cat output/$1.sched_switch.formatted | cut -d',' -f5 | sed 's/ //g' > output/$1.column_nextname
cat output/$1.sched_switch.formatted | cut -d',' -f6 > output/$1.column_nextpid
cat output/$1.sched_switch.formatted | cut -d',' -f7 > output/$1.column_nextprio

#get {curr, next}+{name,pid}
paste output/$1.column_currname output/$1.column_currpid | sed 's/\t//g' > output/$1.curr_name+pid
paste output/$1.column_nextname output/$1.column_nextpid | sed 's/\t//g' > output/$1.next_name+pid

# create task top list
cat output/$1.curr_name+pid | sort | uniq -c | sort -bnr > output/$1.tasktop

error: pathspec 'tool/sched_event_parser/sched_event_parser.sh' did not match any file(s) known to git


ran bfg tool to remove old binary files from repository. you may need to clone or fork again

#!/bin/bash
#set -x

# Shows you the largest objects in your repo's pack file.
# Written for osx.
#
# @see http://stubbisms.wordpress.com/2009/07/10/git-script-to-show-largest-pack-objects-and-trim-your-waist-line/
# @author Antony Stubbs

# set the internal field spereator to line break, so that we can iterate easily over the verify-pack output
IFS=$'\n';

# list all objects including their size, sort by size, take top 10
objects=`git verify-pack -v .git/objects/pack/pack-*.idx | grep -Ev "non delta|chain length|git/objects" | tr -s " " | sort -k3gr | head -n30`

echo "All sizes are in kB's. The pack column is the size of the object, compressed, inside the pack file."

output="size,SHA,location"
for y in $objects
do
  # extract the size in KB
  size=$((`echo $y | cut -f 3 -d ' '`/1024))
  # extract the SHA
  sha=`echo $y | cut -f 1 -d ' '`
  # find the objects location in the repository tree
  other=`git rev-list --all --objects | grep $sha`
  #lineBreak=`echo -e "\n"`
  output="${output}\n${size},${other}"
done

echo -e $output | column -t -s ', '

error: pathspec 'git_largest.sh' did not match any file(s) known to git


Run JS/CSS build as part of CI build

Run JS/CSS build as part of CI build

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/LINKIWI/apache-auth.git/'


Add docs update script.

Add docs update script.

PiperOrigin-RevId: 324847170

#!/bin/bash
# Run this from your github clone.
# It assumes you have tensorflow_docs as the "upstream" remote.

OLD_BRANCH=$1
NEW_BRANCH=$2

if [ -n "$OLD_BRANCH" ]; then
  echo "OLD_BRANCH=$OLD_BRANCH"
else
  echo '$OLD_BRANCH is unset' && exit;
fi

if [ -n "$NEW_BRANCH" ]; then
  echo "NEW_BRANCH=$NEW_BRANCH"
else
  echo '$NEW_BRANCH is unset' && exit
fi

# Print commands while running, and fail if a command fails
set -e
set -x

# Merge the previous releases's docs into the current.
git checkout master
git pull upstream master

git fetch upstream
git branch -D $NEW_BRANCH || echo "failed -> branch doesn't exist -> that\'s ok"
# Checkout the upstream branch, if it doesn't exist create it from master
git checkout  --track upstream/"$NEW_BRANCH" || (git checkout -b "$NEW_BRANCH")
# Merge the previous version. If that gives a merge-conflict, auto-resolve and commit.
git merge upstream/$OLD_BRANCH --message "merge $OLD_BRANCH" ||  (grep -l "<<<<<<<" -r | xargs git checkout --ours && git commit -am "merge $OLD_BRANCH")

# Overwrite the ditectory with the contents from tensorflow/en/versions
rm -rf site/en/api_docs/python
python ../tensorflow/tensorflow/tools/docs/generate2.py --output_dir=site/en/api_docs/python

# Strip some devsite headers and stuff.
# The sed call is independant of the number of files per call so there's
# no problem to a simple "xargs" here.
find site/en/api_docs/ -name "*.md" | xargs sed -i '/Book:/d'
find site/en/api_docs/ -name "*.md" | xargs sed -i '/Project:/d'
find site/en/api_docs/ -name "*.html" | xargs sed -i '/name=\"book_path\"/d'
find site/en/api_docs/ -name "*.html" | xargs sed -i '/name=\"project_path\"/d'

# Commit and push to your github.
git add site/en/api_docs/
git commit -am "Update docs to $NEW_BRANCH"
git push -f origin $NEW_BRANCH

error: pathspec 'tools/release_tools/push_version_to_github.sh' did not match any file(s) known to git


Update to finalconfig.sh

Update to finalconfig.sh

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/addrummond/nodeibexfarm.git/'


mocha path

mocha path

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/nuodb/ruby-activerecord-nuodb-adapter.git/'


change data file location

change data file location

#!/usr/bin/env bash

#
# Copyright 2018 Analytics Zoo Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#

# Usage: bash get_ambient_temperature_system_failure.sh dir
# Download ambient_temperature_system_failure dataset to the target 'dir'.
# If 'dir' is not specified, it will be downloaded to the same dir with this script.

if [ ! -z "$1" ]
then
   DIR=$1
   cd "$DIR"
else
   DIR=$(dirname "$0")
   echo "Download path: $DIR"
   cd "$DIR"
fi

FILENAME="./nyc_taxi.csv"
if [ -f "$FILENAME" ]
then
   echo "$FILENAME already exists."
   exit
fi

echo "Downloading nyc_taxi.csv"
wget raw.githubusercontent.com/numenta/NAB/master/data/realKnownCause/nyc_taxi.csv

echo "Finished"

error: pathspec 'data/NAB/nyc_taxi/get_nyc_taxi.sh' did not match any file(s) known to git


bug 605429 - bring cron test crash submitter into socorro, with locking fixed and overall greatly simplified - patch by Jason Thomas

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/twobraids/socorro.git/'


maven-central-deploy.sh: script for Maven Central deployment

error: pathspec 'scripts/maven-central-deploy.sh' did not match any file(s) known to git


Adding deploy hook to fix error on engine yard

#!/bin/sh
sudo rm /usr/local/bin/ey_node_app_info
sudo ln -s /opt/nodejs/current/bin/ey_node_app_info /usr/local/bin/ey_node_app_info

error: pathspec 'deploy/after_bundle.sh' did not match any file(s) known to git


Added capture unit test stubs.

Added capture unit test stubs.

#!/bin/sh
#
# Copyright (C) 2009-2012	Emmanuel Roullit <emmanuel.roullit@gmail.com>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or (at
# your option) any later version.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
# for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
#

test_description='Test dabba capture command'
ring_size=$((16*1024*1024))

. ./dabba-test-lib.sh

test_expect_success "Setup: Start dabbad" "
    $DABBAD_PATH/dabbad --daemonize
"

test_expect_success "Start a capture thread on loopback" "
    $DABBA_PATH/dabba capture start --device lo --pcap test1.pcap --size $ring_size
"

test_expect_success "List created capture thread" "
    $DABBA_PATH/dabba capture list > result
"

test_expect_success "Start a second capture thread on loopback" "
    $DABBA_PATH/dabba capture start --device lo --pcap test2.pcap --size $ring_size
"

test_expect_success "List created capture thread" "
    $DABBA_PATH/dabba capture list > result
"

test_expect_success "Cleanup: Stop dabbad" "
    killall dabbad
"

test_done

# vim: ft=sh:tabstop=4:et

error: pathspec 'dabba/test/t1100-capture.sh' did not match any file(s) known to git


Fix start-shard.sh not finding root token in Mongo

Looks like this was broken by a typo in a commit today

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/slamdata/slamengine.git/'


Update reference to solidus:auth:install

To fix these errors when generating a sandbox:

> Could not find generator 'spree:auth:install'. Maybe you meant 'spree:install', 'solidus:auth:install' or 'devise:install'
> Run `rails generate --help` for more options.

#!/bin/sh
# Used in the sandbox rake task in Rakefile

case "$DB" in
postgres)
	RAILSDB="postgresql"
	;;
mysql)
	RAILSDB="mysql"
	;;
*)
	RAILSDB="sqlite3"
	;;
esac

rm -rf ./sandbox
bundle exec rails new sandbox --skip-bundle --database="$RAILSDB"
if [ ! -d "sandbox" ]; then
  echo 'sandbox rails application failed'
  exit 1
fi

cd ./sandbox
echo "gem 'solidus', :path => '..'" >> Gemfile
echo "gem 'solidus_auth_devise'" >> Gemfile

cat <<RUBY >> Gemfile
group :test, :development do
  platforms :mri do
    gem 'pry-byebug'
  end
end
RUBY

bundle install --gemfile Gemfile
bundle exec rake db:drop db:create
bundle exec rails g spree:install --auto-accept --user_class=Spree::User --enforce_available_locales=true
bundle exec rails g solidus:auth:install

#!/bin/sh
# Used in the sandbox rake task in Rakefile

case "$DB" in
postgres)
	RAILSDB="postgresql"
	;;
mysql)
	RAILSDB="mysql"
	;;
*)
	RAILSDB="sqlite3"
	;;
esac

rm -rf ./sandbox
bundle exec rails new sandbox --skip-bundle --database="$RAILSDB"
if [ ! -d "sandbox" ]; then
  echo 'sandbox rails application failed'
  exit 1
fi

cd ./sandbox
echo "gem 'solidus', :path => '..'" >> Gemfile
echo "gem 'solidus_auth_devise'" >> Gemfile

cat <<RUBY >> Gemfile
group :test, :development do
  platforms :mri do
    gem 'pry-byebug'
  end
end
RUBY

bundle install --gemfile Gemfile
bundle exec rake db:drop db:create
bundle exec rails g spree:install --auto-accept --user_class=Spree::User --enforce_available_locales=true
bundle exec rails g spree:auth:install


Adding SHIRO-plugins

Adding SHIRO-plugins

PLUGIN=SHIRO-plugins
GIT_URI="https://github.com/BlokasLabs/${PLUGIN} --recursive"
TMP_DIR=${ROOTFS_DIR}/tmp/${PLUGIN}

rm -rf ${TMP_DIR}
git clone --depth 1 ${GIT_URI} ${TMP_DIR}
pushd ${TMP_DIR}

export CC=arm-linux-gnueabihf-gcc
export CXX=arm-linux-gnueabihf-g++
export LD=arm-linux-gnueabihf-ld
export STRIP=arm-linux-gnueabihf-strip

make NOOPT=true -j4 CFLAGS="--sysroot=${ROOTFS_DIR}" LDFLAGS="--sysroot=${ROOTFS_DIR}"

cp -r bin/*.lv2 ${LV2_ABS_DIR}/

popd

rm -rf ${TMP_DIR}

error: pathspec 'stage5/08-SHIRO-plugins/01-run.sh' did not match any file(s) known to git


script to monitor ssh tunnels

script to monitor ssh tunnels

#!/bin/sh
# this clears stale tunnels when there is no equivalent connection
# change the username@ with the tunnel username on the remote system you use
# I run this out of cron
# */5 * * * * /usr/local/bin/tunnel-mon.sh 1>/dev/null 2>&1
sshpid=$(ps auxww | grep autotunnel@ | grep /ssh | awk '{ print $2 }')

if [ -z "$sshpid" ]; then
  exit 0
fi

lsofout=$(lsof -n -P -p $sshpid | grep TCP)

if [ -z "$lsofout" ]; then
  kill -9 $sshpid
fi

exit 0

error: pathspec 'shell/monitor-autossh-tunnel.sh' did not match any file(s) known to git


Added symlink to run-swipl-in-container.sh

error: pathspec 'test/tests/swipl-modules/run.sh' did not match any file(s) known to git


Remove reference to trod-web-config in the postinstall.sh script

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/Trov/trov-web-config.git/'


fix(tests): only update lastupdate file on success

#!/usr/bin/env bash

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

set -o errexit # exit on first command with non-zero status

function update_needed() {
  echo "Checking whether Firefox binaries should be updated... "

  if [ ! -f "$LASTUPDATE_FILE" ]; then
    return # needs to be run for the first time
  fi

  # allow environment override of $update_interval
  local update_interval=${UPDATE_INTERVAL:-86400}

  # isn't date math in bash so much fun?
  local now=$(date +%s)
  local was=$(date -r "$LASTUPDATE_FILE" +%s)
  local age=$(( $now - $was ))
  local fresh=$(( $age < $update_interval ))

  return $fresh
}

function show_firefox_versions() {
  echo "Available firefox versions:"
  for d in latest-beta latest latest-esr; do
    echo -n "  "
    $CHANNELS_DIR/$d/en-US/firefox/firefox-bin --version 2>/dev/null
  done
}

CHANNELS_DIR=$1
if [ -z "$1" ]; then
  CHANNELS_DIR="$HOME/firefox-channels"
fi

FXDOWNLOAD_DIR=$2
if [ -z "$2" ]; then
  FXDOWNLOAD_DIR="$HOME/fxdownload"
fi

LASTUPDATE_FILE="$CHANNELS_DIR/.lastupdate"
mkdir -p $CHANNELS_DIR

if ! update_needed; then
  show_firefox_versions
  echo "No update of Firefox builds is needed at this time."
  exit 0
fi
echo "Firefox builds update needed. Beginning update... "

echo "Updating jrgm/fxdownload repo, if needed ... "
if [ ! -d $FXDOWNLOAD_DIR ]; then
  git clone git://github.com/jrgm/fxdownload $FXDOWNLOAD_DIR
else
  (cd $FXDOWNLOAD_DIR && git pull)
fi

cd $FXDOWNLOAD_DIR && npm install

for d in beta release esr; do
  ./index.js --install-dir $CHANNELS_DIR --channel $d
done

show_firefox_versions

touch "$LASTUPDATE_FILE"
echo "Firefox binaries update complete!"

#!/usr/bin/env bash

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

set -o errexit # exit on first command with non-zero status

function update_needed() {
  echo "Checking whether Firefox binaries should be updated... "

  if [ ! -f "$LASTUPDATE_FILE" ]; then
    touch "$LASTUPDATE_FILE" # ensure it exists
    return # needs to be run for the first time
  fi

  # allow environment override of $update_interval
  local update_interval=${UPDATE_INTERVAL:-86400}

  # isn't date math in bash so much fun?
  local now=$(date +%s)
  local was=$(date -r "$LASTUPDATE_FILE" +%s)
  local age=$(( $now - $was ))
  local fresh=$(( $age < $update_interval ))

  return $fresh
}

function show_firefox_versions() {
  echo "Available firefox versions:"
  for d in latest-beta latest latest-esr; do
    echo -n "  "
    $CHANNELS_DIR/$d/en-US/firefox/firefox-bin --version 2>/dev/null
  done
}

CHANNELS_DIR=$1
if [ -z "$1" ]; then
  CHANNELS_DIR="$HOME/firefox-channels"
fi

FXDOWNLOAD_DIR=$2
if [ -z "$2" ]; then
  FXDOWNLOAD_DIR="$HOME/fxdownload"
fi

LASTUPDATE_FILE="$CHANNELS_DIR/.lastupdate"
mkdir -p $CHANNELS_DIR

if ! update_needed; then
  show_firefox_versions
  echo "No update of Firefox builds is needed at this time."
  exit 0
fi
echo "Firefox builds update needed. Beginning update... "

echo "Updating jrgm/fxdownload repo, if needed ... "
if [ ! -d $FXDOWNLOAD_DIR ]; then
  git clone git://github.com/jrgm/fxdownload $FXDOWNLOAD_DIR
else
  (cd $FXDOWNLOAD_DIR && git pull)
fi

cd $FXDOWNLOAD_DIR && npm install

for d in beta release esr; do
  ./index.js --install-dir $CHANNELS_DIR --channel $d
done

show_firefox_versions

touch "$LASTUPDATE_FILE"
echo "Firefox binaries update complete!"


Add dulcie theme as a basic PS1 prompt with git info

#!/usr/bin/env bash

# Simplistic one-liner theme to display source control management info beside
# the ordinary bash prompt.

prompt() {
  PS1="${reset_color}[\u@\h \W]$(scm_prompt_info)${reset_color}\$ "
}

PROMPT_COMMAND=prompt

error: pathspec 'themes/dulcie/dulcie.theme.bash' did not match any file(s) known to git


add fzf config

add fzf config

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/filipebarros/dotfiles.git/'


Added whoneeds/whowants function

Added whoneeds/whowants function

error: pathspec '_functions.d/whoneeds.sh' did not match any file(s) known to git


changed the order. run mk_so.lua first and then tests.lua

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/NerdWalletOSS/Q.git/'


rbenv replaced with rvm.

rbenv replaced with rvm.

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/jay16/yong-hui-server.git/'


Create requirements.sh

Create requirements.sh

#!/bin/bash

set -e

pushd .

# keystone
cd /tmp
git clone https://github.com/keystone-engine/keystone.git
mkdir -p keystone/build && cd keystone/build
cmake .. && make -j8
sudo make install
cd ../bindings/python && sudo make install # or sudo make install3 for Python3

# capstone
cd /tmp
git clone https://github.com/aquynh/capstone.git
mkdir -p capstone/build && cd capstone/build
cmake .. && make -j8
sudo make install
cd ../bindings/python
sudo make install
sudo make install3 for Python3

# unicorn
cd /tmp
git clone https://github.com/unicorn-engine/unicorn.git
./make.sh -j8
sudo ./make.sh install
cd ./bindings/python
sudo make install
sudo make install3

popd

error: pathspec 'requirements.sh' did not match any file(s) known to git


Create base.sh

Create base.sh

# A base server should have the following stuff to make sysadmin happy
yum install wget mc strace sysstat dstat htop iftop iptraf mtr jwhois mutt elinks tmux screen -y

# This repo is required to get many packages such as proftpd etc
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-7.noarch.rpm

error: pathspec 'base.sh' did not match any file(s) known to git


Create brew.sh

Create brew.sh

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/MarkSHarrison/dotfiles.git/'


add install other useful binaries

add install other useful binaries

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/alexandref93/dotfiles.git/'


Fix vitalizer start test

Fix vitalizer start test

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/vital-software/vitalizer.git/'


zerofill

zerofill

remote: Support for password authentication was removed on August 13, 2021.
remote: Please see https://docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication.
fatal: Authentication failed for 'https://github.com/abrichards5/ABRUnixScripts.git/'