Skip to content

Commit

Permalink
Small fixes
Browse files Browse the repository at this point in the history
- Rename AMD binary urls consts
- Align function comments structure
- Rename arch specific url function variable & add condition for amd
- Remove redundant ˜ symbol
  • Loading branch information
ralongit committed Jan 4, 2024
1 parent 891e896 commit d6ed342
Show file tree
Hide file tree
Showing 10 changed files with 125 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function get_is_fargate_was_selected {
function download_eksctl {
local func_name="${FUNCNAME[0]}"
local binary_name="eksctl"
local download_url=$(get_arch_specific_url "$EKSCTL_URL_DOWNLOAD" "$EKSCTL_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$EKSCTL_AMD_URL_DOWNLOAD" "$EKSCTL_ARM_URL_DOWNLOAD")
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"

download_binary "$download_url" "$binary_name" "$binary_path"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ function get_is_fargate_was_selected {
function download_eksctl {
local func_name="${FUNCNAME[0]}"
local binary_name="eksctl"
local download_url=$(get_arch_specific_url "$EKSCTL_URL_DOWNLOAD" "$EKSCTL_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$EKSCTL_AMD_URL_DOWNLOAD" "$EKSCTL_ARM_URL_DOWNLOAD")
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"

download_binary "$download_url" "$binary_name" "$binary_path"
Expand Down
2 changes: 1 addition & 1 deletion resources-linux/otel/subtype_installer_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ function remove_logzio_otel_collector_service {
function download_otel_collector_binary {
local func_name="${FUNCNAME[0]}"
local binary_name="$OTEL_COLLECTOR_BIN_NAME"
local download_url=$(get_arch_specific_url "$OTEL_COLLECTOR_URL_DOWNLOAD" "$OTEL_COLLECTOR_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$OTEL_COLLECTOR_AMD_URL_DOWNLOAD" "$OTEL_COLLECTOR_ARM_URL_DOWNLOAD")
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"

download_binary "$download_url" "$binary_name" "$binary_path"
Expand Down
2 changes: 1 addition & 1 deletion resources-mac/otel/subtype_installer_utils.bash
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ function remove_logzio_otel_collector_service {
function download_otel_collector_binary {
local func_name="${FUNCNAME[0]}"
local binary_name="$OTEL_COLLECTOR_BIN_NAME"
local download_url=$(get_arch_specific_url "$OTEL_COLLECTOR_URL_DOWNLOAD" "$OTEL_COLLECTOR_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$OTEL_COLLECTOR_AMD_URL_DOWNLOAD" "$OTEL_COLLECTOR_ARM_URL_DOWNLOAD")
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"

download_binary "$download_url" "$binary_name" "$binary_path"
Expand Down
8 changes: 4 additions & 4 deletions scripts/linux/consts.bash
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ AGENT_JSON="$LOGZIO_TEMP_DIR/agent.json"

## Urls
# Url for downloading jq binary
JQ_URL_DOWNLOAD='https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-linux64'
JQ_AMD_URL_DOWNLOAD='https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-linux64'
# Url for downloading yq binary
YQ_URL_DOWNLOAD='https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64.tar.gz'
YQ_AMD_URL_DOWNLOAD='https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_linux_amd64.tar.gz'
# Url for downloading OTEL collector tar.gz
OTEL_COLLECTOR_URL_DOWNLOAD='https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.82.0/otelcol-contrib_0.82.0_linux_amd64.tar.gz'
OTEL_COLLECTOR_AMD_URL_DOWNLOAD='https://github.com/open-telemetry/opentelemetry-collector-releases/releases/download/v0.82.0/otelcol-contrib_0.82.0_linux_amd64.tar.gz'
# Url for downloading eksctl tar.gz
EKSCTL_URL_DOWNLOAD='https://github.com/weaveworks/eksctl/releases/download/v0.133.0/eksctl_Linux_amd64.tar.gz'
EKSCTL_AMD_URL_DOWNLOAD='https://github.com/weaveworks/eksctl/releases/download/v0.133.0/eksctl_Linux_amd64.tar.gz'
# Url for downloading jq arm64 binary
JQ_ARM_URL_DOWNLOAD='https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-linux-arm64'
# Url for downloading yq arm64 binary
Expand Down
39 changes: 36 additions & 3 deletions scripts/linux/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,14 @@ function check_arguments_validation {
return $EXIT_CODE
}

# Download binary
# Downloads binary file
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function download_binary {
local download_url="$1"
local binary_name="$2"
Expand Down Expand Up @@ -285,6 +292,12 @@ function download_binary {
}

# Helper function to download tarballs
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# ---
# Output:
# Extracted binary file in Logz.io temp directory
function download_tarball {
local download_url="$1"
local binary_name="$2"
Expand Down Expand Up @@ -334,6 +347,12 @@ function download_tarball {


# Helper function to download binary directly
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function download_direct {
local download_url="$1"
local binary_path="$2"
Expand All @@ -350,6 +369,13 @@ function download_direct {
}

# Helper function to move the binary to the destination
# Input:
# - source_path - Path to downloaded Binary/zipped binary file
# - binary_path - Path to binary file in Logz.io temp directory
# - func_name - Function name to log
# ---
# Output:
# A binary file in Logz.io temp directory
function move_binary {
local source_path="$1"
local binary_path="$2"
Expand All @@ -374,6 +400,13 @@ function move_binary {
}

# Helper function to provide execution permissions to binary file
# Input:
# - binary_path - Path to downloaded Binary/zipped binary file
# - binary_path - Path to binary file in Logz.io temp directory
# - func_name - Function name to log
# ---
# Output:
# A binary file in Logz.io temp directory
function chmod_binary {
local binary_path="$1"
local func_name="$2"
Expand All @@ -398,7 +431,7 @@ function download_jq {
local func_name="${FUNCNAME[0]}"
local binary_name="jq"
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"
local download_url=$(get_arch_specific_url "$JQ_URL_DOWNLOAD" "$JQ_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$JQ_AMD_URL_DOWNLOAD" "$JQ_ARM_URL_DOWNLOAD")

download_binary "$download_url" "$binary_name" "$binary_path"
}
Expand All @@ -412,7 +445,7 @@ function download_yq {
local func_name="${FUNCNAME[0]}"
local binary_name="yq"
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"
local download_url=$(get_arch_specific_url "$YQ_URL_DOWNLOAD" "$YQ_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$YQ_AMD_URL_DOWNLOAD" "$YQ_ARM_URL_DOWNLOAD")

download_binary "$download_url" "$binary_name" "$binary_path"
}
Expand Down
23 changes: 20 additions & 3 deletions scripts/linux/utils_functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -586,7 +586,14 @@ function execute_task {
>"$TASK_POST_RUN_FILE"
}

# Check if binary is already installed with the correct version
# Check if binary is already installed with the correct version, if it does copy it to temp directory
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function copy_installed_binary {
local binary_name="$1"
local download_url="$2"
Expand Down Expand Up @@ -621,14 +628,24 @@ function copy_installed_binary {
return 1 # Binary is not installed
fi
}

# Function to get the architecture-specific download URL
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function get_arch_specific_url {
local default_url="$1"
local amd_url="$1"
local arm_url="$2"

if [[ ( "$CPU_ARCH" == "arm64" || "$CPU_ARCH" == "aarch64" ) && ! -z "$arm_url" ]]; then
echo "$arm_url"
elif [[ ( "$CPU_ARCH" == "amd64" || "$CPU_ARCH" == "x86_64" ) && ! -z "$amd_url" ]]; then
echo "$amd_url"
else
echo "$default_url"
echo "error getting arch specific url, arm_url: '$arm_url', amd_url: '$amd_url'"
fi
}
8 changes: 4 additions & 4 deletions scripts/mac/consts.bash
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ AGENT_JSON="$LOGZIO_TEMP_DIR/agent.json"

## Urls
# Url for downloading jq binary
JQ_URL_DOWNLOAD='https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-osx-amd64'
JQ_AMD_URL_DOWNLOAD='https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-osx-amd64'
# Url for downloading yq binary
YQ_URL_DOWNLOAD='https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_darwin_amd64.tar.gz'
YQ_AMD_URL_DOWNLOAD='https://github.com/mikefarah/yq/releases/download/v4.40.5/yq_darwin_amd64.tar.gz'
# Url for downloading OTEL collector tar.gz
OTEL_COLLECTOR_URL_DOWNLOAD='https://github.com/logzio/otel-collector-distro/releases/download/v0.82.0/otelcol-logzio-darwin_amd64.tar.gz'
OTEL_COLLECTOR_AMD_URL_DOWNLOAD='https://github.com/logzio/otel-collector-distro/releases/download/v0.82.0/otelcol-logzio-darwin_amd64.tar.gz'
# Url for downloading eksctl tar.gz
EKSCTL_URL_DOWNLOAD='https://github.com/weaveworks/eksctl/releases/download/v0.133.0/eksctl_Darwin_amd64.tar.gz'
EKSCTL_AMD_URL_DOWNLOAD='https://github.com/weaveworks/eksctl/releases/download/v0.133.0/eksctl_Darwin_amd64.tar.gz'
# Url for downloading jq arm64 binary
JQ_ARM_URL_DOWNLOAD='https://github.com/stedolan/jq/releases/download/jq-1.7.1/jq-macos-arm64'
# Url for downloading yq arm64 binary
Expand Down
42 changes: 37 additions & 5 deletions scripts/mac/functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function get_mac_info {
write_task_post_run "MAC_NAME=\"$mac_name\""

message="Mac name is '$mac_name'"
send_log_to_logzio "$LOG_LEVEL_DEBUG"˜ "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID"
send_log_to_logzio "$LOG_LEVEL_DEBUG" "$message" "$LOG_STEP_PRE_INIT" "$LOG_SCRIPT_AGENT" "$func_name" "$AGENT_ID"
write_log "$LOG_LEVEL_DEBUG" "$message"

local mac_version=$(echo -e "$mac_info" | grep 'ProductVersion:' | tr -d " \t\n\r" | cut -d':' -f2)
Expand Down Expand Up @@ -242,7 +242,14 @@ function check_arguments_validation {
return $EXIT_CODE
}

# Download binary
# Downloads binary file
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function download_binary {
local download_url="$1"
local binary_name="$2"
Expand Down Expand Up @@ -270,6 +277,12 @@ function download_binary {
}

# Helper function to download tarballs
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# ---
# Output:
# Extracted binary file in Logz.io temp directory
function download_tarball {
local download_url="$1"
local binary_name="$2"
Expand Down Expand Up @@ -319,6 +332,12 @@ function download_tarball {


# Helper function to download binary directly
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function download_direct {
local download_url="$1"
local binary_path="$2"
Expand All @@ -335,6 +354,13 @@ function download_direct {
}

# Helper function to move the binary to the destination
# Input:
# - source_path - Path to downloaded Binary/zipped binary file
# - binary_path - Path to binary file in Logz.io temp directory
# - func_name - Function name to log
# ---
# Output:
# A binary file in Logz.io temp directory
function move_binary {
local source_path="$1"
local binary_path="$2"
Expand All @@ -359,6 +385,13 @@ function move_binary {
}

# Helper function to provide execution permissions to binary file
# Input:
# - binary_path - Path to downloaded Binary/zipped binary file
# - binary_path - Path to binary file in Logz.io temp directory
# - func_name - Function name to log
# ---
# Output:
# A binary file in Logz.io temp directory
function chmod_binary {
local binary_path="$1"
local func_name="$2"
Expand All @@ -374,7 +407,6 @@ function chmod_binary {
return 0
}


# Downloads jq
# Input:
# ---
Expand All @@ -384,7 +416,7 @@ function download_jq {
local func_name="${FUNCNAME[0]}"
local binary_name="jq"
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"
local download_url=$(get_arch_specific_url "$JQ_URL_DOWNLOAD" "$JQ_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$JQ_AMD_URL_DOWNLOAD" "$JQ_ARM_URL_DOWNLOAD")

download_binary "$download_url" "$binary_name" "$binary_path"
}
Expand All @@ -398,7 +430,7 @@ function download_yq {
local func_name="${FUNCNAME[0]}"
local binary_name="yq"
local binary_path="$LOGZIO_TEMP_DIR/$binary_name"
local download_url=$(get_arch_specific_url "$YQ_URL_DOWNLOAD" "$YQ_ARM_URL_DOWNLOAD")
local download_url=$(get_arch_specific_url "$YQ_AMD_URL_DOWNLOAD" "$YQ_ARM_URL_DOWNLOAD")

download_binary "$download_url" "$binary_name" "$binary_path"
}
Expand Down
23 changes: 20 additions & 3 deletions scripts/mac/utils_functions.bash
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,14 @@ function execute_task {
>"$TASK_POST_RUN_FILE"
}

# Check if binary is already installed with the correct version, if it does copy it
# Check if binary is already installed with the correct version, if it does copy it to temp directory
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function copy_installed_binary {
local binary_name="$1"
local download_url="$2"
Expand Down Expand Up @@ -616,14 +623,24 @@ function copy_installed_binary {
return 1 # Binary is not installed
fi
}

# Function to get the architecture-specific download URL
# Input:
# - download_url - Binary/zipped binary file URL
# - binary_name - Binary file name
# - binary_path - Path to binary file in Logz.io temp directory
# ---
# Output:
# A binary file in Logz.io temp directory
function get_arch_specific_url {
local default_url="$1"
local amd_url="$1"
local arm_url="$2"

if [[ ( "$CPU_ARCH" == "arm64" || "$CPU_ARCH" == "aarch64" ) && ! -z "$arm_url" ]]; then
echo "$arm_url"
elif [[ ( "$CPU_ARCH" == "amd64" || "$CPU_ARCH" == "x86_64" ) && ! -z "$amd_url" ]]; then
echo "$amd_url"
else
echo "$default_url"
echo "error getting arch specific url, arm_url: '$arm_url', amd_url: '$amd_url'"
fi
}

0 comments on commit d6ed342

Please sign in to comment.