From d6ed3425c68969d49d1345473f91e8914bcb1977 Mon Sep 17 00:00:00 2001 From: ralongit Date: Thu, 4 Jan 2024 13:00:33 +0200 Subject: [PATCH] Small fixes MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Rename AMD binary urls consts - Align function comments structure - Rename arch specific url function variable & add condition for amd - Remove redundant ˜ symbol --- .../eks/kubernetes/installer/functions.bash | 2 +- .../eks/kubernetes/installer/functions.bash | 2 +- .../otel/subtype_installer_utils.bash | 2 +- .../otel/subtype_installer_utils.bash | 2 +- scripts/linux/consts.bash | 8 ++-- scripts/linux/functions.bash | 39 +++++++++++++++-- scripts/linux/utils_functions.bash | 23 ++++++++-- scripts/mac/consts.bash | 8 ++-- scripts/mac/functions.bash | 42 ++++++++++++++++--- scripts/mac/utils_functions.bash | 23 ++++++++-- 10 files changed, 125 insertions(+), 26 deletions(-) diff --git a/datasources/linux/kubernetes/eks/kubernetes/installer/functions.bash b/datasources/linux/kubernetes/eks/kubernetes/installer/functions.bash index a599fce74..afd69c179 100755 --- a/datasources/linux/kubernetes/eks/kubernetes/installer/functions.bash +++ b/datasources/linux/kubernetes/eks/kubernetes/installer/functions.bash @@ -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" diff --git a/datasources/mac/kubernetes/eks/kubernetes/installer/functions.bash b/datasources/mac/kubernetes/eks/kubernetes/installer/functions.bash index ec33db8fa..1916ae3ea 100755 --- a/datasources/mac/kubernetes/eks/kubernetes/installer/functions.bash +++ b/datasources/mac/kubernetes/eks/kubernetes/installer/functions.bash @@ -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" diff --git a/resources-linux/otel/subtype_installer_utils.bash b/resources-linux/otel/subtype_installer_utils.bash index 0c18d328a..b09eb6324 100755 --- a/resources-linux/otel/subtype_installer_utils.bash +++ b/resources-linux/otel/subtype_installer_utils.bash @@ -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" diff --git a/resources-mac/otel/subtype_installer_utils.bash b/resources-mac/otel/subtype_installer_utils.bash index 3be18c14d..1367d2de1 100755 --- a/resources-mac/otel/subtype_installer_utils.bash +++ b/resources-mac/otel/subtype_installer_utils.bash @@ -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" diff --git a/scripts/linux/consts.bash b/scripts/linux/consts.bash index 8ce5cdc97..439edd5c5 100755 --- a/scripts/linux/consts.bash +++ b/scripts/linux/consts.bash @@ -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 diff --git a/scripts/linux/functions.bash b/scripts/linux/functions.bash index 68dd2ec59..f83dbbf24 100755 --- a/scripts/linux/functions.bash +++ b/scripts/linux/functions.bash @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" } @@ -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" } diff --git a/scripts/linux/utils_functions.bash b/scripts/linux/utils_functions.bash index 8ac292a44..f90cb22b8 100755 --- a/scripts/linux/utils_functions.bash +++ b/scripts/linux/utils_functions.bash @@ -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" @@ -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 } \ No newline at end of file diff --git a/scripts/mac/consts.bash b/scripts/mac/consts.bash index 60291b900..3e381a93b 100755 --- a/scripts/mac/consts.bash +++ b/scripts/mac/consts.bash @@ -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 diff --git a/scripts/mac/functions.bash b/scripts/mac/functions.bash index bdec6e006..0e2962a04 100755 --- a/scripts/mac/functions.bash +++ b/scripts/mac/functions.bash @@ -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) @@ -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" @@ -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" @@ -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" @@ -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" @@ -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" @@ -374,7 +407,6 @@ function chmod_binary { return 0 } - # Downloads jq # Input: # --- @@ -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" } @@ -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" } diff --git a/scripts/mac/utils_functions.bash b/scripts/mac/utils_functions.bash index 82d5db22d..9bbe1e4f9 100755 --- a/scripts/mac/utils_functions.bash +++ b/scripts/mac/utils_functions.bash @@ -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" @@ -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 } \ No newline at end of file