From 27f61ec62da809c7f650e05f9dc7527a30b1b4fb Mon Sep 17 00:00:00 2001 From: Joaquin Romera Date: Fri, 22 Mar 2024 13:59:27 +0100 Subject: [PATCH] Wazuh agents on mac now use the same script as Linux for upgrades. We need to reflect this on wazuh packages as well to find the correct script. --- wpk/generate_wpk_package.sh | 15 +++++++----- wpk/run.sh | 48 ++++++++++++++++++++----------------- 2 files changed, 35 insertions(+), 28 deletions(-) diff --git a/wpk/generate_wpk_package.sh b/wpk/generate_wpk_package.sh index a96aba56b2..31b026268b 100755 --- a/wpk/generate_wpk_package.sh +++ b/wpk/generate_wpk_package.sh @@ -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" diff --git a/wpk/run.sh b/wpk/run.sh index 5b3ec89150..0b9cab1792 100755 --- a/wpk/run.sh +++ b/wpk/run.sh @@ -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" @@ -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 @@ -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}