New script `upload_release_files.sh` to automatically upload all files produced by `mvn package` to GoogleCode [trunk, 1.0]

#! /bin/sh
#
PROG="$(basename $0)"

usage () {
cat <<EOF
Usage: $PROG [options]

Upload files to http://gridcertlib.googlecode.com/files
Files to upload are searched for in the "target/" directory;
any "*.jar"/"*.tar.gz"/"*.zip" file is uploaded.

The release number, file type and contents (binary, javadoc, sources)
are automatically used as labels.

This program assumes that the script "googlecode_upload.py" is
available on your PATH. You can get this script from:
http://support.googlecode.com/svn/trunk/scripts/googlecode_upload.py

Options:

  -h, --help    Print this help text.
  -n, --no-act  Print upload commands instead of executing them.

Any other option given on the command line is passed down to the
"googlecode_upload.py" script.

EOF
}

## defaults

# GoogleCode project name
PROJECT='gridcertlib'

# space-separated list of labels to add to *any* file upload
LABELS="$PROJECT"

# name of the uploader script
googlecode_upload='googlecode_upload.py'

## helper functions

add_to_labels () {
    if [ -z "$LABELS" ]; then
        LABELS="$1"
    else
        LABELS="$LABELS,$1"
    fi
}

# TRUE if $1 contains $2 as a substring
contains () {
    echo "$1" | fgrep -q -e "$2"
}

die () {
  rc="$1"
  shift
  (echo -n "$PROG: ERROR: ";
      if [ $# -gt 0 ]; then echo "$@"; else cat; fi) 1>&2
  exit $rc
}

# TRUE if $1 ends with (literal) string $2
endswith () {
    expr "$1" : ".*$2\$" 1>/dev/null 2>&1
}

have_command () {
  type "$1" >/dev/null 2>/dev/null
}

require_command () {
  if ! have_command "$1"; then
    die 1 "Could not find required command '$1' in system PATH. Aborting."
  fi
}

is_absolute_path () {
    expr match "$1" '/' >/dev/null 2>/dev/null
}

## sanity check

require_command googlecode_upload.py

## parse command-line

MAYBE=''
args=''

while [ $# -gt 0 ]; do
    case "$1" in
        --help|-h)
            usage
            exit 0
            ;;
        --labels*|-l)
            # did we get '--labels=x,y,z' ?
            labels=$(echo "$1" | cut -d= -f2)
            if [ -z "$labels" ]; then
                # no, it's '--labels x,y,z'
                shift
                labels="$1"
            fi
            add_to_labels "$labels"
            ;;
        --no-act|--dry-run|-n)
            MAYBE=echo
            ;;
        --)
            shift
            break
            ;;
        *)
            args="$args '$1'"
            ;;
    esac
    shift
done

## main

common_labels="$LABELS"
for path in $(ls target/${PROJECT}-* 2>/dev/null); do
    LABELS="$common_labels"
    summary=''

    filename=$(basename "$path")

    release=$(echo $filename | egrep --only-matching '[0-9]+(\.[0-9]+)+')
    add_to_labels $release

    if contains "$filename" '-bin.'; then
        summary="Package combining JAR files of compiled classes, source files and documentation"
    elif contains "$filename" '-sources.' || contains "$filename" '-src.'; then
        summary="Source files of ${PROJECT} ${release}"
    elif contains "$filename" '-javadoc.'; then
        summary="API documentation of ${PROJECT} ${release}"
    fi

    if endswith "$filename" '.asc'; then
        summary="PGP/GPG signature for file ${filename}"
        add_to_labels "pgp,gpg,signature"
    elif endswith "$filename"  '.jar'; then
        add_to_labels 'jar'
    elif endswith "$filename" '.tar.gz'; then
        add_to_labels 'tar,gzip'
    elif endswith "$filename" '.tar.bz2'; then
        add_to_labels 'tar.bzip2'
    elif endswith "$filename" '.zip'; then
        add_to_labels 'zip'
    fi

    if [ -z "$summary" ]; then
        echo 1>&2 "Could not deduce a description for '$filename': skipping it."
    else
        eval $MAYBE $googlecode_upload "--project='$PROJECT'" "--labels='$LABELS'" "--summary='$summary'" $args "'$path'"
    fi
done

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


Added a clean.sh script. Safer than 'rm -rf *'.

#!/bin/sh

rm -rf CMake* cmake* Data Focus libOSGUIsh.* Makefile FocusPolicies \
    Simplest ThreeObjects

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


osx: add new build notes for universal and static compile on >= 10.6

# build notes for compiling mapnik deps statically
# and "FAT" (aka. universal) in order to allow
# linking a fully standalone libmapnik.a

PREFIX=`pwd`/osx/sources
mkdir -p $PREFIX
export DYLD_LIBRARY_PATH=$PREFIX/lib
export DYLD_LIBRARY_PATH=$PREFIX/lib
export PKG_CONFIG_PATH=$PREFIX/lib/pkgconfig
export PATH=$PREFIX/bin:$PATH
export CORE_CFLAGS="-O3 -arch x86_64 -arch i386 -mmacosx-version-min=10.6 -isysroot /Developer/SDKs/MacOSX10.6.sdk"
export CORE_CXXFLAGS=$CORE_CFLAGS
export CORE_LDFLAGS="-Wl,-search_paths_first -arch x86_64 -arch i386 -Wl,-syslibroot,/Developer/SDKs/MacOSX10.6.sdk"
export ARCHFLAGS="-arch x86_64 -arch i386"

cd osx
mkdir -p deps
cd deps

# boost
wget http://voxel.dl.sourceforge.net/project/boost/boost/1.47.0/boost_1_47_0.tar.bz2
tar xjvf boost_1_47_0.tar.bz2
cd boost_1_47_0
./bootstrap.sh

# no icu variant
./bjam --prefix=$PREFIX -j2 -d2 \
  --with-thread \
  --with-filesystem \
  --with-program_options --with-system --with-chrono \
  --with-regex --disable-icu \
  toolset=darwin \
  macosx-version=10.6 \
  address-model=32_64 \
  architecture=x86 \
  link=static \
  variant=release \
  stage

./bjam --prefix=$PREFIX -j2 -d2 \
  --with-thread \
  --with-filesystem \
  --with-program_options --with-system --with-chrono \
  --with-regex --disable-icu \
  toolset=darwin \
  macosx-version=10.6 \
  address-model=32_64 \
  architecture=x86 \
  link=static \
  variant=release \
  install

cd ../

# universal flags
export CFLAGS=$CORE_CFLAGS
export CXXFLAGS=$CORE_CXXFLAGS
export LDFLAGS=$CORE_LDFLAGS

# sqlite
wget http://www.sqlite.org/sqlite-autoconf-3070701.tar.gz
tar xvf sqlite-autoconf-3070701.tar.gz
cd sqlite-autoconf-3070701
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking
make -j4
make install
cd ../

# freetype
wget http://download.savannah.gnu.org/releases/freetype/freetype-2.4.6.tar.bz2
tar xvf freetype-2.4.6.tar.bz2
cd freetype-2.4.6
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking
make -j4
make install
cd ../

# proj4
wget http://download.osgeo.org/proj/proj-datumgrid-1.5.zip
#wget http://download.osgeo.org/proj/proj-4.7.0.tar.gz
#tar xvf proj-4.7.0.tar.gz
#cd proj-4.7.0
# we use trunk instead for better threading support
svn co http://svn.osgeo.org/metacrs/proj/trunk/proj proj-trunk # at the time pre-release 4.8.0
cd proj-trunk/nad
unzip ../../proj-datumgrid-1.5.zip
cd ../
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking
make -j4
make install
cd ../

# libpng
wget ftp://ftp.simplesystems.org/pub/libpng/png/src/libpng-1.5.4.tar.gz
tar xvf libpng-1.5.4.tar.gz
cd libpng-1.5.4
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking
make -j4
make install
cd ../

# libjpeg
wget http://www.ijg.org/files/jpegsrc.v8c.tar.gz
tar xvf jpegsrc.v8c.tar.gz
cd jpeg-8c
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking
make -j4
make install
cd ../

# libtiff
wget http://download.osgeo.org/libtiff/tiff-3.9.5.tar.gz
tar xvf tiff-3.9.5.tar.gz
cd tiff-3.9.5
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking
make -j4
make install
cd ../

# gdal 1.8.1
wget http://download.osgeo.org/gdal/gdal-1.8.1.tar.gz
tar xvf gdal-1.8.1.tar.gz
cd gdal-1.8.1
./configure --prefix=$PREFIX --enable-static --disable-shared --disable-dependency-tracking \
--with-libtiff=$PREFIX \
--with-jpeg=$PREFIX \
--with-png=$PREFIX \
--with-static-proj4=$PREFIX \
--with-sqlite3=no \
--with-spatialite=no \
--with-curl=no \
--with-geos=no \
--with-pcraster=no \
--with-cfitsio=no \
--with-odbc=no \
--with-libkml=no \
--with-pcidsk=no \
--with-jasper=no \
--with-gif=no \
--with-pg=no \
--with-hide-internal-symbols=yes \
--with-vfk=no \
--with-grib=no

make -j4
make install
cd ../

# cairo and friends

# pkg-config so we get cairo and friends configured correctly
wget http://pkgconfig.freedesktop.org/releases/pkg-config-0.26.tar.gz
tar xvf pkg-config-0.26.tar.gz
cd pkg-config-0.26
./configure --disable-dependency-tracking --prefix=$PREFIX
make -j4
make install
cd ../

# pixman
wget http://cairographics.org/releases/pixman-0.22.2.tar.gz
tar xvf pixman-0.22.2.tar.gz
cd pixman-0.22.2
./configure --enable-static --disable-shared --disable-dependency-tracking --prefix=$PREFIX
make -j4
make install
cd ../

# fontconfig
wget http://www.freedesktop.org/software/fontconfig/release/fontconfig-2.8.0.tar.gz
tar xvf fontconfig-2.8.0.tar.gz
cd fontconfig-2.8.0
./configure --enable-static --disable-shared --disable-dependency-tracking --prefix=$PREFIX \
    --with-freetype-config=$PREFIX/bin/freetype-config
make -j4
make install
cd ../

# cairo
wget http://cairographics.org/releases/cairo-1.10.2.tar.gz
tar xvf cairo-1.10.2.tar.gz
cd cairo-1.10.2
# NOTE: PKG_CONFIG_PATH must be correctly set by this point
export LDFLAGS="-L$PREFIX/lib "$CORE_LDFLAGS
export CFLAGS="-I$PREFIX/include "$CORE_CFLAGS
export png_CFLAGS="-I$PREFIX/include"
export png_LIBS="-I$PREFIX/lib -lpng"
./configure \
  --enable-static --disable-shared \
  --enable-pdf=yes \
  --enable-ft=yes \
  --enable-png=yes \
  --enable-svg=yes \
  --enable-ps=yes \
  --enable-fc=yes \
  --enable-trace=no \
  --enable-gtk-doc=no \
  --enable-qt=no \
  --enable-quartz=no \
  --enable-quartz-font=no \
  --enable-quartz-image=no \
  --enable-win32=no \
  --enable-win32-font=no \
  --enable-skia=no \
  --enable-os2=no \
  --enable-beos=no \
  --enable-drm=no \
  --enable-drm-xr=no \
  --enable-gallium=no \
  --enable-gl=no \
  --enable-directfb=no \
  --enable-vg=no \
  --enable-egl=no \
  --enable-glx=no \
  --enable-wgl=no \
  --enable-test-surfaces=no \
  --enable-tee=no \
  --enable-xml=no \
  --enable-interpreter=no \
  --disable-valgrind \
  --enable-gobject=no \
  --enable-static=no \
  --enable-xlib=no \
  --enable-xlib-xrender=no \
  --enable-xcb=no \
  --enable-xlib-xcb=no \
  --enable-xcb-shm=no \
  --enable-xcb-drm=no \
  --disable-dependency-tracking \
  --prefix=$PREFIX
make -j4
make install
cd ../

# libsigcxx
wget http://ftp.gnome.org/pub/GNOME/sources/libsigc++/2.2/libsigc++-2.2.10.tar.bz2
tar xvf libsigc++-2.2.10.tar.bz2
cd libsigc++-2.2.10
export CFLAGS=$CORE_CFLAGS
export CXXFLAGS=$CORE_CXXFLAGS
export LDFLAGS=$CORE_LDFLAGS
./configure --enable-static --disable-shared --disable-dependency-tracking --prefix=$PREFIX
make -j4
make install
cd ../

# cairomm
wget http://cairographics.org/releases/cairomm-1.10.0.tar.gz
tar xvf cairomm-1.10.0.tar.gz
cd cairomm-1.10.0
# NOTE: PKG_CONFIG_PATH must be correctly set by this point
export LDFLAGS="-L$PREFIX/lib -lcairo -lfontconfig -lsigc-2.0 "$CORE_LDFLAGS
export CFLAGS="-I$PREFIX/include -I$PREFIX/include/cairo -I$PREFIX/include/freetype2 -I$PREFIX/include/fontconfig -I$PREFIX/lib/sigc++-2.0/include -I$PREFIX/include/sigc++-2.0 -I$PREFIX/include/sigc++-2.0/sigc++ "$CORE_CFLAGS
export CXXFLAGS="-I$PREFIX/include "$CFLAGS

./configure --enable-static --disable-shared \
    --disable-dependency-tracking --prefix=$PREFIX
make -j4
make install

error: pathspec 'osx/scripts/static-universal.sh' did not match any file(s) known to git


Update casks to add macdown and remove brew-cask

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/khornberg/dotfiles.git/'


added original Makefile for http-paraser

#!/bin/sh

# download link for the sources to be stored in dl directory
PKG_DOWNLOAD="https://github.com/nodejs/http-parser/archive/v2.7.1.tar.gz"

# md5 checksum of archive in dl directory
PKG_CHECKSUM="31c6fefb6208b16d19b3f990e71cb04a"

# name of directory after extracting the archive in working directory
PKG_DIR="http-parser-2.7.1"

# name of the archive in dl directory
PKG_ARCHIVE_FILE="${PKG_DIR}.tar.gz"

SCRIPTSDIR="$(dirname $0)"
HELPERSDIR="${SCRIPTSDIR}/helpers"
TOPDIR="$(realpath ${SCRIPTSDIR}/../..)"

. ${TOPDIR}/scripts/common_settings.sh
. ${HELPERSDIR}/functions.sh

PKG_ARCHIVE="${DOWNLOADS_DIR}/${PKG_ARCHIVE_FILE}"
PKG_SRC_DIR="${SOURCES_DIR}/${PKG_DIR}"
PKG_BUILD_DIR="${BUILD_DIR}/${PKG_DIR}"
PKG_INSTALL_DIR="${PKG_BUILD_DIR}/install"

configure()
{
    true
}

compile()
{
    copy_overlay
    cd "${PKG_BUILD_DIR}"
    export CFLAGS="${M3_CFLAGS} -L${STAGING_LIB} -I${STAGING_INCLUDE}"
    export CPPFLAGS="${M3_CFLAGS} -L${STAGING_LIB} -I${STAGING_INCLUDE}"
    export LDFLAGS="${M3_LDFLAGS} -L${STAGING_LIB}"
    export AR="armv7a-hardfloat-linux-gnueabi-ar"
    export CC="armv7a-hardfloat-linux-gnueabi-gcc"
    export PREFIX='$(DESTDIR)'
    make "${M3_MAKEFLAGS}" || exit_failure "failed to build ${PKG_DIR}"
    make DESTDIR="${PKG_INSTALL_DIR}" install
}

install_staging()
{
    cd "${PKG_BUILD_DIR}"
    export CFLAGS="${M3_CFLAGS} -L${STAGING_LIB} -I${STAGING_INCLUDE}"
    export CPPFLAGS="${M3_CFLAGS} -L${STAGING_LIB} -I${STAGING_INCLUDE}"
    export LDFLAGS="${M3_LDFLAGS} -L${STAGING_LIB}"
    export AR="armv7a-hardfloat-linux-gnueabi-ar"
    export CC="armv7a-hardfloat-linux-gnueabi-gcc"
    export PREFIX='$(DESTDIR)'
    make -i DESTDIR="${STAGING_DIR}" install || exit_failure "failed to install ${PKG_DIR}"
}

. ${HELPERSDIR}/call_functions.sh

error: pathspec 'oss_packages/scripts/http-parser-v2.7.1.sh' did not match any file(s) known to git


Make versions global variable, no need to regenerate each time

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/cybeliak/mispronounceableness.git/'


hooks/prepare-32bit: fix shlib-provides detection for subpkgs.

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/Bubble-be/void-packages.git/'


add uninstall mysql from mac

add uninstall mysql from mac

#!/usr/bash
sudo rm /usr/local/mysql
sudo rm -rf /usr/local/mysql*
sudo rm -rf /Library/StartupItems/MySQLCOM
sudo rm -rf /Library/PreferencePanes/My*
# vim /etc/hostconfig  (and removed the line MYSQLCOM=-YES-)
sudo sed -i -e '/MYSQLCOM=-YES-/d' etc/hostconfig
rm -rf ~/Library/PreferencePanes/My*
sudo rm -rf /Library/Receipts/mysql*
sudo rm -rf /Library/Receipts/MySQL*
sudo rm -rf /var/db/receipts/com.mysql.*

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


Adding keychain config

Adding keychain config

if [[ -e `which keychain` ]]; then
  if [ $TMUX ]; then
    eval `keychain --eval`
  fi
fi

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


Create HexMaker.sh

Create HexMaker.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/kapucin28/HexEmbedd_V.git/'


Don't generate the "**/*" file if none find

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/mettatw/probable-octo-guacamole.git/'


Add maintenance script

Add maintenance script

#!/bin/bash

try_failed() {
	# some day, make failure optional, elect to continue with -f?
	echo "[fail] Aborting"
	echo "[fail] Step: $1"
	echo "[fail] Command: $2"
	echo "[fail] Status: $3"
	exit $3
}

try() {
	echo "[command] $1"
	sudo /bin/sh -c "$2"
	R=$?
	if [[ $R -ne 0 ]] ; then
		try_failed "$1" "$2" "$R"
	fi
}

try "Check that we can really run commands" "id -a"
try "Update all packages" "emerge -uDN --with-bdeps=y --complete-graph @world"
try "Rebuild preserved libraries" "emerge @preserved-rebuild"
try "Fix broken reverse-dependencies" "revdep-rebuild"
try "Fix outdated Python modules" "python-updater --enable-all"
try "Fix Perl modules, step 1" "perl-cleaner --modules"
try "Fix Perl modules, step 2" "perl-cleaner --phall"
try "Review patched configuration files" "dispatch-conf"

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


Add mercurial 3.8.1

Add mercurial 3.8.1

The mercurial built by this plan is capable of cloning HTTP and HTTPS
based mercurial repositories.

Depending on your studio setup, you may see the following post-test
failure:

    --- /hab/cache/src/mercurial-3.9.1/tests/test-obsolete.t
    +++ /hab/cache/src/mercurial-3.9.1/tests/test-obsolete.t.err
    @@ -972,8 +972,6 @@

       $ chmod 000 .hg/cache/hidden
       $ hg log -r . -T '{node}' --debug
    -  cannot read hidden cache
    -  error writing hidden changesets cache
       8fd96dfc63e51ed5a8af1bec18eb4b19dbf83812 (no-eol)
     #endif

    ERROR: test-obsolete.t output changed

This fails in containers if the filesystem allows the read on
`.hg/cache/hidden` despite the 000 mode.

A number of other tests are skipped, mostly related to
internationalization and canonical-specific features.

Signed-off-by: Steven Danna <9ce5770b3bb4b2a1d59be2d97e34379cd192299f@chef.io>

pkg_name=mercurial
pkg_origin=core
pkg_version=3.9.1
pkg_description="A free, distributed source control management tool."
pkg_upstream_url="https://www.mercurial-scm.org/"
pkg_license=('GPL-2.0')
pkg_maintainer="The Habitat Maintainers <humans@habitat.sh>"
pkg_source=https://www.mercurial-scm.org/release/mercurial-${pkg_version}.tar.gz
pkg_shasum=625e4fc7e85ec2278c2828bdc547fce74091b3bbe4d9eeeba2d61af51195df74
pkg_deps=(core/glibc core/python2 core/cacerts)
pkg_build_deps=(core/gcc core/make core/python2 core/coreutils core/diffutils core/which)
pkg_lib_dirs=(lib)
pkg_bin_dirs=(bin)

do_build() {
  make build PREFIX="$pkg_prefix"
}

do_install() {
  make install-bin PREFIX="$pkg_prefix"
  install_cacerts
}

do_check() {
  fix_test_interpreters
  make tests PREFIX="$pkg_prefix"
}

install_cacerts() {
  build_line "Writing hgrc with cacerts config"
  mkdir -p "${pkg_prefix}/etc/mercurial"
  cat <<EOF > "${pkg_prefix}/etc/mercurial/hgrc"
[web]
cacerts = $(pkg_path_for cacerts)/ssl/cert.pem
EOF
}

#
# We can't use fix_interpreter here without including
# core/coreutils as a runtime dependency.
#
# For a possible solution see:
#   https://github.com/habitat-sh/habitat/issues/1041
#
fix_test_interpreters() {
  files_to_fix_env=(contrib/check-commit
                    contrib/check-code.py
                    tests/bundles/rebase.sh
                    tests/check-perf-code.py
                    tests/dumbhttp.py
                    tests/dummysmtpd.py
                    tests/dummyssh
                    tests/f
                    tests/filterpyflakes.py
                    tests/get-with-headers.py
                    tests/hghave
                    tests/killdaemons.py
                    tests/md5sum.py
                    tests/printenv.py
                    tests/readlink.py
                    tests/revlog-formatv0.py
                    tests/run-tests.py
                    tests/seq.py
                    tests/svn-safe-append.py
                    tests/test-bisect.t
                    tests/test-extdiff.t
                    tests/test-extension.t
                    tests/test-filelog.py
                    tests/test-highlight.t
                    tests/test-largefiles-cache.t
                    tests/test-merge-symlinks.t
                    tests/test-newcgi.t
                    tests/test-newercgi.t
                    tests/test-oldcgi.t
                    tests/test-run-tests.t
                    tests/test-status-inprocess.py
                    tests/tinyproxy.py)

  interpreter_old="/usr/bin/env"
  interpreter_new="$(pkg_path_for coreutils)/bin/env"

  for f in "${files_to_fix_env[@]}"; do
    build_line "Fixing interpreter on $f"
    sed -e "s#\#\!${interpreter_old}#\#\!${interpreter_new}#" -i "$f"
  done
}

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


updates

updates

# https://docs.docker.com/installation/centos/
sudo yum install docker

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


Travis: Use new javadoc directory

Travis: Use new javadoc directory

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/arashahmadi/sensemi_ai.git/'


Zydis: Enable assertions during fuzzing (#6404)

Related PR in Zydis: https://github.com/zyantific/zycore-c/pull/29

#!/bin/bash -eu
# Copyright 2020 Google Inc.
#
# 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.
#
################################################################################

mv $SRC/ZydisFuzz_seed_corpus.zip $OUT/ZydisFuzz_seed_corpus.zip

mkdir build && cd build

cmake                                   \
    -DZYAN_FORCE_ASSERTS=ON             \
    -DZYDIS_BUILD_EXAMPLES=OFF          \
    -DZYDIS_BUILD_TOOLS=OFF             \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo   \
    -DCMAKE_C_COMPILER=$CC              \
    -DCMAKE_CXX_COMPILER=$CXX           \
    -DCMAKE_C_FLAGS="$CFLAGS"           \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS"       \
    ..

make -j$(nproc) VERBOSE=1

$CXX                                    \
    $CXXFLAGS                           \
    $LIB_FUZZING_ENGINE                 \
    ../tools/ZydisFuzzIn.c              \
    -DZYDIS_LIBFUZZER                   \
    -o $OUT/ZydisFuzz                   \
    -I .                                \
    -I ./zycore                         \
    -I ../include                       \
    -I ../dependencies/zycore/include   \
    ./libZydis.a

#!/bin/bash -eu
# Copyright 2020 Google Inc.
#
# 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.
#
################################################################################

mv $SRC/ZydisFuzz_seed_corpus.zip $OUT/ZydisFuzz_seed_corpus.zip

mkdir build && cd build

cmake                                   \
    -DZYDIS_BUILD_EXAMPLES=OFF          \
    -DZYDIS_BUILD_TOOLS=OFF             \
    -DCMAKE_BUILD_TYPE=RelWithDebInfo   \
    -DCMAKE_C_COMPILER=$CC              \
    -DCMAKE_CXX_COMPILER=$CXX           \
    -DCMAKE_C_FLAGS="$CFLAGS"           \
    -DCMAKE_CXX_FLAGS="$CXXFLAGS"       \
    ..

make -j8

$CXX                                    \
    $CXXFLAGS                           \
    $LIB_FUZZING_ENGINE                 \
    ../tools/ZydisFuzzIn.c              \
    -DZYDIS_LIBFUZZER                   \
    -o $OUT/ZydisFuzz                   \
    -I .                                \
    -I ./zycore                         \
    -I ../include                       \
    -I ../dependencies/zycore/include   \
    ./libZydis.a


Add run chrome script

Add run chrome script

while true; do
     chromium-browser --kiosk http://localhost:8080 --no-first-run --touch-events=enabled --fast --fast-start --disable-popup-blocking --disable-infobars --disable-session-crashed-bubble --disable-tab-switcher --disable-translate --enable-low-res-tiling --noerrdalogs
     sleep 10s;
done

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


added the shell file, so that it actually works now

#!/bin/bash
rm db.sqlite3; #deletes the database file.
rm -rf task/migrations; #deletes the migrations folder.
python manage.py migrate; #run the initial django migration to create all the initial tables. need this step because we are killing the database just above
python manage.py makemigrations task; #creates the migration.
python manage.py migrate task; #runs the migration.  This will delete all of the data in your database.

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


add some file

add some file

git add *
git commit -a -m 'add some file'
git push -u orign master

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


Add cask-remove-old-versions.sh

Add cask-remove-old-versions.sh

#!/bin/bash
# cask-remove-old-versions.sh

set i = 0

for folder in /opt/homebrew-cask/Caskroom/*
do
	for version in $folder/*
	do
		let "i++"
	done

	if [ $i -gt 1 ]; then
		# reverse sort so NR>2 skips "total" & current version
		echo "Removing old cask $folder"
		ls -lr $folder | awk -v d="$folder/" '(NR>2) {print d $9}' | xargs -L1 rm -fr
	fi

	let "i=0"
done

error: pathspec 'scripts/cask-remove-old-versions.sh' did not match any file(s) known to git


scripts: add create-uninstalled-setup script

Little script that sets up things in ~/gst and clones
the main modules and prints some instructions.

From http://gstreamer.freedesktop.org/wiki/UninstalledSetup

#!/bin/sh
# ----------------------------------------------------------------------------
#
# create-uninstalled-setup.sh
#
# Little shell script that creates a fresh GStreamer uninstalled setup in
# your home directory.
#
# ----------------------------------------------------------------------------
#
# Copyright (C) 2011-2012 Tim-Philipp Muller <tim centricular net>
#
# This script is free software; you can redistribute it and/or
# modify it under the terms of the GNU Library General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library 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
# Library General Public License for more details.
#
# You should have received a copy of the GNU Library General Public
# License along with this library; if not, write to the
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
# Boston, MA 02111-1307, USA.
#
# ----------------------------------------------------------------------------

set -e

# set BRANCH to "0.10" for a GStreamer 0.10.x checkout
BRANCH="master"

# set to "ssh" if you have a developer account and ssh access
GIT_ACCESS="anongit"

# git modules to clone
MODULES="gstreamer gst-plugins-base gst-plugins-good gst-plugins-ugly gst-plugins-bad gst-ffmpeg"

# note: we use ~/gst because that's what the gst-uninstalled script
# uses by default, so don't just change that to something else
UNINSTALLED_ROOT=~/gst

echo "==========================================================================================="
echo "Creating new GStreamer uninstalled environment for branch $BRANCH in $UNINSTALLED_ROOT ... "
echo "==========================================================================================="

mkdir -p $UNINSTALLED_ROOT
mkdir -p $UNINSTALLED_ROOT/$BRANCH

mkdir -p $UNINSTALLED_ROOT/$BRANCH/prefix

cd $UNINSTALLED_ROOT/$BRANCH

for m in $MODULES
do
  if test "$GIT_ACCESS" = "ssh"; then
    git clone ssh://git.freedesktop.org/gstreamer/$m
  else
    git clone git://anongit.freedesktop.org/gstreamer/$m
  fi

  cd $m
  if test "$BRANCH" != "master"; then
    git checkout -b $BRANCH origin/$BRANCH
  fi
  cd ..
done

cd $UNINSTALLED_ROOT
ln -s $BRANCH/gstreamer/scripts/gst-uninstalled gst-$BRANCH
chmod +x gst-$BRANCH

cd ~

echo "==========================================================================================="
echo
echo "Done. Created new GStreamer uninstalled environment for branch $BRANCH in $UNINSTALLED_ROOT"
echo
echo "To enter the uninstalled environment do: cd $UNINSTALLED_ROOT; ./gst-$BRANCH"
echo
echo "To leave the uninstalled environment do: exit"
echo
echo "To check the uninstalled environment do: printenv | grep GST"
echo "    (loads of output = you're in the uninstalled environment)"
echo
echo "==========================================================================================="
echo
echo "Now compile all GStreamer modules one by one by first switching into"
echo "the uninstalled environment and then doing:"
echo
echo "    cd <MODULE>; ./autogen.sh; make"
echo
echo "First gstreamer, then gst-plugins-base, then the other modules."
echo "You do not need to do 'make install'"
echo
echo "==========================================================================================="
echo
echo "If your system GLib is too old, you can install a newer version"
echo "into --prefix=$UNINSTALLED_ROOT/$BRANCH/prefix and it should be picked up"
echo "by autogen.sh/configure"
echo
echo "==========================================================================================="
echo
echo "Also see http://gstreamer.freedesktop.org/wiki/UninstalledSetup
echo
echo "==========================================================================================="

error: pathspec 'scripts/create-uninstalled-setup.sh' did not match any file(s) known to git


Script for generating changelogs.

Script for generating changelogs.

#!/bin/sh

git log $1...$2 --pretty=format:'+ [view commit](http://github.com/dylanfprice/angular-gm/commit/%H) • %s ' --reverse | grep -v Merge

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


repo: added version bumper script

repo: added version bumper script

# get version from argument
VERSION=`git branch | sed -En "s/.*release\/v(.*)/\1/p"`

# update docker images
sed -Ei "s/[0-9]\.[0-9]\.[0-9]/${VERSION}/" ./docker-compose.prod.yml

# update web
sed -Ei "/version/s/[0-9]\.[0-9]\.[0-9]/${VERSION}/" ./web/package.json

# update api
sed -Ei "/version/s/[0-9]\.[0-9]\.[0-9]/${VERSION}/" ./api/package.json

# update mobile
sed -Ei "/version/s/[0-9]\.[0-9]\.[0-9]/${VERSION}/" ./mobile/package.json
sed -Ei "/version/s/[0-9]\.[0-9]\.[0-9]/${VERSION}/" ./mobile/app.json

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


Add zsh fzf search hidden dirs via ag

Add zsh fzf search hidden dirs via ag

# FZF extra configuration
#
# Search dot files with ag
export FZF_DEFAULT_COMMAND='ag --hidden --ignore .git -l -g ""'

error: pathspec 'zsh/.config/zshenv/fzf.zsh' did not match any file(s) known to git


created shell to check code format

created shell to check code format

#!/bin/bash -e

# Copyright 2012 gandalf authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.

status=0
out=`gofmt -s -l .`
if [ "${out}" != "" ]
then
    echo "ERROR: there are files that need to be formatted with gofmt"
    echo
    echo "Files:"
    for file in $out
    do
        echo "- ${file}"
    done
    status=1
fi

`go vet ./... > .vet 2>&1`
out=`cat .vet`
if [ "${out}" != "" ]
then
    echo "ERROR: go vet failures:"
    echo
    cat <<END
${out}
END
    status=1
fi

rm .vet || /bin/true
exit $status

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


new theme/syntax, rm unused pkgs

new theme/syntax, rm unused pkgs

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/nhejazi/installPkgs.git/'


feature: create a docker-compose down binstub

#!/usr/bin/env bash

set -e

docker-compose down
docker system prune -a -f

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


Use cygpath to convert windows paths

Use cygpath to convert windows paths

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/plicease/libffi.git/'


*autoload: Prevent pager from being run on update/update-all

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/psprint/zplugin.git/'


remove nginx.sh

remove nginx.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/ontouchstart/docker-github-pages-base.git/'


Add script to start nginx

Add script to start nginx

#!/bin/bash

docker run --name docker-nginx -p 80:80 -v ~/html:/usr/share/nginx/html -v ./default.conf:/etc/nginx/conf.d/default.conf -d nginx

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


Create elasticSearchNow

Create elasticSearchNow

ElasticSearch StartUp

1.  Install ElasticSearch
2.  Install plugins -kopf or head, javascript and python (optional)
3.  Create an index by running the command:
--the name of the index, crux, can be anything you want
curl -XPUT http://localhost:9200/crux -d '{
    "settings" : {
        "index" : {
            "number_of_shards" : 2,
            "number_of_replicas" : 1
        }
    }
}'

4.  Verify the index is created.
5.  Run the create index command again.  An error should be returned:
  E.g.: {"error":"IndexAlreadyExistsException[[crux] already exists]","status":400}

6.  Create an index with mappings:

curl -XPOST localhost:9200/yaba -d '{ "settings" : { "number_of_shards" : 2,
        "number_of_replicas" : 1    },    "mappings" : { "order" : { "properties" : {
              "id" : {"type" : "string", "store" : "yes" , "index":"not_analyzed"},
              "date" : {"type" : "date", "store" : "no" , "index":"not_analyzed"},
              "customer_id" : {"type" : "string", "store" : "yes" , "index":"not_analyzed"},
              "sent" : {"type" : "boolean", "index":"not_analyzed"},
              "name" : {"type" : "string", "index":"analyzed"},
              "quantity" : {"type" : "integer", "index":"not_analyzed"},
              "vat" : {"type" : "double", "index":"no"}
          }
      }
  }
}'
7.  Delete an index: *** CAUTION: cannot be reversed if index backup does not exists ***
  curl -XDELETE http://localhost:9200/{existing_index_name}
  -should get an acknowledged true response.   Http 404 is returned for non-existing index
8.  Closing an index:
  curl -XPOST http://localhost:9200/{existing_index_name}/_close
    -should get an acknowledged true response
9.  Open a closed index:
  curl -XPOST http://localhost:9200/{existing_index_name}/_open
    - should get an acknowledged true response
10.  Rivers  - are ElasticSearch services that pulls/get data into ElasticSearch.  Compartible data sources include
  CouchDB, MongoDB, RabbitMQ, SQL DBMS (Oracle, MySQL, PostgreSQL etc), Redis, Twitter, Wikipedia
11.  To create a river, run a command like this :
   curl -XPUT 'http://localhost:9200/_river/benue/_meta' -d  '{"type": "dummy"}'
    --should get an OK:true response
12.

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


feat: 打包脚本

feat: 打包脚本

#!/bin/bash
#set -x
mvn clean install deploy -Dmaven.test.skip=true -Ddbinit.skip -Pjdk18
mv -f target/*.zip .

mvn clean install deploy -Dmaven.test.skip=true -Ddbinit.skip -Pjdk17
mv -f target/*.zip .

mvn clean install deploy -Dmaven.test.skip=true -Ddbinit.skip -Pjdk16
mv -f target/*.zip .

md5 *.zip
du -h *.zip

# package(){
# 	mvn clean install deploy -Dmaven.test.skip=true -Ddbinit.skip -Pjdk18
# 	$filename = `ls target/*.zip`

# 	mv -f target/*.zip .

# 	echo "Package for ${app_name}"
# }

exit 0

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


Add shell script for packaging JAR file

Add shell script for packaging JAR file

git-svn-id: 464247b772b47fb892ddc6c4a897645d921924ed@67 43b03309-50c7-4bd2-8aa6-20f049331b16

#!/bin/sh
cd $(dirname $0)/bin
jar -cvf ../j2mod.jar $(find . -name '*.class')


Update package.sh

Update package.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/electron226/Tab-Position-Configure.git/'


updated deploy script

updated deploy 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/Vidal-ru/Vidal.git/'


touch

touch

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


[1347][test.sh] Update

[1347][test.sh] Update

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/Fiware/data.Cygnus.git/'


added unix/grep-file-type.sh

added unix/grep-file-type.sh

#!/bin/sh

# Required arguments:
#   $1: Relative path to the directory
#         in which to grep.
#   $2: File extension to grep.
#   $3: String to grep.
#
# Example: sh grep-file-type.sh target/directory ".sh" "string"

# Check if at least 3 arguments were passed.
if [ $# -lt 3 ]
then
    echo 'Missing arguments.'
    exit 2
fi

# Navigate to the target directory.
cd $1

# grep.
grep -l -r --include $2 $3 .

error: pathspec 'unix/grep-file-type.sh' did not match any file(s) known to git


fix install django-admin-tools with pip 1.5

#!/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
#

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

#Install mode can me either CLONE or DOWNLOAD
INSTALL_MODE='CLONE'
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 --allow-all-external --allow-unverified django-admin-tools
    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

    #Load Countries Dialcode
    #python manage.py load_country_dialcode

    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

    case $INSTALL_MODE in
        'CLONE')
            git clone git://github.com/Star2Billing/newfies-dialer.git
            #Install Develop / Master
            if echo $BRANCH | grep -i "^develop" > /dev/null ; then
                cd newfies-dialer
                git checkout -b develop --track origin/develop
            fi
        ;;
    esac

    #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/master/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 on your server"
    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
    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
#

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

#Install mode can me either CLONE or DOWNLOAD
INSTALL_MODE='CLONE'
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

    #Load Countries Dialcode
    #python manage.py load_country_dialcode

    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

    case $INSTALL_MODE in
        'CLONE')
            git clone git://github.com/Star2Billing/newfies-dialer.git
            #Install Develop / Master
            if echo $BRANCH | grep -i "^develop" > /dev/null ; then
                cd newfies-dialer
                git checkout -b develop --track origin/develop
            fi
        ;;
    esac

    #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/master/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 on your server"
    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
    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
}


Only upload necessary dist files

Only upload necessary dist files

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/chbfiv/fabric-engine-old.git/'


New version.

New version.

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/webintrinsics/clusterlite.git/'


Add colored man plugin.

Add colored man plugin.

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/yukimemi/oh-my-zsh.git/'


Add colored man plugin.

Add colored man plugin.

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/joeylomanto/oh-my-zsh.git/'


fix: next(lcms)

fix: next(lcms)

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/takeutch-kemeco/private-build-script.git/'


update: next(libksba)

update: next(libksba)


update: next(autoconf-archive)

update: next(autoconf-archive)