Skip to content

Commit

Permalink
Add script build all packages
Browse files Browse the repository at this point in the history
  • Loading branch information
yenienserrano committed Dec 1, 2023
1 parent 10859ce commit c36ffd4
Show file tree
Hide file tree
Showing 2 changed files with 185 additions and 2 deletions.
12 changes: 10 additions & 2 deletions dev-tools/build-packages/base/generate_base.sh
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ build() {
# Validate and download files to build the package
valid_url='(https?|ftp|file)://[-[:alnum:]\+&@#/%?=~_|!:,.;]*[-[:alnum:]\+&@#/%=~_|]'
echo
echo "Downloading files..."
echo "Downloading plugins..."
echo
mkdir -p $tmp_dir
cd $tmp_dir
Expand All @@ -72,6 +72,10 @@ build() {
clean 1
fi

echo
echo "Downloading dashboards..."
echo

if [[ $base =~ $valid_url ]]; then
if [[ $base =~ .*\.zip ]]; then
if ! curl --output wazuh-dashboard.zip --silent --fail "${base}"; then
Expand All @@ -81,7 +85,7 @@ build() {
echo "Extracting Wazuh Dashboard base"
unzip -q wazuh-dashboard.zip -d .
rm wazuh-dashboard.zip
mv $(ls | grep opensearch-dashboard) wazuh-dashboard.tar.gz
mv $(ls | grep wazuh-dashboard) wazuh-dashboard.tar.gz
fi
else
if ! curl --output wazuh-dashboard.tar.gz --silent --fail "${base}"; then
Expand All @@ -94,6 +98,10 @@ build() {
clean 1
fi

echo
echo "Downloading security plugin..."
echo

if [[ $security =~ $valid_url ]]; then
if ! curl --output applications/security.zip --silent --fail "${security}"; then
echo "The given URL or Path to the Wazuh Security Plugin is not working: ${security}"
Expand Down
175 changes: 175 additions & 0 deletions dev-tools/build-packages/build-packages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
#!/bin/bash

app=""
base=""
revision="1"
security=""
version=""
all_platforms="no"
deb="no"
rpm="no"
tar="no"
output="$( cd $(dirname $0) ; pwd -P )/output"

current_path="$( cd $(dirname $0) ; pwd -P )"

build_tar() {
echo "Building tar package..."
cd ./base
# bash ./generate_base.sh -a $app -b $base -s $security -v $version -r $revision

name_package_tar = $(ls ./output)

if [ "$tar" == "yes" ]; then
echo $(pwd)
mv $current_path/base/output/$name_package_tar $output/$name_package_tar
fi
cd ../
}

build_deb() {
echo "Building deb package..."
cd ./deb
# bash ./launcher.sh -v $version -r $revision -p file://$current_path/base/output/$name_package_tar
cd ../
}

build_rpm() {
echo "Building rpm package..."
cd ./rpm
# bash ./launcher.sh -v $version -r $revision -p file://$current_path/base/output/$name_package_tar
cd ../
}


build() {
name_package_tar="wazuh-dashboard-$version-$revision-linux-x64.tar.gz"

if [ ! -d "$output" ]; then
mkdir -p $output
fi

if [ "$all_platforms" == "yes" ]; then
deb="yes"
rpm="yes"
tar="yes"
fi

build_tar
cd $current_path

if [ $deb == "yes" ]; then
echo "Building deb package..."
build_deb
fi

if [ $rpm == "yes" ]; then
echo "Building rpm package..."
build_rpm
fi
}

help() {
echo
echo "Usage: $0 [OPTIONS]"
echo " -a, --app <url/path> Set the location of the .zip file containing the Wazuh plugin."
echo " -b, --base <url/path> Set the location of the .tar.gz file containing the base wazuh-dashboard build."
echo " -s, --security <url/path> Set the location of the .zip file containing the wazuh-security-dashboards-plugin."
echo " -v, --version <version> Set the version of this build."
echo " --all-platforms Build for all platforms."
echo " --deb Build for deb."
echo " --rpm Build for rpm."
echo " --tar Build for tar."
echo " -r, --revision <revision> [Optional] Set the revision of this build. By default, it is set to 1."
echo " -o, --output <path> [Optional] Set the destination path of package. By default, an output folder will be created."
echo " -h, --help Show this help."
echo
exit $1
}

# -----------------------------------------------------------------------------

main() {
while [ -n "${1}" ]; do
case "${1}" in
"-h" | "--help")
help 0
;;
"-a" | "--app")
if [ -n "$2" ]; then
app="$2"
shift 2
else
help 1
fi
;;
"-s" | "--security")
if [ -n "${2}" ]; then
security="${2}"
shift 2
else
help 0
fi
;;
"-b" | "--base")
if [ -n "${2}" ]; then
base="${2}"
shift 2
else
help 0
fi
;;
"-v" | "--version")
if [ -n "${2}" ]; then
version="${2}"
shift 2
else
help 0
fi
;;
"-r" | "--revision")
if [ -n "${2}" ]; then
revision="${2}"
shift 2
fi
;;
"--all-platforms")
all_platforms="yes"
shift 1
;;
"--deb")
deb="yes"
shift 1
;;
"--rpm")
rpm="yes"
shift 1
;;
"--tar")
tar="yes"
shift 1
;;
"-o" | "--output")
if [ -n "${2}" ]; then
output="${2}"
shift 2
fi
;;
*)
echo "help"

help 1
;;
esac
done

if [ -z "$app" ] | [ -z "$base" ] | [ -z "$security" ] | [ -z "$version" ]; then
help 1
fi

build || exit 1

exit 0
}

main "$@"

0 comments on commit c36ffd4

Please sign in to comment.