Skip to content

Commit

Permalink
Added future and download SPECs option
Browse files Browse the repository at this point in the history
  • Loading branch information
okynos committed Jan 11, 2022
1 parent 3b023f4 commit 83dc351
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 20 deletions.
28 changes: 20 additions & 8 deletions indexer/deb/build_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ REVISION="1"
BUILD_DOCKER="yes"
DEB_AMD64_BUILDER="deb_indexer_builder_amd64"
DEB_AMD64_BUILDER_DOCKERFILE="${CURRENT_PATH}/docker/amd64"
INSTALLATION_PATH="/usr/share/wazuh-indexer"
FUTURE="no"

trap ctrl_c INT

Expand Down Expand Up @@ -44,11 +44,18 @@ build_deb() {
docker build -t ${CONTAINER_NAME} ${DOCKERFILE_PATH} || return 1
fi


# Build the Debian package with a Docker container
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
-v ${CURRENT_PATH}:/root/spec:Z \
${CONTAINER_NAME} ${ARCHITECTURE} \
${REVISION} ${INSTALLATION_PATH} || return 1
if [ "${REFERENCE}" ];then
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
${CONTAINER_NAME} ${ARCHITECTURE} ${REVISION} \
${FUTURE} ${REFERENCE} || return 1
else
docker run -t --rm -v ${OUTDIR}/:/tmp:Z \
-v ${CURRENT_PATH}:/root/spec:Z \
${CONTAINER_NAME} ${ARCHITECTURE} ${REVISION} \
${FUTURE} || return 1
fi

echo "Package $(ls -Art ${OUTDIR} | tail -n 1) added to ${OUTDIR}."

Expand Down Expand Up @@ -78,8 +85,9 @@ help() {
echo " -a, --architecture <arch> [Optional] Target architecture of the package [amd64]."
echo " -r, --revision <rev> [Optional] Package revision. By default: 1."
echo " -s, --store <path> [Optional] Set the destination path of package. By default, an output folder will be created."
echo " -p, --path <path> [Optional] Installation path for the package. By default: /usr/share/wazuh-indexer"
echo " --reference <ref> [Optional] wazuh-packages branch to download SPECs, not used by default."
echo " --dont-build-docker [Optional] Locally built docker image will be used instead of generating a new one."
echo " --future [Optional] Build test future package x.30.0 Used for development purposes."
echo " -h, --help Show this help."
echo
exit $1
Expand Down Expand Up @@ -109,9 +117,9 @@ main() {
help 1
fi
;;
"-p"|"--path")
"--reference")
if [ -n "$2" ]; then
INSTALLATION_PATH="$2"
REFERENCE="$2"
shift 2
else
help 1
Expand All @@ -121,6 +129,10 @@ main() {
BUILD_DOCKER="no"
shift 1
;;
"--future")
FUTURE="yes"
shift 1
;;
"-s"|"--store")
if [ -n "$2" ]; then
OUTDIR="$2"
Expand Down
34 changes: 22 additions & 12 deletions indexer/deb/builder.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

# Wazuh package builder
# Copyright (C) 2015-2021, Wazuh Inc.
# Copyright (C) 2015-2022, Wazuh Inc.
#
# This program is a free software; you can redistribute it
# and/or modify it under the terms of the GNU General Public
Expand All @@ -13,13 +13,23 @@ set -ex
target="wazuh-indexer"
architecture=$1
release=$2
directory_base=$3
version="4.3.0"
future=$3
spec_reference=$4
directory_base="/usr/share/wazuh-indexer"

if [ -z "${release}" ]; then
release="1"
fi

if [ "${future}" = "yes" ];then
version="99.99.0"
else
if [ "${spec_reference}" ];then
version=$(curl -sL https://raw.githubusercontent.com/wazuh/wazuh-packages/${spec_reference}/indexer/deb/debian/changelog | egrep -o -m 1 '[0-9]+\.[0-9]+\.[0-9]+')
else
version=$(egrep -o -m 1 '[0-9]+\.[0-9]+\.[0-9]+' /root/spec/debian/changelog)
fi
fi

# Build directories
build_dir=/build
Expand All @@ -28,25 +38,25 @@ pkg_path="${build_dir}/${target}"
sources_dir="${pkg_path}/${pkg_name}"

mkdir -p ${sources_dir}/debian
#cp -R wazuh-indexer-* ${sources_dir}

#package_files="/specs"
#specs_path="${package_files}/SPECS"

# Including spec file
if [ "${spec_reference}" ];then
curl -sL https://github.com/wazuh/wazuh-packages/tarball/${spec_reference} | tar zx
cp -r ./wazuh*/indexer/deb/debian/* ${sources_dir}/debian/
else
cp -r /root/spec/debian/* ${sources_dir}/debian/
fi

cp -r /root/spec/debian/* ${sources_dir}/debian/

#cp -pr ${specs_path}/${version}/${target}/debian ${sources_dir}/debian
#cp -p ${package_files}/gen_permissions.sh ${sources_dir}
if [ "${future}" = "yes" ];then
sed -i '1s|[0-9]\+.[0-9]\+.[0-9]\+-RELEASE|99.99.0-RELEASE|' ${sources_dir}/debian/changelog
fi

# Generating directory structure to build the .deb package
cd ${build_dir}/${target} && tar -czf ${pkg_name}.orig.tar.gz "${pkg_name}"

# Configure the package with the different parameters
sed -i "s:RELEASE:${release}:g" ${sources_dir}/debian/changelog
sed -i "s:export INSTALLATION_DIR=.*:export INSTALLATION_DIR=${directory_base}:g" ${sources_dir}/debian/rules
#sed -i "s:DIR=\"/var/ossec\":DIR=\"${directory_base}\":g" ${sources_dir}/debian/{preinst,postinst,prerm,postrm}

# Installing build dependencies
cd ${sources_dir}
Expand Down

0 comments on commit 83dc351

Please sign in to comment.