osquery-1/tools/provision.sh

449 lines
11 KiB
Bash
Raw Normal View History

2014-09-24 05:14:28 +00:00
#!/usr/bin/env bash
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
2014-09-20 23:26:40 +00:00
WORKING_DIR="$SCRIPT_DIR/../.sources"
export PATH="$PATH:/usr/local/bin"
source "$SCRIPT_DIR/lib.sh"
# cmake
# downloads: http://www.cmake.org/download/
function install_cmake() {
2014-10-02 17:58:56 +00:00
if [ "$OS" = "centos" ] || [ "$OS" = "ubuntu" ] || [ "$OS" = "darwin" ]; then
if [[ ! -f cmake-2.8.12.2.tar.gz ]]; then
log "downloading the cmake source"
wget http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
fi
if [[ ! -d cmake-2.8.12.2 ]]; then
log "unpacking the cmake source"
tar -xf cmake-2.8.12.2.tar.gz
fi
if [[ -f /usr/local/bin/cmake ]]; then
log "cmake is already installed. skipping."
else
log "building cmake"
pushd cmake-2.8.12.2 > /dev/null
CC=clang CXX=clang++ ./configure
make
2014-10-02 23:46:32 +00:00
sudo make install
popd
fi
fi
}
function install_thrift() {
2014-09-23 02:27:19 +00:00
if [[ ! -f /usr/local/lib/libthrift.a ]]; then
if [[ ! -f 0.9.1.tar.gz ]]; then
wget https://github.com/apache/thrift/archive/0.9.1.tar.gz
fi
if [[ ! -d thrift-0.9.1 ]]; then
tar -xf 0.9.1.tar.gz
fi
pushd thrift-0.9.1
./bootstrap.sh
./configure --with-cpp=yes --with-ruby=no --with-go=no --with-erlang=no --with-java=no --with-python=no
make
2014-09-25 07:27:07 +00:00
sudo make install
popd
else
log "thrift is installed. skipping."
fi
}
function install_rocksdb() {
if [[ ! -f /usr/local/lib/librocksdb.a ]]; then
if [[ ! -f rocksdb-3.5.tar.gz ]]; then
wget https://github.com/facebook/rocksdb/archive/rocksdb-3.5.tar.gz
fi
if [[ ! -d rocksdb-rocksdb-3.5 ]]; then
tar -xf rocksdb-3.5.tar.gz
2014-09-20 23:36:04 +00:00
fi
if [ "$OS" = "ubuntu" ] || [ "$OS" = "centos" ]; then
if [[ ! -f rocksdb-rocksdb-3.5/librocksdb.a ]]; then
if [[ $OS = "ubuntu" ]]; then
CLANG_INCLUDE="-I/usr/include/clang/3.4/include"
elif [[ $OS = "centos" ]]; then
CLANG_VERSION=`clang --version | grep version | cut -d" " -f3`
CLANG_INCLUDE="-I/usr/lib/clang/$CLANG_VERSION/include"
fi
pushd rocksdb-rocksdb-3.5
make static_lib CFLAGS="$CLANG_INCLUDE"
popd
fi
2014-09-25 07:27:07 +00:00
sudo cp rocksdb-rocksdb-3.5/librocksdb.a /usr/local/lib
sudo cp -R rocksdb-rocksdb-3.5/include/rocksdb /usr/local/include
elif [[ $OS = "darwin" ]]; then
if [[ ! -f rocksdb-rocksdb-3.5/librocksdb.a ]]; then
pushd rocksdb-rocksdb-3.5
make static_lib
popd
fi
sudo cp rocksdb-rocksdb-3.5/librocksdb.a /usr/local/lib
sudo cp -R rocksdb-rocksdb-3.5/include/rocksdb /usr/local/include
fi
else
log "rocksdb already installed. skipping."
fi
}
function install_boost() {
if [[ ! -f /usr/local/lib/libboost_thread.a ]]; then
if [[ ! -f boost_1_55_0.tar.gz ]]; then
wget -O boost_1_55_0.tar.gz http://sourceforge.net/projects/boost/files/boost/1.55.0/boost_1_55_0.tar.gz/download
2014-09-20 23:42:20 +00:00
else
log "boost source is already downloaded. skipping."
2014-09-20 23:42:20 +00:00
fi
if [[ ! -d boost_1_55_0 ]]; then
tar -xf boost_1_55_0.tar.gz
fi
pushd boost_1_55_0
./bootstrap.sh
n=`getconf _NPROCESSORS_ONLN`
sudo ./b2 --with=all -j $n toolset=clang install
sudo ldconfig
popd
else
log "boost library is already installed. skipping."
fi
}
function install_gflags() {
if [[ ! -f /usr/local/lib/libgflags.a ]]; then
if [[ ! -f v2.1.1.tar.gz ]]; then
wget https://github.com/schuhschuh/gflags/archive/v2.1.1.tar.gz
2014-09-20 23:26:40 +00:00
else
log "gflags source is already downloaded. skipping."
2014-09-20 23:26:40 +00:00
fi
if [[ ! -d gflags-2.1.1 ]]; then
tar -xf v2.1.1.tar.gz
2014-09-20 23:36:04 +00:00
fi
pushd gflags-2.1.1
cmake -DCMAKE_CXX_FLAGS=-fPIC -DGFLAGS_NAMESPACE:STRING=google .
make
sudo make install
popd
else
log "gflags library is already installed. skipping."
fi
}
function install_glog() {
if [[ ! -d /usr/local/include/glog ]]; then
if [[ ! -f glog-0.3.3.tar.gz ]]; then
wget https://google-glog.googlecode.com/files/glog-0.3.3.tar.gz
2014-09-20 23:26:40 +00:00
else
log "glog source is already downloaded. skipping."
fi
if [[ ! -d glog-0.3.3 ]]; then
tar -xf glog-0.3.3.tar.gz
2014-09-20 23:26:40 +00:00
fi
pushd glog-0.3.3
./configure CXXFLAGS="-DGFLAGS_NAMESPACE=google"
make
sudo make install
popd
else
log "glog is already installed. skipping."
fi
}
function install_autoconf() {
if [[ ! -f /usr/bin/autoconf ]]; then
if [[ ! -f autoconf-2.69.tar.gz ]]; then
wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
else
log "autoconf is already downloaded. skipping."
fi
if [[ ! -d autoconf-2.69 ]]; then
tar -xf autoconf-2.69.tar.gz
fi
pushd autoconf-2.69
./configure --prefix=/usr
make
sudo make install
popd
else
log "autoconf is already installed. skipping."
fi
}
function install_automake() {
if [[ ! -f /usr/bin/automake ]]; then
if [[ ! -f automake-1.14.tar.gz ]]; then
wget http://ftp.gnu.org/gnu/automake/automake-1.14.tar.gz
else
log "automake is already downloaded. skipping."
fi
if [[ ! -d automake-1.14 ]]; then
tar -xf automake-1.14.tar.gz
fi
pushd automake-1.14
./configure --prefix=/usr
make
sudo make install
popd
else
log "automake is already installed. skipping."
fi
}
function install_libtool() {
if [[ ! -f /usr/bin/libtool ]]; then
if [[ ! -f libtool-2.4.2.tar.gz ]]; then
wget http://mirror.anl.gov/pub/gnu/libtool/libtool-2.4.2.tar.gz
else
log "libtool is already downloaded. skipping."
fi
if [[ ! -d libtool-2.4.2 ]]; then
tar -xf libtool-2.4.2.tar.gz
fi
pushd libtool-2.4.2
./configure --prefix=/usr
make
sudo make install
popd
else
log "libtool is already installed. skipping."
fi
}
function package() {
if [[ $OS = "ubuntu" ]]; then
if dpkg --get-selections | grep --quiet $1; then
log "$1 is already installed. skipping."
else
2014-09-25 07:27:07 +00:00
sudo apt-get install $@ -y
fi
elif [[ $OS = "centos" ]]; then
if rpm -qa | grep --quiet $1; then
log "$1 is already installed. skipping."
else
2014-09-25 07:27:07 +00:00
sudo yum install $@ -y
fi
elif [[ $OS = "darwin" ]]; then
if brew list | grep --quiet $1; then
log "$1 is already installed. skipping."
else
brew install $@ || brew upgrade $@
fi
fi
}
2014-11-09 00:55:19 +00:00
function check() {
platform OS
if [[ $OS = "darwin" ]]; then
HASH=`shasum $0 | awk '{print $1}'`
else
HASH=`sha1sum $0 | awk '{print $1}'`
fi
if [[ ! "$1" = "check" ]]; then
echo $HASH > "$2/.provision"
return
fi
if [[ "$#" < 2 ]]; then
echo "Usage: $0 check BUILD_PATH"
exit 1
fi
CHECKPOINT=`cat $2/.provision 2>&1 &`
if [[ ! $HASH = $CHECKPOINT ]]; then
echo "Requested dependencies have changed, run: sudo make deps"
exit 1
fi
exit 0
}
function main() {
platform OS
mkdir -p "$WORKING_DIR"
cd "$WORKING_DIR"
if [[ $OS = "centos" ]]; then
log "detected centos"
elif [[ $OS = "ubuntu" ]]; then
log "detected ubuntu"
2014-09-23 07:28:34 +00:00
DISTRO=`cat /etc/*-release | grep DISTRIB_CODENAME | awk '{split($0,bits,"="); print bits[2]}'`
elif [[ $OS = "darwin" ]]; then
log "detected mac os x"
else
fatal "could not detect the current operating system. exiting."
fi
2014-09-25 08:45:13 +00:00
threads THREADS
if [[ $OS = "ubuntu" ]]; then
2014-09-23 07:28:34 +00:00
if [[ $DISTRO = "precise" ]]; then
2014-10-03 00:48:45 +00:00
sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
2014-09-23 07:28:34 +00:00
fi
2014-10-03 00:48:45 +00:00
sudo apt-get update
package git
package unzip
package build-essential
2014-10-02 17:58:56 +00:00
package libtool
package autoconf
package automake
package pkg-config
package libssl-dev
package liblzma-dev
package bison
package flex
package python-pip
package python-dev
package libbz2-dev
package devscripts
package debhelper
package clang-3.4
package clang-format-3.4
package librpm-dev
package libudev-dev
2014-11-03 22:23:24 +00:00
package libblkid-dev
2014-11-05 00:40:12 +00:00
package linux-headers-generic
set_cc clang
set_cxx clang++
2014-11-02 09:33:11 +00:00
2014-10-02 17:58:56 +00:00
if [[ $DISTRO = "precise" ]]; then
package gcc-4.7
package g++-4.7
2014-10-03 00:48:45 +00:00
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.7 100 --slave /usr/bin/g++ g++ /usr/bin/g++-4.7
install_boost
2014-10-02 17:58:56 +00:00
install_cmake
else
package cmake
package libboost1.55-all-dev
fi
2014-09-23 07:28:34 +00:00
if [[ $DISTRO = "precise" ]]; then
package libunwind7-dev
fi
if [[ $DISTRO = "trusty" || $DISTRO = "utopic" ]]; then
2014-09-23 07:28:34 +00:00
package libunwind8-dev
fi
if [[ $DISTRO = "precise" ]]; then
install_gflags
install_glog
2014-09-23 07:28:34 +00:00
else
package libgoogle-glog-dev
fi
package libsnappy-dev
package libbz2-dev
package libreadline-dev
2014-10-02 17:58:56 +00:00
if [[ $DISTRO = "precise" ]]; then
package libproc-dev
else
package libprocps3-dev
fi
install_thrift
install_rocksdb
2014-09-23 02:27:19 +00:00
elif [[ $OS = "centos" ]]; then
2014-09-25 07:27:07 +00:00
sudo yum update -y
rpm -i ftp://rpmfind.net/linux/centos/7.0.1406/updates/x86_64/Packages/kernel-headers-3.10.0-123.9.3.el7.x86_64.rpm
package git-all
package unzip
package xz
package xz-devel
package epel-release.noarch
package python-pip.noarch
package python-devel
pushd /etc/yum.repos.d
if [[ ! -f /etc/yum.repos.d/devtools-2.repo ]]; then
wget http://people.centos.org/tru/devtools-2/devtools-2.repo
fi
package devtoolset-2-gcc
package devtoolset-2-binutils
package devtoolset-2-gcc-c++
export CC=/opt/rh/devtoolset-2/root/usr/bin/gcc
export CPP=/opt/rh/devtoolset-2/root/usr/bin/cpp
export CXX=/opt/rh/devtoolset-2/root/usr/bin/c++
source /opt/rh/devtoolset-2/enable
if [[ ! -d /usr/lib/gcc ]]; then
ln -s /opt/rh/devtoolset-2/root/usr/lib/gcc /usr/lib/
fi
popd
package cmake28
if [[ ! -f /usr/bin/cmake ]]; then
ln -s /usr/bin/cmake28 /usr/bin/cmake
fi
if [[ ! -f /usr/bin/ccmake ]]; then
ln -s /usr/bin/ccmake28 /usr/bin/ccmake
fi
package clang
package clang-devel
set_cc clang
set_cxx clang++
package bzip2
package bzip2-devel
package openssl-devel
package readline-devel
package procps-devel
2014-11-02 09:33:11 +00:00
package rpm-devel
package libblkid-devel
install_boost
install_gflags
install_glog
package doxygen
package snappy
package snappy-devel
package byacc
package flex
package bison
package libunwind
package libunwind-devel
package libudev-devel
# package libtool.x86_64
# package boost.x86_64
install_autoconf
install_automake
install_libtool
install_thrift
set_cc gcc
set_cxx g++
install_rocksdb
elif [[ $OS = "darwin" ]]; then
type brew >/dev/null 2>&1 || {
fatal "could not find homebrew. please install it from http://brew.sh/";
}
type pip >/dev/null 2>&1 || {
fatal "could not find pip. please install it using 'sudo easy_install pip'";
}
brew update
package rocksdb
package cmake
package boost
package gflags
package glog
package thrift
fi
cd "$SCRIPT_DIR/../"
2014-09-24 20:07:28 +00:00
sudo pip install -r requirements.txt
2014-09-24 04:22:42 +00:00
git submodule init
git submodule update
}
2014-11-09 00:55:19 +00:00
check $1 $2
main