Skip to content

Commit

Permalink
Wazuh agents on mac now use the same script as Linux for upgrades. We…
Browse files Browse the repository at this point in the history
… need to reflect this on wazuh packages as well to find the correct script.
  • Loading branch information
jr0me committed Mar 25, 2024
1 parent d7688f7 commit 27f61ec
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 28 deletions.
15 changes: 9 additions & 6 deletions wpk/generate_wpk_package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -324,21 +324,24 @@ function main() {
fi

if [[ "${HAVE_TARGET}" == true ]] && [[ "${HAVE_BRANCH}" == true ]] && [[ "${HAVE_DESTINATION}" == true ]] && [[ "${HAVE_OUT_NAME}" == true ]]; then
if [[ "${TARGET}" == "windows" || "${TARGET}" == "macos" ]]; then
if [[ "${TARGET}" == "linux" || "${TARGET}" == "windows" || "${TARGET}" == "macos" ]]; then
if [[ "${HAVE_PKG_NAME}" == true ]]; then
build_container ${COMMON_BUILDER} ${COMMON_BUILDER_DOCKERFILE} || clean ${COMMON_BUILDER_DOCKERFILE} 1
local CONTAINER_NAME="${COMMON_BUILDER}"
pack_wpk ${BRANCH} ${DESTINATION} ${CONTAINER_NAME} ${JOBS} ${PKG_NAME} ${OUT_NAME} ${CHECKSUM} ${CHECKSUMDIR} ${INSTALLATION_PATH} ${AWS_REGION} ${WPK_KEY} ${WPK_CERT} || clean ${COMMON_BUILDER_DOCKERFILE} 1
clean ${COMMON_BUILDER_DOCKERFILE} 0
elif [[ "${TARGET}" == "linux" ]]; then
build_container ${LINUX_BUILDER} ${LINUX_BUILDER_DOCKERFILE} || clean ${LINUX_BUILDER_DOCKERFILE} 1
local CONTAINER_NAME="${LINUX_BUILDER}"
build_wpk_linux ${BRANCH} ${DESTINATION} ${CONTAINER_NAME} ${JOBS} ${OUT_NAME} ${CHECKSUM} ${CHECKSUMDIR} ${INSTALLATION_PATH} ${AWS_REGION} ${WPK_KEY} ${WPK_CERT} || clean ${LINUX_BUILDER_DOCKERFILE} 1
clean ${LINUX_BUILDER_DOCKERFILE} 0
else
echo "ERROR: No MSI/PKG package name specified for Windows or macOS WPK"
echo "ERROR: Only Linux can be built without a package name."
help 1
fi
else
build_container ${LINUX_BUILDER} ${LINUX_BUILDER_DOCKERFILE} || clean ${LINUX_BUILDER_DOCKERFILE} 1
local CONTAINER_NAME="${LINUX_BUILDER}"
build_wpk_linux ${BRANCH} ${DESTINATION} ${CONTAINER_NAME} ${JOBS} ${OUT_NAME} ${CHECKSUM} ${CHECKSUMDIR} ${INSTALLATION_PATH} ${AWS_REGION} ${WPK_KEY} ${WPK_CERT} || clean ${LINUX_BUILDER_DOCKERFILE} 1
clean ${LINUX_BUILDER_DOCKERFILE} 0
echo "ERROR: Target system must be linux, windows or macos."
help 1
fi
else
echo "ERROR: Need more parameters"
Expand Down
48 changes: 26 additions & 22 deletions wpk/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ INSTALLATION_PATH="/var/ossec"
PKG_NAME=""
HAVE_PKG_NAME_WIN=false
HAVE_PKG_NAME_MAC=false
HAVE_PKG_NAME_LINUX=false
AWS_REGION="us-east-1"
KEYPATH="/etc/wazuh"
WPKCERT="${KEYPATH}/wpkcert.pem"
Expand Down Expand Up @@ -85,6 +86,10 @@ main() {
HAVE_PKG_NAME_WIN=true
elif [ "${PKG_NAME: -4}" == ".pkg" ]; then
HAVE_PKG_NAME_MAC=true
elif [ "${PKG_NAME: -4}" == ".rpm" ]; then
HAVE_PKG_NAME_LINUX=true
elif [ "${PKG_NAME: -4}" == ".deb" ]; then
HAVE_PKG_NAME_LINUX=true
fi
shift 2
fi
Expand Down Expand Up @@ -185,28 +190,27 @@ main() {
if [ "${DIST_NAME}" = "centos" ]; then
${PYTHON} /usr/local/bin/wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} *
else

if [ "${HAVE_PKG_NAME_WIN}" == true ]; then
CURRENT_DIR=$(pwd)
echo "wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.bat do_upgrade.ps1"
cd ${OUTDIR}
cp ${CURRENT_DIR}/src/win32/{upgrade.bat,do_upgrade.ps1} .
cp /var/pkg/${PKG_NAME} ${OUTDIR} 2>/dev/null
wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.bat do_upgrade.ps1
rm -f upgrade.bat do_upgrade.ps1 ${PKG_NAME}
elif [ "${HAVE_PKG_NAME_MAC}" == true ]; then
CURRENT_DIR=$(pwd)
echo "wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.sh pkg_installer_mac.sh"
cd ${OUTDIR}
cp ${CURRENT_DIR}/src/init/pkg_installer_mac.sh .
cp ${CURRENT_DIR}/upgrade.sh .
cp /var/pkg/${PKG_NAME} ${OUTDIR} 2>/dev/null
wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.sh pkg_installer_mac.sh
rm -f upgrade.sh pkg_installer_mac.sh ${PKG_NAME}
else
echo "ERROR: MSI/PKG package is needed to build the Windows or macOS WPK"
help 1
fi
if [ "${HAVE_PKG_NAME_WIN}" == true ]; then
CURRENT_DIR=$(pwd)
echo "wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.bat do_upgrade.ps1"
cd ${OUTDIR}
cp ${CURRENT_DIR}/src/win32/{upgrade.bat,do_upgrade.ps1} .
cp /var/pkg/${PKG_NAME} ${OUTDIR} 2>/dev/null
wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.bat do_upgrade.ps1
rm -f upgrade.bat do_upgrade.ps1 ${PKG_NAME}
elif [ "${HAVE_PKG_NAME_MAC}" == true ] || [ "${HAVE_PKG_NAME_LINUX}" == true ]; then
CURRENT_DIR=$(pwd)
echo "wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.sh pkg_installer.sh"
cd ${OUTDIR}
cp ${CURRENT_DIR}/src/init/pkg_installer.sh .
cp ${CURRENT_DIR}/upgrade.sh .
cp /var/pkg/${PKG_NAME} ${OUTDIR} 2>/dev/null
wpkpack ${OUTPUT} ${WPKCERT} ${WPKKEY} ${PKG_NAME} upgrade.sh pkg_installer.sh
rm -f upgrade.sh pkg_installer.sh ${PKG_NAME}
else
echo "ERROR: a package (MSI/PKG/RPM/DEB) is needed to build the WPK"
help 1
fi
fi
echo "PACKED FILE -> ${OUTPUT}"
cd ${OUTDIR}
Expand Down

0 comments on commit 27f61ec

Please sign in to comment.