2014-09-24 05:14:28 +00:00
|
|
|
#!/usr/bin/env bash
|
2014-09-17 08:22:14 +00:00
|
|
|
|
2016-02-11 19:48:58 +00:00
|
|
|
# Copyright (c) 2014-present, Facebook, Inc.
|
2014-12-18 18:50:47 +00:00
|
|
|
# All rights reserved.
|
|
|
|
#
|
|
|
|
# This source code is licensed under the BSD-style license found in the
|
2014-12-30 22:24:49 +00:00
|
|
|
# LICENSE file in the root directory of this source tree. An additional grant
|
2014-12-18 18:50:47 +00:00
|
|
|
# of patent rights can be found in the PATENTS file in the same directory.
|
|
|
|
|
2014-09-17 08:22:14 +00:00
|
|
|
set -e
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Helpful defines for the provisioning process.
|
2014-09-17 08:22:14 +00:00
|
|
|
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
|
2014-11-13 06:33:27 +00:00
|
|
|
BUILD_DIR="$SCRIPT_DIR/../build"
|
2016-06-02 21:58:43 +00:00
|
|
|
FORMULA_DIR="$SCRIPT_DIR/provision/formula"
|
2016-07-31 18:32:31 +00:00
|
|
|
|
|
|
|
HOMEBREW_REPO="https://github.com/Homebrew/brew"
|
|
|
|
LINUXBREW_REPO="https://github.com/Linuxbrew/brew"
|
|
|
|
|
|
|
|
# Set the SHA1 commit hashes for the pinned homebrew Taps.
|
|
|
|
# Pinning allows determinism for bottle availability, expect to update often.
|
2016-10-19 22:25:31 +00:00
|
|
|
HOMEBREW_CORE="0e6f293450cf9b54e324e92ea0b0475fd4e0d929"
|
2016-07-31 18:32:31 +00:00
|
|
|
LINUXBREW_CORE="600e1460c79b9cf6945e87cb5374b9202db1f6a9"
|
2016-10-19 22:25:31 +00:00
|
|
|
HOMEBREW_DUPES="00df450f28f23aa1013564889d11440ab80b36a5"
|
2016-07-31 18:32:31 +00:00
|
|
|
LINUXBREW_DUPES="83cad3d474e6d245cd543521061bba976529e5df"
|
2014-09-17 08:22:14 +00:00
|
|
|
|
2014-10-30 19:59:10 +00:00
|
|
|
source "$SCRIPT_DIR/lib.sh"
|
2015-04-03 04:34:55 +00:00
|
|
|
source "$SCRIPT_DIR/provision/lib.sh"
|
2014-11-09 00:55:19 +00:00
|
|
|
|
2016-11-10 16:14:26 +00:00
|
|
|
function platform_linux_main() {
|
|
|
|
brew_uninstall bison
|
|
|
|
|
|
|
|
# GCC 5x bootstrapping.
|
|
|
|
brew_tool patchelf
|
|
|
|
brew_tool zlib
|
|
|
|
brew_tool binutils
|
|
|
|
brew_tool linux-headers
|
|
|
|
brew_tool gmp
|
|
|
|
brew_tool mpfr
|
|
|
|
brew_tool libmpc
|
|
|
|
brew_tool isl
|
|
|
|
brew_tool pkg-config
|
|
|
|
|
|
|
|
# Build a bottle of a modern glibc.
|
|
|
|
brew_tool osquery/osquery-local/glibc
|
|
|
|
|
|
|
|
# Build a bottle for a legacy glibc.
|
|
|
|
brew_tool osquery/osquery-local/glibc-legacy
|
|
|
|
|
|
|
|
# GCC 5x.
|
|
|
|
brew_tool osquery/osquery-local/gcc
|
|
|
|
|
|
|
|
# Need LZMA for final builds.
|
|
|
|
brew_tool osquery/osquery-local/zlib-legacy
|
|
|
|
brew_tool osquery/osquery-local/xz
|
|
|
|
brew_tool osquery/osquery-local/ncurses
|
|
|
|
brew_tool osquery/osquery-local/bzip2
|
|
|
|
|
|
|
|
brew_tool unzip
|
|
|
|
brew_tool sqlite
|
|
|
|
brew_tool makedepend
|
|
|
|
brew_tool libidn
|
|
|
|
brew_tool libedit
|
|
|
|
brew_tool libtool
|
|
|
|
brew_tool m4
|
|
|
|
brew_tool autoconf
|
|
|
|
brew_tool automake
|
|
|
|
|
|
|
|
# OpenSSL is needed for the final build.
|
2016-11-11 16:00:59 +00:00
|
|
|
brew_tool osquery/osquery-local/libxml2
|
2016-11-10 16:14:26 +00:00
|
|
|
brew_clean osquery/osquery-local/curl
|
|
|
|
brew_tool osquery/osquery-local/openssl
|
|
|
|
|
|
|
|
# Curl and Python are needed for LLVM mostly.
|
|
|
|
brew_tool osquery/osquery-local/curl
|
|
|
|
brew_tool osquery/osquery-local/python
|
|
|
|
brew_tool osquery/osquery-local/cmake --without-docs
|
|
|
|
|
|
|
|
# Linux library secondary dependencies.
|
|
|
|
brew_tool osquery/osquery-local/berkeley-db
|
|
|
|
brew_tool osquery/osquery-local/popt
|
|
|
|
brew_tool osquery/osquery-local/beecrypt
|
|
|
|
|
|
|
|
# LLVM/Clang.
|
|
|
|
brew_tool osquery/osquery-local/llvm
|
|
|
|
|
|
|
|
# Util-Linux provides libuuid.
|
|
|
|
brew_dependency osquery/osquery-local/util-linux
|
|
|
|
|
|
|
|
platform_posix_main
|
|
|
|
|
|
|
|
# General Linux dependencies and custom formulas for table implementations.
|
|
|
|
brew_dependency osquery/osquery-local/libgpg-error
|
|
|
|
brew_dependency osquery/osquery-local/libdevmapper
|
|
|
|
brew_dependency osquery/osquery-local/libaptpkg
|
|
|
|
brew_dependency osquery/osquery-local/libiptables
|
|
|
|
brew_dependency osquery/osquery-local/libgcrypt
|
|
|
|
brew_dependency osquery/osquery-local/libcryptsetup
|
|
|
|
brew_dependency osquery/osquery-local/libudev
|
|
|
|
brew_dependency osquery/osquery-local/libaudit
|
|
|
|
brew_dependency osquery/osquery-local/libdpkg
|
|
|
|
brew_dependency osquery/osquery-local/librpm
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
function platform_darwin_main() {
|
|
|
|
brew_tool xz
|
|
|
|
brew_tool readline
|
|
|
|
brew_tool sqlite
|
|
|
|
brew_tool makedepend
|
|
|
|
brew_tool clang-format
|
|
|
|
brew_tool pkg-config
|
|
|
|
brew_tool bison
|
|
|
|
brew_tool autoconf
|
|
|
|
brew_tool automake
|
|
|
|
brew_tool libtool
|
|
|
|
|
2016-11-11 16:00:59 +00:00
|
|
|
brew_dependency osquery/osquery-local/libxml2
|
2016-11-10 16:14:26 +00:00
|
|
|
brew_dependency osquery/osquery-local/openssl
|
|
|
|
brew_tool osquery/osquery-local/python
|
|
|
|
brew_tool osquery/osquery-local/cmake --without-docs
|
|
|
|
|
|
|
|
platform_posix_main
|
|
|
|
}
|
|
|
|
|
|
|
|
function platform_posix_main() {
|
|
|
|
# List of LLVM-compiled dependencies.
|
|
|
|
brew_dependency osquery/osquery-local/lz4
|
|
|
|
brew_dependency osquery/osquery-local/libmagic
|
|
|
|
brew_dependency osquery/osquery-local/pcre
|
|
|
|
brew_dependency osquery/osquery-local/boost
|
|
|
|
brew_dependency osquery/osquery-local/asio
|
|
|
|
brew_dependency osquery/osquery-local/cpp-netlib
|
|
|
|
brew_dependency osquery/osquery-local/google-benchmark
|
|
|
|
brew_dependency osquery/osquery-local/snappy
|
|
|
|
brew_dependency osquery/osquery-local/sleuthkit
|
|
|
|
brew_dependency osquery/osquery-local/thrift
|
|
|
|
brew_dependency osquery/osquery-local/rocksdb
|
|
|
|
brew_dependency osquery/osquery-local/gflags
|
|
|
|
brew_dependency osquery/osquery-local/aws-sdk-cpp
|
|
|
|
brew_dependency osquery/osquery-local/yara
|
|
|
|
brew_dependency osquery/osquery-local/glog
|
|
|
|
brew_dependency osquery/osquery-local/linenoise-ng
|
2016-11-11 16:00:59 +00:00
|
|
|
brew_dependency osquery/osquery-local/augeas
|
2016-11-10 16:14:26 +00:00
|
|
|
|
|
|
|
# POSIX-shared locally-managed tools.
|
|
|
|
brew_dependency osquery/osquery-local/zzuf
|
|
|
|
brew_dependency osquery/osquery-local/cppcheck
|
|
|
|
brew_dependency osquery/osquery-local/ccache
|
|
|
|
}
|
|
|
|
|
2014-09-17 08:22:14 +00:00
|
|
|
function main() {
|
|
|
|
platform OS
|
2014-11-12 05:34:59 +00:00
|
|
|
distro $OS DISTRO
|
2015-05-10 00:32:24 +00:00
|
|
|
threads THREADS
|
2014-11-12 05:34:59 +00:00
|
|
|
|
2015-09-24 23:12:26 +00:00
|
|
|
if ! hash sudo 2>/dev/null; then
|
2016-11-10 16:14:26 +00:00
|
|
|
echo "Please install sudo in this machine"
|
|
|
|
exit 1
|
2015-10-14 23:05:12 +00:00
|
|
|
fi
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# Setup the osquery dependency directory.
|
|
|
|
# One can use a non-build location using OSQUERY_DEPS=/path/to/deps
|
|
|
|
if [[ -e "$OSQUERY_DEPS" ]]; then
|
|
|
|
DEPS_DIR="$OSQUERY_DEPS"
|
|
|
|
else
|
|
|
|
DEPS_DIR="/usr/local/osquery"
|
|
|
|
fi
|
|
|
|
|
|
|
|
if [[ "$1" = "clean" ]]; then
|
|
|
|
do_sudo rm -rf "$DEPS_DIR"
|
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Setup the local ./build/DISTRO cmake build directory.
|
2014-11-13 06:33:27 +00:00
|
|
|
if [[ ! -z "$SUDO_USER" ]]; then
|
2014-11-16 21:59:19 +00:00
|
|
|
echo "chown -h $SUDO_USER $BUILD_DIR/*"
|
|
|
|
chown -h $SUDO_USER:$SUDO_GID "$BUILD_DIR" || true
|
|
|
|
if [[ $OS = "linux" ]]; then
|
|
|
|
chown -h $SUDO_USER:$SUDO_GID "$BUILD_DIR/linux" || true
|
|
|
|
fi
|
|
|
|
chown $SUDO_USER:$SUDO_GID "$WORKING_DIR" > /dev/null 2>&1 || true
|
2014-11-13 06:33:27 +00:00
|
|
|
fi
|
2016-07-31 18:32:31 +00:00
|
|
|
|
|
|
|
# Provisioning uses either Linux or Home (OS X) brew.
|
|
|
|
if [[ $OS = "darwin" ]]; then
|
|
|
|
BREW_TYPE="darwin"
|
|
|
|
else
|
|
|
|
BREW_TYPE="linux"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Each OS/Distro may have specific provisioning needs.
|
|
|
|
# These scripts are optional and should installed the needed packages for:
|
|
|
|
# 1. A basic ruby interpreter to run brew
|
|
|
|
# 2. A GCC compiler to compile a modern glibc/GCC and legacy glibc.
|
|
|
|
# 3. Curl, git, autotools, autopoint, and gawk.
|
|
|
|
OS_SCRIPT="$SCRIPT_DIR/provision/$OS.sh"
|
|
|
|
if [[ -f "$OS_SCRIPT" ]]; then
|
|
|
|
log "found $OS provision script: $OS_SCRIPT"
|
|
|
|
source "$OS_SCRIPT"
|
2016-08-16 04:30:39 +00:00
|
|
|
if [[ -z "$SKIP_DISTRO_MAIN" && "$1" = "build" ]]; then
|
2016-07-31 18:32:31 +00:00
|
|
|
distro_main
|
|
|
|
fi
|
2014-09-17 08:22:14 +00:00
|
|
|
else
|
2016-07-31 18:32:31 +00:00
|
|
|
log "your $OS does not use a provision script"
|
2014-09-17 08:22:14 +00:00
|
|
|
fi
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
# The dependency directory (DEPS_DIR) will contain our legacy runtime glibc
|
|
|
|
# and various compilers/library dependencies.
|
|
|
|
if [[ ! -d "$DEPS_DIR" ]]; then
|
|
|
|
log "creating build dir: $DEPS_DIR"
|
|
|
|
do_sudo mkdir -p "$DEPS_DIR"
|
|
|
|
do_sudo chown $USER "$DEPS_DIR" > /dev/null 2>&1 || true
|
|
|
|
fi
|
|
|
|
cd "$DEPS_DIR"
|
|
|
|
|
|
|
|
# Finally run the setup of *brew, and checkout the needed Taps.
|
|
|
|
# This will install a local tap using a symbol to the formula subdir here.
|
|
|
|
export PATH="$DEPS_DIR/bin:$PATH"
|
|
|
|
setup_brew "$DEPS_DIR" "$BREW_TYPE"
|
|
|
|
|
2016-08-16 04:30:39 +00:00
|
|
|
if [[ "$1" = "bottle" ]]; then
|
|
|
|
brew_bottle "$2"
|
|
|
|
return
|
|
|
|
elif [[ "$1" = "install" ]]; then
|
2016-11-10 16:14:26 +00:00
|
|
|
brew_dependency "$2"
|
2016-08-16 04:30:39 +00:00
|
|
|
return
|
|
|
|
fi
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
if [[ ! -z "$OSQUERY_BUILD_DEPS" ]]; then
|
|
|
|
log "[notice]"
|
|
|
|
log "[notice] you are choosing to build dependencies instead of installing"
|
|
|
|
log "[notice]"
|
|
|
|
fi
|
|
|
|
|
|
|
|
log "running unified platform initialization"
|
2016-09-16 18:29:43 +00:00
|
|
|
brew_clear_cache
|
2016-07-31 18:32:31 +00:00
|
|
|
if [[ "$BREW_TYPE" = "darwin" ]]; then
|
|
|
|
platform_darwin_main
|
|
|
|
else
|
|
|
|
platform_linux_main
|
|
|
|
fi
|
2016-09-16 18:29:43 +00:00
|
|
|
brew_clear_cache
|
2016-08-10 03:27:42 +00:00
|
|
|
|
2014-10-30 19:59:10 +00:00
|
|
|
cd "$SCRIPT_DIR/../"
|
2014-11-16 09:31:59 +00:00
|
|
|
|
2016-08-10 03:27:42 +00:00
|
|
|
# Additional compilations may occur for Python and Ruby
|
|
|
|
export LIBRARY_PATH="$DEPS_DIR/legacy/lib:$DEPS_DIR/lib:$LIBRARY_PATH"
|
|
|
|
|
2016-03-15 16:30:40 +00:00
|
|
|
# Pip may have just been installed.
|
2016-07-31 18:32:31 +00:00
|
|
|
log "upgrading pip and installing python dependencies"
|
2016-03-15 16:30:40 +00:00
|
|
|
PIP=`which pip`
|
2016-07-31 18:32:31 +00:00
|
|
|
$PIP install --upgrade pip
|
|
|
|
# Pip may change locations after upgrade.
|
2016-07-21 00:02:40 +00:00
|
|
|
PIP=`which pip`
|
2016-07-31 18:32:31 +00:00
|
|
|
$PIP install -r requirements.txt
|
2015-04-01 08:10:28 +00:00
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
log "running auxiliary initialization"
|
2016-01-21 10:32:53 +00:00
|
|
|
initialize $OS
|
2014-09-17 08:22:14 +00:00
|
|
|
}
|
|
|
|
|
2016-07-31 18:32:31 +00:00
|
|
|
check $1 "$2"
|
|
|
|
main $1 "$2"
|