Skip to content

Commit

Permalink
Refactor rpm builder
Browse files Browse the repository at this point in the history
  • Loading branch information
Tostti committed Jun 28, 2023
1 parent cca55c0 commit 40c9e66
Showing 1 changed file with 21 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
# License (version 2) as published by the FSF - Free Software
# Foundation.

current_path="$( cd $(dirname $0) ; pwd -P )"
outdir="${current_path}/output"
revision="1"
architecture="x86_64"
build_docker="yes"
Expand All @@ -19,6 +17,13 @@ build_base="yes"
package=""
version=""

# Paths
current_path="$( cd $(dirname $0) ; pwd -P )"
config_path=$(realpath $current_path/../config)

# Folders
out_dir="${current_path}/output"
tmp_dir="${current_path}/tmp"

trap ctrl_c INT

Expand All @@ -28,10 +33,12 @@ clean() {
echo "Cleaning temporary files..."
echo
# Clean the files
rm -rf ${dockerfile_path}/{*.sh,*.tar.gz,wazuh-*,*.tar.gz,*.zip} wazuh-dashboard.tar.gz wazuh-dashboard-base
rm -r $tmp_dir
rm $current_path/docker/x86_64/*.sh

if [ $exit_code != 0 ]; then
rm -rf $output/*
rm $out_dir/*
rmdir $out_dir
fi

exit ${exit_code}
Expand All @@ -51,6 +58,10 @@ build_rpm() {
echo
echo "Downloading files..."
echo

mkdir -p $tmp_dir
cd $tmp_dir

if [[ $package =~ $valid_url ]];then
if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${package}"; then
echo "The given URL or Path to the Wazuh Dashboard package is not working: ${package}"
Expand All @@ -72,7 +83,7 @@ build_rpm() {
rm wazuh-dashboard.tar.gz
mv $directory_name wazuh-dashboard-base
mkdir -p wazuh-dashboard-base/etc/services
cp ../config/* wazuh-dashboard-base/etc/services
cp $config_path/* wazuh-dashboard-base/etc/services
echo ${version} > wazuh-dashboard-base/VERSION
tar -czf ./wazuh-dashboard.tar.gz wazuh-dashboard-base

Expand All @@ -84,15 +95,17 @@ build_rpm() {
if [[ ${build_docker} == "yes" ]]; then
docker build -t ${container_name} ${dockerfile_path} || return 1
fi

# Build the RPM package with a Docker container
volumes="-v ${outdir}/:/tmp:Z -v ${current_path}/wazuh-dashboard.tar.gz:/opt/wazuh-dashboard.tar.gz"
mkdir -p $out_dir
volumes="-v ${out_dir}/:/tmp:Z -v ${tmp_dir}/wazuh-dashboard.tar.gz:/opt/wazuh-dashboard.tar.gz"
docker run -t --rm ${volumes} \
-v ${current_path}/../..:/root:Z \
${container_name} ${architecture} \
${revision} ${version} || return 1


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

echo
echo DONE!
Expand All @@ -103,7 +116,7 @@ build_rpm() {

build() {
build_name="${rpm_x86_builder}"
file_path="${rpm_builder_dockerfile}/${architecture}"
file_path="../${rpm_builder_dockerfile}/${architecture}"
build_rpm ${build_name} ${file_path} || return 1
return 0
}
Expand Down

0 comments on commit 40c9e66

Please sign in to comment.