<commit_before>#!/bin/bash
##### NOVA AGENT BUILDER
##### how_to:$ sh nova-agent-builder.sh help
##### W.I.P. works fine for most of cases,
#####   needs some updates for RHEL & OpenSuse support

##### Fixing LANG for nodes where it ain't
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="UTF-8"
export LANG="en_US.UTF-8"

##### Var
INSTALL_PIP='easy_install pip'
PIP='pip'

NOVA_AGENT_REPO='git://github.com/rackerlabs/openstack-guest-agents-unix.git'
BASE_DIR="/tmp/test_nova_agent"
REPO_DIR='nova-agent'

SYSTEM_NOVA_AGENT='/usr/share/nova-agent'
BACKUP_NOVA_AGENT=$SYSTEM_NOVA_AGENT".original"

NOVA_AGENT_BINTAR="$HOME/nova-agent/artifacts"
##### Functions
shout(){
  echo "***************************************************"
  echo $1
  echo "***************************************************"
}

patchelf_git(){
  shout "installing PatchElf from Git"
  PATCHELF_DIR='/tmp/patchelf'
  CURR_DIR=`pwd`
  if [ -d $PATCHELF_DIR ]; then
    cd $PATCHELF_DIR
    git checkout .
    git pull
  else
    git clone https://github.com/NixOS/patchelf.git $PATCHELF_DIR
    cd $PATCHELF_DIR
  fi
  sh bootstrap.sh
  ./configure
  make
  make install
  cd $CURR_DIR
}

python_module_installer()
{
  shout "Install required modules"

  if [ `which pip > /dev/null 2>&1 ; echo $?` -ne 0 ]; then
    shout "Installing PIP using: $INSTALL_PIP"
    `$INSTALL_PIP`
  fi

  `$PIP install pycrypto`
  `$PIP install pyxenstore`
  `$PIP install unittest2`
  `$PIP install mox`
}

major_version(){
  export OS_VERSION=`cat $RELEASE_FILE | sed 's/[^0-9.]*//g'`
  export OS_VERSION_MAJOR=`echo $OS_VERSION | awk -F'.' '{print $1}'`
}

get_epel_repo(){
  shout "enabling EPEL repo"
  major_version
  EPEL_URI='http://epel.mirror.net.in/epel'
  if [ $OS_VERSION_MAJOR -eq 6 ]; then
    EPEL_URI=$EPEL_URI"/6/i386/epel-release-6-8.noarch.rpm"
  elif [ $OS_VERSION_MAJOR -eq 5 ]; then
    EPEL_URI=$EPEL_URI"/5/i386/epel-release-5-4.noarch.rpm"
  else
    shout "This version isn't supported." && exit 1
  fi

  EPEL_RPM='/tmp/epel-6.8.rpm'
  curl -L -o $EPEL_RPM $EPEL_URI
  rpm -ivh $EPEL_RPM && yum repolist
}

# for distros: RedHat, CentOS, Fedora
install_pre_requisite_redhat(){
  export RELEASE_FILE='/etc/redhat-release'
  cat $RELEASE_FILE

  get_epel_repo

  yum -y install git autoconf gcc gcc-c++ make automake libtool
  yum -y install python-crypto python-devel

  yum install -y centos-release-xen.x86_64 &&  yum repolist
  yum install -y xen-devel
  patchelf_git

  INSTALL_PIP='yum -y install python-pip'
  PIP='python-pip'
  python_module_installer
}

# for distros: Debian, Ubuntu
install_pre_requisite_debian(){
  export RELEASE_FILE='/etc/debian_version'
  cat $RELEASE_FILE
  apt-get -y update
  apt-get -y install git curl
  apt-get -y install autoconf make automake build-essential python-cjson libxen-dev
  apt-get -y install python-anyjson python-pip python-crypto libtool python-dev
  patchelf_git

  INSTALL_PIP='apt-get install -y python-pip'
  python_module_installer
}

# for distros: Gentoo
install_pre_requisite_gentoo(){
  export RELEASE_FILE='/etc/gentoo-release'
  cat $RELEASE_FILE

  emerge git autoconf
  emerge patchelf

  INSTALL_PIP='emerge dev-python/pip'
  python_module_installer
}

# for distros: ArchLinux
install_pre_requisite_archlinux(){
  export RELEASE_FILE='/etc/arch-release'
  cat $RELEASE_FILE

  pacman -Sc --noconfirm
  pacman -Sy --noconfirm git autoconf patchelf python-pip

  python_module_installer
}

# for distros: FreeBSD
install_pre_requisite_freebsd(){
    uname -a

    pkg_add -r git autogen automake wget
    pkg_add -r py27-unittest2 py27-cryptkit py27-pycrypto py27-mox

    # re-install xen-tool :: required for pyxenstore install
    cd /usr/ports/sysutils/xen-tools
    make reinstall
    cp  /usr/ports/sysutils/xen-tools/work/xen-4.1.3/tools/xenstore/libxenstore.so  /usr/lib
    cp /usr/ports/sysutils/xen-tools/work/xen-4.1.3/tools/xenstore/xs.h /usr/local/include/python2.7/
    cp /usr/ports/sysutils/xen-tools/work/xen-4.1.3/tools/xenstore/xs_lib.h /usr/local/include/python2.7/
    mkdir -p /usr/local/include/python2.7/xen/io
    cp /usr/ports/sysutils/xen-tools/work/xen-4.1.3/xen/include/public/io/xs_wire.h /usr/local/include/python2.7/xen/io/
    cd -

    # installing pyxenstore
    cd /tmp
    wget --no-check-certificate https://pypi.python.org/packages/source/p/pyxenstore/pyxenstore-0.0.2.tar.gz
    tar zvxf pyxenstore-0.0.2.tar.gz
    cd pyxenstore-0.0.2
    python setup.py install
    cd -

    alias make='gmake' # patchelf and nova-agent require 'gmake' instead of 'make'
    patchelf_git
}

install_pre_requisite(){
  if [ -f /etc/redhat-release ]; then
    install_pre_requisite_redhat

  elif [ -f /etc/debian_version ]; then
    install_pre_requisite_debian

  elif [ -f /etc/gentoo-release ]; then
    install_pre_requisite_gentoo

  elif [ -f /etc/arch-release ]; then
    install_pre_requisite_archlinux

  elif [ `uname -s` == 'FreeBSD' ] ; then<commit_msg>nova-agent-builder.sh updated FreeBSD make=>gmake to function, alias not working for default shell<commit_after>#!/bin/bash
##### NOVA AGENT BUILDER
##### how_to:$ sh nova-agent-builder.sh help
##### W.I.P. works fine for most of cases,
#####   needs some updates for RHEL & OpenSuse support

##### Fixing LANG for nodes where it ain't
export LANGUAGE="en_US.UTF-8"
export LC_ALL="en_US.UTF-8"
export LC_CTYPE="UTF-8"
export LANG="en_US.UTF-8"

##### Var
INSTALL_PIP='easy_install pip'
PIP='pip'

NOVA_AGENT_REPO='git://github.com/rackerlabs/openstack-guest-agents-unix.git'
BASE_DIR="/tmp/test_nova_agent"
REPO_DIR='nova-agent'

SYSTEM_NOVA_AGENT='/usr/share/nova-agent'
BACKUP_NOVA_AGENT=$SYSTEM_NOVA_AGENT".original"

NOVA_AGENT_BINTAR="$HOME/nova-agent/artifacts"
##### Functions
shout(){
  echo "***************************************************"
  echo $1
  echo "***************************************************"
}

patchelf_git(){
  shout "installing PatchElf from Git"
  PATCHELF_DIR='/tmp/patchelf'
  CURR_DIR=`pwd`
  if [ -d $PATCHELF_DIR ]; then
    cd $PATCHELF_DIR
    git checkout .
    git pull
  else
    git clone https://github.com/NixOS/patchelf.git $PATCHELF_DIR
    cd $PATCHELF_DIR
  fi
  sh bootstrap.sh
  ./configure
  make
  make install
  cd $CURR_DIR
}

python_module_installer()
{
  shout "Install required modules"

  if [ `which pip > /dev/null 2>&1 ; echo $?` -ne 0 ]; then
    shout "Installing PIP using: $INSTALL_PIP"
    `$INSTALL_PIP`
  fi

  `$PIP install pycrypto`
  `$PIP install pyxenstore`
  `$PIP install unittest2`
  `$PIP install mox`
}

major_version(){
  export OS_VERSION=`cat $RELEASE_FILE | sed 's/[^0-9.]*//g'`
  export OS_VERSION_MAJOR=`echo $OS_VERSION | awk -F'.' '{print $1}'`
}

get_epel_repo(){
  shout "enabling EPEL repo"
  major_version
  EPEL_URI='http://epel.mirror.net.in/epel'
  if [ $OS_VERSION_MAJOR -eq 6 ]; then
    EPEL_URI=$EPEL_URI"/6/i386/epel-release-6-8.noarch.rpm"
  elif [ $OS_VERSION_MAJOR -eq 5 ]; then
    EPEL_URI=$EPEL_URI"/5/i386/epel-release-5-4.noarch.rpm"
  else
    shout "This version isn't supported." && exit 1
  fi

  EPEL_RPM='/tmp/epel-6.8.rpm'
  curl -L -o $EPEL_RPM $EPEL_URI
  rpm -ivh $EPEL_RPM && yum repolist
}

# for distros: RedHat, CentOS, Fedora
install_pre_requisite_redhat(){
  export RELEASE_FILE='/etc/redhat-release'
  cat $RELEASE_FILE

  get_epel_repo

  yum -y install git autoconf gcc gcc-c++ make automake libtool
  yum -y install python-crypto python-devel

  yum install -y centos-release-xen.x86_64 &&  yum repolist
  yum install -y xen-devel
  patchelf_git

  INSTALL_PIP='yum -y install python-pip'
  PIP='python-pip'
  python_module_installer
}

# for distros: Debian, Ubuntu
install_pre_requisite_debian(){
  export RELEASE_FILE='/etc/debian_version'
  cat $RELEASE_FILE
  apt-get -y update
  apt-get -y install git curl
  apt-get -y install autoconf make automake build-essential python-cjson libxen-dev
  apt-get -y install python-anyjson python-pip python-crypto libtool python-dev
  patchelf_git

  INSTALL_PIP='apt-get install -y python-pip'
  python_module_installer
}

# for distros: Gentoo
install_pre_requisite_gentoo(){
  export RELEASE_FILE='/etc/gentoo-release'
  cat $RELEASE_FILE

  emerge git autoconf
  emerge patchelf

  INSTALL_PIP='emerge dev-python/pip'
  python_module_installer
}

# for distros: ArchLinux
install_pre_requisite_archlinux(){
  export RELEASE_FILE='/etc/arch-release'
  cat $RELEASE_FILE

  pacman -Sc --noconfirm
  pacman -Sy --noconfirm git autoconf patchelf python-pip

  python_module_installer
}

# for distros: FreeBSD
install_pre_requisite_freebsd(){
    uname -a

    pkg_add -r git autogen automake wget
    pkg_add -r py27-unittest2 py27-cryptkit py27-pycrypto py27-mox

    # re-install xen-tool :: required for pyxenstore install
    cd /usr/ports/sysutils/xen-tools
    make reinstall
    cp  /usr/ports/sysutils/xen-tools/work/xen-4.1.3/tools/xenstore/libxenstore.so  /usr/lib
    cp /usr/ports/sysutils/xen-tools/work/xen-4.1.3/tools/xenstore/xs.h /usr/local/include/python2.7/
    cp /usr/ports/sysutils/xen-tools/work/xen-4.1.3/tools/xenstore/xs_lib.h /usr/local/include/python2.7/
    mkdir -p /usr/local/include/python2.7/xen/io
    cp /usr/ports/sysutils/xen-tools/work/xen-4.1.3/xen/include/public/io/xs_wire.h /usr/local/include/python2.7/xen/io/
    cd -

    # installing pyxenstore
    cd /tmp
    wget --no-check-certificate https://pypi.python.org/packages/source/p/pyxenstore/pyxenstore-0.0.2.tar.gz
    tar zvxf pyxenstore-0.0.2.tar.gz
    cd pyxenstore-0.0.2
    python setup.py install
    cd -

    # patchelf and nova-agent require 'gmake' instead of 'make'
    #  on default shell on FreeBSD `alias make='gmake'` doesn't work
    function make(){
      gmake $@
    }

    patchelf_git
}

install_pre_requisite(){
  if [ -f /etc/redhat-release ]; then
    install_pre_requisite_redhat

  elif [ -f /etc/debian_version ]; then
    install_pre_requisite_debian

  elif [ -f /etc/gentoo-release ]; then
    install_pre_requisite_gentoo

  elif [ -f /etc/arch-release ]; then
    install_pre_requisite_archlinux

  elif [ `uname -s` == 'FreeBSD' ] ; then
{'fraction_non_alphanumeric': 0.14240506329113925, 'fraction_numerical': 0.014042721518987342, 'mean_word_length': 3.677613320999075, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 8, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2200532', 'n_tokens_mistral': 4203, 'n_tokens_neox': 3925, 'n_words': 794}