Skip to content

Commit

Permalink
Updating linux_run script for XDr installs to account for older RHEL …
Browse files Browse the repository at this point in the history
…versions
  • Loading branch information
MartyFox committed Sep 10, 2024
1 parent f39fbb2 commit 9cb6d41
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions scripts/linux_run_script.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,44 @@
#!/bin/bash
set -ex
# Get OS type

# Get OS type/version/name
check_os_version() {
if [ -f /etc/os-release ]; then
. /etc/os-release
OS=$ID
VERSION=$VERSION_ID
elif type lsb_release >/dev/null 2>&1; then
OS=$(lsb_release -si)
OS_TYPE=$(lsb_release -sd | sed 's/"//g')
VERSION=$(lsb_release -sr)
elif [ -f /etc/redhat-release ]; then
OS=$(awk '{print $1$2$3$5}' /etc/redhat-release)
OS_TYPE=$(awk '{print $1, $2, $3, $4, $5}' /etc/redhat-release)
VERSION=$(cat /etc/redhat-release | sed 's/[^0-9.]*//g')
else
echo "Cannot determine the operating system."
fi

# Run the command only if the OS is not Ubuntu
if [ "$OS" != "ubuntu" ]; then
echo "Running command on $OS"

sudo yum install redhat-lsb-core -y
else
echo "Skipping command on Ubuntu"
fi

if command -v lsb_release &> /dev/null
then
OS_TYPE=$(lsb_release -a | grep "Description" | cut -f2 -d: | sed -e 's/^[[:space:]]*//')
else
echo "Operating System could not be determined."
fi
echo "Operating System: $OS"
echo "Version: $VERSION"
}

check_os_version

# Run the command only if the OS is not Ubuntu
if [ "$OS" != "ubuntu" ]; then
echo "Running command on $OS"
sudo yum install redhat-lsb-core -y
else
echo "Skipping command on Ubuntu"
fi

STORAGE_ACCOUNT_NAME="cftptlintsvc"
CONTAINER_NAME="xdr-collectors"
STORAGE_ACCOUNT_NAME="cftptlintsvc"
CONTAINER_NAME="xdr-collectors"

install_azcli() {
# Install Azure CLI (if not already installed)

if ! command -v az &> /dev/null
then

Expand All @@ -41,30 +48,30 @@ install_azcli() {
fi

if [[ "$OS_TYPE" == *"Red Hat Enterprise"* && "$OS_TYPE" == *"7."* ]]; then
echo -e "[azure-cli]
echo -e "[azure-cli]
name=Azure CLI
baseurl=https://packages.microsoft.com/yumrepos/azure-cli
enabled=1
gpgcheck=1
gpgkey=https://packages.microsoft.com/keys/microsoft.asc" | sudo tee /etc/yum.repos.d/azure-cli.repo

sudo dnf clean all
sudo dnf -v install azure-cli -y
sudo dnf clean all
sudo dnf -v install azure-cli -y
elif [[ "$OS_TYPE" == *"Red Hat Enterprise"* && "$OS_TYPE" == *"8."* ]]; then
sudo dnf install -y https://packages.microsoft.com/config/rhel/8/packages-microsoft-prod.rpm

sudo dnf install azure-cli
elif [[ "$OS_TYPE" == *"Red Hat Enterprise"* && "$OS_TYPE" == *"9."* ]]; then
sudo dnf install -y https://packages.microsoft.com/config/rhel/9.0/packages-microsoft-prod.rpm
sudo dnf install -y https://packages.microsoft.com/config/rhel/9.0/packages-microsoft-prod.rpm

sudo dnf install azure-cli
sudo dnf install azure-cli
else
curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
fi
else
echo "Azure CLI is already installed."
fi

}

install_agent() {
Expand All @@ -76,7 +83,7 @@ install_agent() {
sudo apt-get update
sudo apt-get install -y selinux-utils policycoreutils
fi

local SA_KEY="$1"
local ENV="$2"
local XDR_TAGS="$3"
Expand All @@ -95,7 +102,7 @@ install_agent() {
sudo echo "$STRING_TO_APPEND" >> $LOCAL_FILE_PATH
sudo mkdir -p /etc/panw
sudo cp $LOCAL_FILE_PATH /etc/panw/

# Install agent
local BLOB_NAME="${ENV}/${ENV}_agent-HMCTS_Linux_rpm_8.5.0.125392/cortex-8.5.0.125392.rpm"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/cortexagent.rpm"
Expand All @@ -112,7 +119,7 @@ install_agent() {
sudo echo "$STRING_TO_APPEND" >> $LOCAL_FILE_PATH
sudo mkdir -p /etc/panw
sudo cp $LOCAL_FILE_PATH /etc/panw/

# Install agent
local BLOB_NAME="${ENV}/${ENV}_agent-HMCTS_Linux_deb_8.5.0.125392/cortex-8.5.0.125392.deb"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/cortexagent.deb"
Expand All @@ -126,7 +133,7 @@ install_agent() {

install_collector() {
echo "Info: Installing XDR Collectors"

if [ "$OS" != "ubuntu" ]; then
sudo yum install -y selinux-policy-devel
else
Expand All @@ -147,7 +154,7 @@ install_collector() {
download_blob "$STORAGE_ACCOUNT_NAME" "$SA_KEY" "$CONTAINER_NAME" "$BLOB_NAME" "$LOCAL_FILE_PATH"
sudo mkdir -p /etc/panw
sudo cp $LOCAL_FILE_PATH /etc/panw/

# Install collector
local BLOB_NAME="${ENV}/collector-1.4.1.1089.rpm/collector-1.4.1.1089.rpm"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/collector.rpm"
Expand All @@ -163,7 +170,7 @@ install_collector() {
download_blob "$STORAGE_ACCOUNT_NAME" "$SA_KEY" "$CONTAINER_NAME" "$BLOB_NAME" "$LOCAL_FILE_PATH"
sudo mkdir -p /etc/panw
sudo cp $LOCAL_FILE_PATH /etc/panw/

# Install collector
local BLOB_NAME="${ENV}/collector-1.4.1.1089.deb/collector-1.4.1.1089.deb"
local LOCAL_FILE_PATH="XDR_DOWNLOAD/collector.deb"
Expand Down

0 comments on commit 9cb6d41

Please sign in to comment.