osquery-1/tools/deployment/make_linux_package.sh

158 lines
4.7 KiB
Bash
Raw Normal View History

2015-01-08 23:53:51 +00:00
#!/usr/bin/env bash
# Copyright (c) 2014-present, Facebook, Inc.
2015-01-08 23:53:51 +00:00
# All rights reserved.
#
# This source code is licensed under the BSD-style license found in the
2015-01-30 03:37:24 +00:00
# LICENSE file in the root directory of this source tree. An additional grant
2015-01-08 23:53:51 +00:00
# of patent rights can be found in the PATENTS file in the same directory.
set -e
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
SOURCE_DIR="$SCRIPT_DIR/../.."
BUILD_DIR="$SOURCE_DIR/build/linux"
export PATH="$PATH:/usr/local/bin"
source $SCRIPT_DIR/../lib.sh
PACKAGE_VERSION=`git describe --tags HEAD || echo 'unknown-version'`
2015-03-28 02:19:55 +00:00
PACKAGE_ARCH=`uname -m`
PACKAGE_ITERATION=""
PACKAGE_TYPE=""
2015-01-08 23:53:51 +00:00
DESCRIPTION="osquery is an operating system instrumentation toolchain."
PACKAGE_NAME="osquery"
2015-01-30 03:37:24 +00:00
if [[ $PACKAGE_VERSION == *"-"* ]]; then
DESCRIPTION="$DESCRIPTION (unstable/latest version)"
2015-01-30 03:37:24 +00:00
fi
OUTPUT_PKG_PATH="$BUILD_DIR/$PACKAGE_NAME-$PACKAGE_VERSION."
2015-01-08 23:53:51 +00:00
# Config files
INITD_SRC="$SCRIPT_DIR/osqueryd.initd"
INITD_DST="/etc/init.d/osqueryd"
SYSTEMD_SERVICE_SRC="$SCRIPT_DIR/osqueryd.service"
SYSTEMD_SERVICE_DST="/usr/lib/systemd/system/osqueryd.service"
SYSTEMD_SYSCONFIG_SRC="$SCRIPT_DIR/osqueryd.sysconfig"
SYSTEMD_SYSCONFIG_DST="/etc/sysconfig/osqueryd"
2015-01-22 18:57:22 +00:00
CTL_SRC="$SCRIPT_DIR/osqueryctl"
PACKS_SRC="$SOURCE_DIR/packs"
PACKS_DST="/usr/share/osquery/packs/"
2015-01-08 23:53:51 +00:00
OSQUERY_EXAMPLE_CONFIG_SRC="$SCRIPT_DIR/osquery.example.conf"
2015-01-21 23:41:24 +00:00
OSQUERY_EXAMPLE_CONFIG_DST="/usr/share/osquery/osquery.example.conf"
2015-01-08 23:53:51 +00:00
OSQUERY_LOG_DIR="/var/log/osquery/"
2015-01-22 18:57:22 +00:00
OSQUERY_VAR_DIR="/var/osquery"
OSQUERY_ETC_DIR="/etc/osquery"
2015-01-08 23:53:51 +00:00
WORKING_DIR=/tmp/osquery_packaging
INSTALL_PREFIX=$WORKING_DIR/prefix
function usage() {
2015-03-28 02:19:55 +00:00
fatal "Usage: $0 -t deb|rpm -i REVISION -d DEPENDENCY_LIST
2015-01-08 23:53:51 +00:00
This will generate an Linux package with:
(1) An example config /var/osquery/osquery.example.config
(2) An init.d script /etc/init.d/osqueryd
(3) The osquery toolset /usr/bin/osquery*"
2015-01-08 23:53:51 +00:00
}
function parse_args() {
while [ "$1" != "" ]; do
case $1 in
-t | --type ) shift
PACKAGE_TYPE=$1
;;
2015-03-28 02:19:55 +00:00
-i | --iteration ) shift
PACKAGE_ITERATION=$1
;;
2015-01-08 23:53:51 +00:00
-d | --dependencies ) shift
PACKAGE_DEPENDENCIES="${@}"
;;
-h | --help ) usage
;;
esac
shift
done
}
function check_parsed_args() {
2015-03-28 02:19:55 +00:00
if [[ $PACKAGE_TYPE = "" ]] || [[ $PACKAGE_ITERATION = "" ]]; then
2015-01-08 23:53:51 +00:00
usage
fi
OUTPUT_PKG_PATH=$OUTPUT_PKG_PATH$PACKAGE_TYPE
}
function main() {
parse_args $@
check_parsed_args
platform OS
distro $OS DISTRO
2015-01-08 23:53:51 +00:00
rm -rf $WORKING_DIR
rm -f $OUTPUT_PKG_PATH
mkdir -p $INSTALL_PREFIX
log "copying osquery binaries"
BINARY_INSTALL_DIR="$INSTALL_PREFIX/usr/bin/"
mkdir -p $BINARY_INSTALL_DIR
cp "$BUILD_DIR/osquery/osqueryi" $BINARY_INSTALL_DIR
cp "$BUILD_DIR/osquery/osqueryd" $BINARY_INSTALL_DIR
strip $BINARY_INSTALL_DIR/*
2015-01-22 18:57:22 +00:00
cp "$CTL_SRC" $BINARY_INSTALL_DIR
2015-01-08 23:53:51 +00:00
# Create the prefix log dir and copy source configs
log "copying osquery configurations"
2015-01-22 18:57:22 +00:00
mkdir -p $INSTALL_PREFIX/$OSQUERY_VAR_DIR
2015-01-08 23:53:51 +00:00
mkdir -p $INSTALL_PREFIX/$OSQUERY_LOG_DIR
2015-01-22 18:57:22 +00:00
mkdir -p $INSTALL_PREFIX/$OSQUERY_ETC_DIR
mkdir -p $INSTALL_PREFIX/$PACKS_DST
2015-01-08 23:53:51 +00:00
mkdir -p `dirname $INSTALL_PREFIX$OSQUERY_EXAMPLE_CONFIG_DST`
cp $OSQUERY_EXAMPLE_CONFIG_SRC $INSTALL_PREFIX$OSQUERY_EXAMPLE_CONFIG_DST
cp $PACKS_SRC/* $INSTALL_PREFIX/$PACKS_DST
2015-01-08 23:53:51 +00:00
2016-01-20 01:05:14 +00:00
if [[ $DISTRO = "centos7" || $DISTRO = "rhel7" ]]; then
# Install the systemd service and sysconfig
mkdir -p `dirname $INSTALL_PREFIX$SYSTEMD_SERVICE_DST`
mkdir -p `dirname $INSTALL_PREFIX$SYSTEMD_SYSCONFIG_DST`
cp $SYSTEMD_SERVICE_SRC $INSTALL_PREFIX$SYSTEMD_SERVICE_DST
cp $SYSTEMD_SYSCONFIG_SRC $INSTALL_PREFIX$SYSTEMD_SYSCONFIG_DST
else
mkdir -p `dirname $INSTALL_PREFIX$INITD_DST`
cp $INITD_SRC $INSTALL_PREFIX$INITD_DST
fi
2015-01-08 23:53:51 +00:00
log "creating package"
IFS=',' read -a deps <<< "$PACKAGE_DEPENDENCIES"
PACKAGE_DEPENDENCIES=
for element in "${deps[@]}"
do
element=`echo $element | sed 's/ *$//'`
PACKAGE_DEPENDENCIES="$PACKAGE_DEPENDENCIES -d \"$element\""
done
2015-08-15 22:11:29 +00:00
platform OS
distro $OS DISTRO
FPM="fpm"
if [[ $DISTRO == "lucid" ]]; then
FPM="/var/lib/gems/1.8/bin/fpm"
fi
CMD="$FPM -s dir -t $PACKAGE_TYPE \
2015-01-30 03:37:24 +00:00
-n $PACKAGE_NAME -v $PACKAGE_VERSION \
2015-03-28 02:19:55 +00:00
--iteration $PACKAGE_ITERATION \
-a $PACKAGE_ARCH \
2015-01-08 23:53:51 +00:00
$PACKAGE_DEPENDENCIES \
-p $OUTPUT_PKG_PATH \
2015-03-28 02:19:55 +00:00
--url https://osquery.io \
2015-01-08 23:53:51 +00:00
-m osquery@osquery.io \
--vendor Facebook \
--license BSD \
--description \"$DESCRIPTION\" \
\"$INSTALL_PREFIX/=/\""
eval "$CMD"
log "package created at $OUTPUT_PKG_PATH"
}
main $@