|
#!/bin/bash |
|
|
|
download_if_not_exists() { |
|
local FILE_URL="$1" # URL to download from |
|
local DEST_PATH="$2" # Directory where the file should be saved |
|
|
|
# Extract the filename from the URL |
|
local FILENAME=$(basename "$FILE_URL") |
|
|
|
# Full path where the file will be saved |
|
local LOCAL_FILE="$DEST_PATH/$FILENAME" |
|
|
|
# Create the destination directory if it does not exist |
|
mkdir -p "$DEST_PATH" |
|
|
|
# Check if the file exists |
|
if [ ! -f "$LOCAL_FILE" ]; then |
|
echo "File does not exist. Downloading to $LOCAL_FILE..." |
|
if curl -s -f -o "$LOCAL_FILE" "$FILE_URL"; then |
|
echo "Downloaded." |
|
else |
|
echo "Download failed due to missing file or other reasons. For some assets it is normal." |
|
fi |
|
else |
|
echo "File already exists at $LOCAL_FILE. Skipping download." |
|
fi |
|
} |
|
|
|
# Function to generate artifact URLs |
|
generate_artifacts() { |
|
local version=("$@") |
|
|
|
binaries=( |
|
"apm-server/apm-server" |
|
"beats/auditbeat/auditbeat" |
|
"beats/elastic-agent/elastic-agent" |
|
"beats/filebeat/filebeat" |
|
"beats/heartbeat/heartbeat" |
|
"beats/metricbeat/metricbeat" |
|
"beats/osquerybeat/osquerybeat" |
|
"beats/packetbeat/packetbeat" |
|
"cloudbeat/cloudbeat" |
|
"endpoint-dev/endpoint-security" |
|
"fleet-server/fleet-server" |
|
"prodfiler/pf-host-agent" |
|
"prodfiler/pf-elastic-collector" |
|
"prodfiler/pf-elastic-symbolizer" |
|
) |
|
|
|
files=( |
|
"linux-arm64.tar.gz" |
|
"linux-x86_64.tar.gz" |
|
"darwin-x86_64.tar.gz" |
|
"windows-x86_64.zip" |
|
"darwin-x86_64.tar.gz" |
|
"darwin-aarch64.tar.gz" |
|
) |
|
|
|
artifact_extensions=( |
|
"" |
|
".sha512" |
|
".asc" |
|
) |
|
|
|
for binary in "${binaries[@]}"; do |
|
for file in "${files[@]}"; do |
|
for ext in "${artifact_extensions[@]}"; do |
|
asset_url="https://artifacts.elastic.co/downloads/${binary}-${version}-${file}${ext}" |
|
echo "$asset_url" |
|
done |
|
done |
|
done |
|
} |
|
|
|
DESTINATION_PATH=/tmp/assets |
|
|
|
# Parse JSON data and process each version |
|
curl -s https://www.elastic.co/api/product_versions | jq -c '.[] | map(select(.version_number | test("^(7\\.17\\.[0-9]+)|(8\\.[0-9]+\\.[0-9]+)$")) | .version_number)[]' -r | sort -r -V | uniq | while IFS= read -r version; do |
|
generate_artifacts "$version" | while IFS= read -r fileUrl; do |
|
download_if_not_exists "$fileUrl" "$DESTINATION_PATH" |
|
done |
|
done |