From 87a20ffedec7961817b21399122e93c75c3d467d Mon Sep 17 00:00:00 2001 From: Josh Brower Date: Wed, 3 May 2023 10:44:46 -0400 Subject: [PATCH] Refactor Wrapper gen script --- .../sbin/so-elastic-agent-gen-installers | 35 +++++++++++++++---- setup/so-setup | 4 +-- 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/salt/common/tools/sbin/so-elastic-agent-gen-installers b/salt/common/tools/sbin/so-elastic-agent-gen-installers index 805f6152a..44c352352 100755 --- a/salt/common/tools/sbin/so-elastic-agent-gen-installers +++ b/salt/common/tools/sbin/so-elastic-agent-gen-installers @@ -17,18 +17,39 @@ FLEETHOST="{{ GLOBALS.manager_ip }}" #FLEETHOST=$1 #ENROLLMENTOKEN=$2 -CONTAINERGOOS=( "linux" "darwin" "windows" ) +TARGETOS=( "linux" "darwin" "windows" ) -#rm -rf /tmp/elastic-agent-workspace -#mkdir -p /tmp/elastic-agent-workspace +printf "\n### Get rid of any previous runs\n" +rm -rf /tmp/elastic-agent-workspace +mkdir -p /tmp/elastic-agent-workspace -for OS in "${CONTAINERGOOS[@]}" +printf "\n### Extract outer tarball and then each individual tarball/zip\n" +tar -xf /nsm/elastic-fleet/artifacts/elastic-agent_SO-{{ GLOBALS.so_version }}.tar.gz -C /tmp/elastic-agent-workspace/ +unzip /tmp/elastic-agent-workspace/elastic-agent-*.zip -d /tmp/elastic-agent-workspace/ +for archive in /tmp/elastic-agent-workspace/*.tar.gz +do + tar xf "$archive" -C /tmp/elastic-agent-workspace/ +done + +printf "\n### Strip out unused components" +find /tmp/elastic-agent-workspace/elastic-agent-*/data/elastic-agent-*/components -regex '.*fleet.*\|.*packet.*\|.*apm*.*\|.*audit.*\|.*heart.*\|.*cloud.*' -delete + +printf "\n### Tar everything up again" +for OS in "${TARGETOS[@]}" +do + rm -rf /tmp/elastic-agent-workspace/elastic-agent + mv /tmp/elastic-agent-workspace/elastic-agent-*-$OS-x86_64 /tmp/elastic-agent-workspace/elastic-agent + tar -czvf /tmp/elastic-agent-workspace/$OS.tar.gz -C /tmp/elastic-agent-workspace elastic-agent +done + +printf "\n### Generate OS packages using the cleaned up tarballs" +for OS in "${TARGETOS[@]}" do - printf "\n\nGenerating $OS Installer..." - #cp /opt/so/saltstack/default/salt/elasticfleet/files/elastic-agent/so-elastic-agent-*-$OS-x86_64.tar.gz /tmp/elastic-agent-workspace/$OS.tar.gz + printf "\n\n### Generating $OS Installer...\n" docker run -e CGO_ENABLED=0 -e GOOS=$OS \ --mount type=bind,source=/etc/ssl/certs/,target=/workspace/files/cert/ \ + --mount type=bind,source=/tmp/elastic-agent-workspace/,target=/workspace/files/elastic-agent/ \ --mount type=bind,source=/opt/so/saltstack/local/salt/elasticfleet/files/so_agent-installers/,target=/output/ \ {{ GLOBALS.registry_host }}:5000/{{ GLOBALS.image_repo }}/so-elastic-agent-builder:{{ GLOBALS.so_version }} go build -ldflags "-X main.fleetHost=$FLEETHOST -X main.enrollmentToken=$ENROLLMENTOKEN" -o /output/so-elastic-agent_$OS - printf "\n $OS Installer Generated..." + printf "\n### $OS Installer Generated...\n" done diff --git a/setup/so-setup b/setup/so-setup index 654484334..72549d79d 100755 --- a/setup/so-setup +++ b/setup/so-setup @@ -605,11 +605,11 @@ if ! [[ -f $install_opt_file ]]; then gpg_rpm_import # Create the local repo and point the box to use the local repo securityonion_repo + # Update existing packages + update_packages # Download Elastic Agent Artifacts title "Downloading Elastic Agent Artifacts" download_elastic_agent_artifacts - # Update existing packages - update_packages # Install salt saltify # Start the master service