2015-04-03 04:34:55 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
# Copyright (c) 2014, Facebook, Inc.
|
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
|
|
|
function install_cmake() {
|
2015-04-03 07:44:27 +00:00
|
|
|
if [[ ! -f /usr/local/bin/cmake ]]; then
|
2015-04-04 23:49:17 +00:00
|
|
|
if [[ ! -f cmake-3.2.1.tar.gz ]]; then
|
2015-04-03 07:44:27 +00:00
|
|
|
log "downloading the cmake source"
|
2015-04-04 23:49:17 +00:00
|
|
|
wget https://osquery-packages.s3.amazonaws.com/deps/cmake-3.2.1.tar.gz
|
2015-04-03 07:44:27 +00:00
|
|
|
fi
|
2015-04-04 23:49:17 +00:00
|
|
|
if [[ ! -d cmake-3.2.1 ]]; then
|
2015-04-03 07:44:27 +00:00
|
|
|
log "unpacking the cmake source"
|
2015-04-04 23:49:17 +00:00
|
|
|
tar -xf cmake-3.2.1.tar.gz
|
2015-04-03 07:44:27 +00:00
|
|
|
fi
|
|
|
|
log "building cmake"
|
2015-04-23 00:58:08 +00:00
|
|
|
|
2015-04-04 23:49:17 +00:00
|
|
|
pushd cmake-3.2.1
|
2015-04-23 00:58:08 +00:00
|
|
|
./bootstrap --prefix=/usr/local/
|
2015-04-03 07:44:27 +00:00
|
|
|
make
|
|
|
|
sudo make install
|
|
|
|
popd
|
|
|
|
else
|
|
|
|
log "cmake is already installed. skipping."
|
2015-04-03 04:34:55 +00:00
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_thrift() {
|
|
|
|
if [[ ! -f /usr/local/lib/libthrift.a ]]; then
|
|
|
|
if [[ ! -f 0.9.1.tar.gz ]]; then
|
|
|
|
wget https://osquery-packages.s3.amazonaws.com/deps/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
|
2015-04-03 07:44:27 +00:00
|
|
|
./configure CFLAGS="$CFLAGS" \
|
|
|
|
--with-cpp=yes \
|
2015-04-11 00:15:31 +00:00
|
|
|
--with-python=yes \
|
2015-04-03 07:44:27 +00:00
|
|
|
--with-ruby=no \
|
|
|
|
--with-go=no \
|
|
|
|
--with-erlang=no \
|
|
|
|
--with-java=no \
|
2015-04-11 00:15:31 +00:00
|
|
|
--with-php=no
|
2015-04-03 04:34:55 +00:00
|
|
|
make
|
|
|
|
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://osquery-packages.s3.amazonaws.com/deps/rocksdb-3.5.tar.gz
|
2015-04-03 07:44:27 +00:00
|
|
|
else
|
|
|
|
log "rocksdb source is already downloaded. skipping."
|
2015-04-03 04:34:55 +00:00
|
|
|
fi
|
|
|
|
if [[ ! -d rocksdb-rocksdb-3.5 ]]; then
|
|
|
|
tar -xf rocksdb-3.5.tar.gz
|
|
|
|
fi
|
2015-04-03 07:44:27 +00:00
|
|
|
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" ] || [ $OS = "rhel" ]; then
|
|
|
|
CLANG_VERSION=`clang --version | grep version | cut -d" " -f3`
|
|
|
|
CLANG_INCLUDE="-I/usr/lib/clang/$CLANG_VERSION/include"
|
2015-04-03 04:34:55 +00:00
|
|
|
fi
|
2015-04-03 07:44:27 +00:00
|
|
|
pushd rocksdb-rocksdb-3.5
|
|
|
|
make static_lib CFLAGS="$CLANG_INCLUDE $CFLAGS"
|
|
|
|
popd
|
2015-04-03 04:34:55 +00:00
|
|
|
fi
|
2015-04-03 07:44:27 +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
|
2015-04-03 04:34:55 +00:00
|
|
|
else
|
|
|
|
log "rocksdb already installed. skipping."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_snappy() {
|
|
|
|
if [[ ! -f /usr/local/lib/libsnappy.a ]]; then
|
|
|
|
if [[ ! -f snappy-1.1.1.tar.gz ]]; then
|
|
|
|
wget https://osquery-packages.s3.amazonaws.com/deps/snappy-1.1.1.tar.gz
|
|
|
|
else
|
|
|
|
log "snappy source is already downloaded. skipping."
|
|
|
|
fi
|
|
|
|
if [[ ! -d snappy-1.1.1 ]]; then
|
|
|
|
tar -xf snappy-1.1.1.tar.gz
|
|
|
|
fi
|
|
|
|
if [[ ! -f snappy-1.1.1/.libs/libsnappy.a ]]; then
|
|
|
|
pushd snappy-1.1.1
|
|
|
|
./configure --with-pic --enable-static
|
|
|
|
make
|
|
|
|
popd
|
|
|
|
fi
|
|
|
|
sudo cp snappy-1.1.1/.libs/libsnappy.a /usr/local/lib
|
|
|
|
else
|
|
|
|
log "snappy library is already installed. skipping."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-04-03 07:49:29 +00:00
|
|
|
function install_yara() {
|
|
|
|
if [[ ! -f /usr/local/lib/libyara.a ]]; then
|
|
|
|
if [[ ! -f yara-3.3.0.tar.gz ]]; then
|
|
|
|
wget https://s3.amazonaws.com/osquery-packages/deps/yara-3.3.0.tar.gz
|
|
|
|
else
|
|
|
|
log "yara source is already downloaded. skipping."
|
|
|
|
fi
|
|
|
|
if [[ ! -d yara-3.3.0 ]]; then
|
|
|
|
tar xzf yara-3.3.0.tar.gz
|
|
|
|
fi
|
|
|
|
pushd yara-3.3.0
|
|
|
|
./bootstrap.sh
|
2015-04-04 23:49:17 +00:00
|
|
|
CC="$CC" CXX="$CXX" ./configure --with-pic --enable-static
|
2015-04-03 07:49:29 +00:00
|
|
|
make
|
|
|
|
sudo make install
|
|
|
|
popd
|
|
|
|
else
|
|
|
|
log "yara library is already installed. skipping."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2015-04-03 04:34:55 +00:00
|
|
|
function install_boost() {
|
|
|
|
if [[ ! -f /usr/local/lib/libboost_thread.a ]]; then
|
|
|
|
if [[ ! -f boost_1_55_0.tar.gz ]]; then
|
|
|
|
wget https://osquery-packages.s3.amazonaws.com/deps/boost_1_55_0.tar.gz
|
|
|
|
else
|
|
|
|
log "boost source is already downloaded. skipping."
|
|
|
|
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`
|
2015-04-04 23:49:17 +00:00
|
|
|
sudo ./b2 --with=all -j $n toolset="$CC" install
|
2015-04-03 04:34:55 +00:00
|
|
|
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://osquery-packages.s3.amazonaws.com/deps/v2.1.1.tar.gz
|
|
|
|
else
|
|
|
|
log "gflags source is already downloaded. skipping."
|
|
|
|
fi
|
|
|
|
if [[ ! -d gflags-2.1.1 ]]; then
|
|
|
|
tar -xf v2.1.1.tar.gz
|
|
|
|
fi
|
|
|
|
if [[ ! -x "$(which gmake)" ]]; then
|
|
|
|
sudo ln -s `which make` /usr/local/bin/gmake
|
|
|
|
fi
|
|
|
|
pushd gflags-2.1.1
|
|
|
|
cmake -DCMAKE_CXX_FLAGS="$CFLAGS" -DGFLAGS_NAMESPACE:STRING=google .
|
|
|
|
make
|
|
|
|
sudo make install
|
|
|
|
popd
|
|
|
|
else
|
|
|
|
log "gflags library is already installed. skipping."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function install_autoconf() {
|
2015-04-03 07:44:27 +00:00
|
|
|
if [[ ! -f /usr/bin/autoconf ]] || [[ `autoconf -V | head -1 | awk '{print $4}' | sed 's/\.//g'` -lt "269" ]]; then
|
2015-04-03 04:34:55 +00:00
|
|
|
if [[ ! -f autoconf-2.69.tar.gz ]]; then
|
|
|
|
wget https://osquery-packages.s3.amazonaws.com/deps/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 https://osquery-packages.s3.amazonaws.com/deps/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.5.tar.gz ]]; then
|
|
|
|
wget https://osquery-packages.s3.amazonaws.com/deps/libtool-2.4.5.tar.gz
|
|
|
|
else
|
|
|
|
log "libtool is already downloaded. skipping."
|
|
|
|
fi
|
|
|
|
if [[ ! -d libtool-2.4.5 ]]; then
|
|
|
|
tar -xf libtool-2.4.5.tar.gz
|
|
|
|
fi
|
|
|
|
pushd libtool-2.4.5
|
|
|
|
./configure --prefix=/usr
|
|
|
|
make
|
|
|
|
sudo make install
|
|
|
|
popd
|
|
|
|
else
|
|
|
|
log "libtool is already installed. skipping."
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function package() {
|
|
|
|
if [[ $OS = "ubuntu" ]]; then
|
|
|
|
if [[ -n "$(dpkg --get-selections | grep $1)" ]]; then
|
|
|
|
log "$1 is already installed. skipping."
|
|
|
|
else
|
|
|
|
log "installing $1"
|
|
|
|
sudo apt-get install $1 -y
|
|
|
|
fi
|
2015-04-03 23:53:02 +00:00
|
|
|
elif [ $OS = "centos" ] || [ $OS = "rhel" ]; then
|
2015-04-19 02:51:00 +00:00
|
|
|
if [[ ! -n "$(rpm -V $1)" ]]; then
|
2015-04-03 04:34:55 +00:00
|
|
|
log "$1 is already installed. skipping."
|
|
|
|
else
|
|
|
|
log "installing $1"
|
|
|
|
sudo yum install $1 -y
|
|
|
|
fi
|
|
|
|
elif [[ $OS = "darwin" ]]; then
|
|
|
|
if [[ -n "$(brew list | grep $1)" ]]; then
|
|
|
|
log "$1 is already installed. skipping."
|
|
|
|
else
|
|
|
|
log "installing $1"
|
|
|
|
brew install --build-bottle $1 || brew upgrade $@
|
|
|
|
fi
|
|
|
|
elif [[ $OS = "freebsd" ]]; then
|
|
|
|
if [[ -z "$(pkg info -q $1)" ]]; then
|
|
|
|
log "$1 is already installed. skipping."
|
|
|
|
else
|
|
|
|
log "installing $1"
|
|
|
|
sudo pkg install -y $1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function remove_package() {
|
|
|
|
if [[ $OS = "ubuntu" ]]; then
|
|
|
|
if [[ -n "$(dpkg --get-selections | grep $1)" ]]; then
|
|
|
|
log "removing $1"
|
|
|
|
sudo apt-get remove $1 -y
|
|
|
|
else
|
|
|
|
log "Removing: $1 is not installed. skipping."
|
|
|
|
fi
|
2015-04-03 23:53:02 +00:00
|
|
|
elif [ $OS = "centos" ] || [ $OS = "rhel" ]; then
|
2015-04-03 04:34:55 +00:00
|
|
|
if [[ -n "$(rpm -qa | grep $1)" ]]; then
|
|
|
|
log "removing $1"
|
|
|
|
sudo yum remove $1 -y
|
|
|
|
else
|
|
|
|
log "Removing: $1 is not installed. skipping."
|
|
|
|
fi
|
|
|
|
elif [[ $OS = "darwin" ]]; then
|
|
|
|
if [[ -n "$(brew list | grep $1)" ]]; then
|
|
|
|
log "removing $1"
|
|
|
|
brew uninstall $1
|
|
|
|
else
|
|
|
|
log "Removing: $1 is not installed. skipping."
|
|
|
|
fi
|
|
|
|
elif [[ $OS = "freebsd" ]]; then
|
|
|
|
if [[ -n "$(pkg info -q $1)" ]]; then
|
|
|
|
log "removing $1"
|
|
|
|
sudo pkg delete -y $1
|
|
|
|
else
|
|
|
|
log "Removing: $1 is not installed. skipping."
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function gem_install() {
|
|
|
|
if [[ -n "$(gem list | grep $1)" ]]; then
|
|
|
|
log "$1 is already installed. skipping."
|
|
|
|
else
|
|
|
|
sudo gem install $1
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
function check() {
|
|
|
|
platform OS
|
|
|
|
|
|
|
|
if [[ $OS = "darwin" ]]; then
|
|
|
|
HASH=`shasum $0 | awk '{print $1}'`
|
|
|
|
elif [[ $OS = "freebsd" ]]; then
|
|
|
|
HASH=`sha1 -q $0`
|
|
|
|
else
|
|
|
|
HASH=`sha1sum $0 | awk '{print $1}'`
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "build" ]]; then
|
|
|
|
echo $HASH > "$2/.provision"
|
|
|
|
if [[ ! -z "$SUDO_USER" ]]; then
|
|
|
|
chown $SUDO_USER "$2/.provision" > /dev/null 2>&1 || true
|
|
|
|
fi
|
|
|
|
return
|
|
|
|
elif [[ ! "$1" = "check" ]]; then
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$#" < 2 ]]; then
|
|
|
|
echo "Usage: $0 (check|build) BUILD_PATH"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
|
|
|
CHECKPOINT=`cat $2/.provision 2>&1 &`
|
|
|
|
if [[ ! $HASH = $CHECKPOINT ]]; then
|
|
|
|
echo "Requested dependencies may have changed, run: make deps"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
exit 0
|
|
|
|
}
|