Skip to content

Instantly share code, notes, and snippets.

@linuxmalaysia
Last active December 28, 2024 03:19
Show Gist options
  • Save linuxmalaysia/2d356c1548f1cd6fa5a49eed87ba1cd9 to your computer and use it in GitHub Desktop.
Save linuxmalaysia/2d356c1548f1cd6fa5a49eed87ba1cd9 to your computer and use it in GitHub Desktop.
Download Elastic Assets for airgap installation
#!/bin/bash
### Script mudah untuk download asset daripada elastic downloads bagi tujuan
### Internal repo kepada Elastic Fleet.
### use with own risks
### buat directory ini bawah html /usr/share/nginx/html
### Harisfazillah Bin Jamel 28/12/2024
### Ubuntu / Debian - apt install nginx
### Alma Linux / Rocky Linux - dnf install nginx
### Created with Google Gemini
# Check for distribution and install Nginx
if [[ -f /etc/os-release ]]; then
# Assuming Ubuntu/Debian based distribution
source /etc/os-release
if [[ "$ID" == "ubuntu" ]]; then
sudo apt update
sudo apt install -y nginx
elif [[ "$ID" == "debian" ]]; then
sudo apt update
sudo apt install -y nginx
fi
elif [[ -f /etc/redhat-release ]] || [[ -f /etc/centos-release ]] || [[ -f /etc/rocky-release ]] || [[ -f /etc/almalinux-release ]]; then
# Assuming RedHat/CentOS/Rocky/AlmaLinux based distribution
sudo dnf install -y nginx
fi
DOWNLPATH="/usr/share/nginx/html"
VERSI="8.7.0"
cd $DOWNLPATH
mkdir -p downloads/apm-server
chmod 755 downloads/apm-server
cd downloads/apm-server
curl -O https://artifacts.elastic.co/downloads/apm-server/apm-server-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/apm-server/apm-server-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/apm-server/apm-server-$VERSI-linux-x86_64.tar.gz.asc
##
cd $DOWNLPATH
mkdir -p downloads/beats/auditbeat
chmod 755 downloads/beats/auditbeat
cd downloads/beats/auditbeat
curl -O https://artifacts.elastic.co/downloads/beats/auditbeat/auditbeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/auditbeat/auditbeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/auditbeat/auditbeat-$VERSI-linux-x86_64.tar.gz.asc
###
cd $DOWNLPATH
mkdir -p downloads/beats/elastic-agent
chmod 755 downloads/beats/elastic-agent
cd downloads/beats/elastic-agent
curl -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-$VERSI-linux-x86_64.tar.gz.asc
###
cd $DOWNLPATH
mkdir -p downloads/beats/filebeat
chmod 755 downloads/beats/filebeat
cd downloads/beats/filebeat
curl -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-$VERSI-linux-x86_64.tar.gz.asc
###
cd $DOWNLPATH
mkdir -p downloads/beats/heartbeat
chmod 755 downloads/beats/heartbeat
cd downloads/beats/heartbeat
curl -O https://artifacts.elastic.co/downloads/beats/heartbeat/heartbeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/heartbeat/heartbeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/heartbeat/heartbeat-$VERSI-linux-x86_64.tar.gz.asc
####
cd $DOWNLPATH
mkdir -p downloads/beats/metricbeat
chmod 755 downloads/beats/metricbeat
cd downloads/beats/metricbeat
curl -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-$VERSI-linux-x86_64.tar.gz.asc
#####
cd $DOWNLPATH
mkdir -p downloads/beats/osquerybeat
chmod 755 downloads/beats/osquerybeat
cd downloads/beats/osquerybeat
curl -O https://artifacts.elastic.co/downloads/beats/osquerybeat/osquerybeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/osquerybeat/osquerybeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/osquerybeat/osquerybeat-$VERSI-linux-x86_64.tar.gz.asc
####
cd $DOWNLPATH
mkdir -p downloads/beats/packetbeat
chmod 755 downloads/beats/packetbeat
cd downloads/beats/packetbeat
curl -O https://artifacts.elastic.co/downloads/beats/packetbeat/packetbeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/beats/packetbeat/packetbeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/beats/packetbeat/packetbeat-$VERSI-linux-x86_64.tar.gz.asc
#####
cd $DOWNLPATH
mkdir -p downloads/cloudbeat
chmod 755 downloads/cloudbeat
cd downloads/cloudbeat
curl -O https://artifacts.elastic.co/downloads/cloudbeat/cloudbeat-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/cloudbeat/cloudbeat-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/cloudbeat/cloudbeat-$VERSI-linux-x86_64.tar.gz.asc
#####
cd $DOWNLPATH
mkdir -p downloads/endpoint-dev
chmod 755 downloads/endpoint-dev
cd downloads/endpoint-dev
curl -O https://artifacts.elastic.co/downloads/endpoint-dev/endpoint-security-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/endpoint-dev/endpoint-security-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/endpoint-dev/endpoint-security-$VERSI-linux-x86_64.tar.gz.asc
####
cd $DOWNLPATH
mkdir -p downloads/fleet-server
chmod 755 downloads/fleet-server
cd downloads/fleet-server
curl -O https://artifacts.elastic.co/downloads/fleet-server/fleet-server-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/fleet-server/fleet-server-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/fleet-server/fleet-server-$VERSI-linux-x86_64.tar.gz.asc
#######
cd $DOWNLPATH
mkdir -p downloads/prodfiler
chmod 755 downloads/prodfiler
cd downloads/prodfiler
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-host-agent-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-host-agent-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-host-agent-$VERSI-linux-x86_64.tar.gz.asc
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-collector-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-collector-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-collector-$VERSI-linux-x86_64.tar.gz.asc
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-symbolizer-$VERSI-linux-x86_64.tar.gz
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-symbolizer-$VERSI-linux-x86_64.tar.gz.sha512
curl -O https://artifacts.elastic.co/downloads/prodfiler/pf-elastic-symbolizer-$VERSI-linux-x86_64.tar.gz.asc
###
cd $DOWNLPATH
mkdir -p downloads/beats/elastic-agent
chmod 755 downloads/beats/elastic-agent
cd downloads/beats/elastic-agent
curl -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-$VERSI-windows-x86_64.zip
curl -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-$VERSI-windows-x86_64.zip.sha512
curl -O https://artifacts.elastic.co/downloads/beats/elastic-agent/elastic-agent-$VERSI-windows-x86_64.zip.asc
###
cd $DOWNLPATH
find $DOWNLPATH/downloads -type f -exec chmod 644 {} \;
find $DOWNLPATH/downloads -type d -exec chmod 755 {} \;
# contoh link untuk fleet server settint
## http://192.168.0.2/downloads
###
@linuxmalaysia
Copy link
Author

linuxmalaysia commented Dec 27, 2024

Still having errors

#!/bin/bash

### Script mudah untuk download asset daripada elastic downloads bagi tujuan
### Internal repo kepada Elastic Fleet.
### use with own risks
### buat directory ini bawah html /usr/share/nginx/html
### Harisfazillah Bin Jamel 28/12/2024
### Ubuntu / Debian - apt install nginx
### Alma Linux / Rocky Linux - dnf install nginx
### Created with Google Gemini

# Check for distribution and install Nginx

if [[ -f /etc/os-release ]]; then
  # Assuming Ubuntu/Debian based distribution
  source /etc/os-release
  if [[ "$ID" == "ubuntu" ]]; then
    sudo apt update
    sudo apt install -y nginx
  elif [[ "$ID" == "debian" ]]; then
    sudo apt update
    sudo apt install -y nginx
  fi
elif [[ -f /etc/redhat-release ]] || [[ -f /etc/centos-release ]] || [[ -f /etc/rocky-release ]] || [[ -f /etc/almalinux-release ]]; then
  # Assuming RedHat/CentOS/Rocky/AlmaLinux based distribution
  sudo dnf install -y nginx
fi

# Download directory path
DOWNLPATH="/usr/share/nginx/html/downloads"
VERSI="8.7.0"

# Base URL for Elastic downloads
BASE_URL="https://artifacts.elastic.co/downloads"

# Define download URLs for each asset (replace with actual URLs if different)
APM_SERVER_URL="$BASE_URL/apm-server/apm-server-$VERSI-linux-x86_64.tar.gz"
AUDITBEAT_URL="$BASE_URL/beats/auditbeat/auditbeat-$VERSI-linux-x86_64.tar.gz"
ELASTIC_AGENT_URL="$BASE_URL/beats/elastic-agent/elastic-agent-$VERSI-linux-x86_64.tar.gz"
FILEBEAT_URL="$BASE_URL/beats/filebeat/filebeat-$VERSI-linux-x86_64.tar.gz"
HEARTBEAT_URL="$BASE_URL/beats/heartbeat/heartbeat-$VERSI-linux-x86_64.tar.gz"
# ... (define URLs for other assets) ...
ELASTIC_AGENT_WINDOWS_URL="$BASE_URL/beats/elastic-agent/elastic-agent-$VERSI-windows-x86_64.zip"


# Create directories for each asset
mkdir -p "$DOWNLPATH"
for asset in apm-server auditbeat elastic-agent filebeat heartbeat metricbeat osquerybeat packetbeat cloudbeat endpoint-dev fleet-server prodfiler; do
  mkdir -p "$DOWNLPATH/$asset"
  chmod 755 "$DOWNLPATH/$asset"
  ASSET_URL="$BASE_URL/$asset/$asset-$VERSI-linux-x86_64.tar.gz"
  echo "$ASSET_URL"

  # Download asset archive, checksum, and signature using variables
  curl -o "$DOWNLPATH/$asset/$asset-$VERSI-linux-x86_64.tar.gz" "$ASSET_URL"
  curl -o "$DOWNLPATH/$asset/$asset-$VERSI-linux-x86_64.tar.gz.sha512" "$ASSET_URL.sha512"
  curl -o "$DOWNLPATH/$asset/$asset-$VERSI-linux-x86_64.tar.gz.asc" "$ASSET_URL.asc"
done

# Download Windows version of Elastic Agent
#curl -o "$DOWNLPATH/$asset/elastic-agent-$VERSI-windows-x86_64.zip" "$ELASTIC_AGENT_WINDOWS_URL"
curl -o "$DOWNLPATH/$asset/elastic-agent-$VERSI-windows-x86_64.zip.sha512" "$ELASTIC_AGENT_WINDOWS_URL.sha512"
curl -o "$DOWNLPATH/$asset/elastic-agent-$VERSI-windows-x86_64.zip.asc" "$ELASTIC_AGENT_WINDOWS_URL.asc"

# Set permissions on downloaded files and directories
find "$DOWNLPATH" -type f -exec chmod 644 {} \;
find "$DOWNLPATH" -type d -exec chmod 755 {} \;

echo "Nginx installed and Elastic assets downloaded to $DOWNLPATH"

# contoh link untuk setting Elastic Fleet
## http://192.168.0.2/downloads

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment