From 0626768a908b3498beb2b806b40c30f3197b1481 Mon Sep 17 00:00:00 2001 From: Andrew Battat <113942931+andrewbattat@users.noreply.github.com> Date: Mon, 27 Jan 2025 08:45:58 -0600 Subject: [PATCH] chore(node): normalize config.sh to return empty string (#3502) normalize config.sh get_config_value: - If key not found or value is "null", returns empty string. Otherwise, returns value --- ic-os/components/misc/config/setupos/config.sh | 13 +++++++++++-- ic-os/components/setupos-scripts/check-network.sh | 13 +++++-------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/ic-os/components/misc/config/setupos/config.sh b/ic-os/components/misc/config/setupos/config.sh index a16d9fcceba..630b5ab8ff5 100644 --- a/ic-os/components/misc/config/setupos/config.sh +++ b/ic-os/components/misc/config/setupos/config.sh @@ -5,9 +5,18 @@ # Retrieves a value from the config.json file using a JSON path. # Arguments: # $1 - JSON path to the desired value (e.g., '.icos_settings.nns_urls') -# Note: If the key is not found, this function will return null. +# Returns: +# If key is not found or value is "null", returns empty string. +# Otherwise, returns value. function get_config_value() { local CONFIG_FILE="/var/ic/config/config.json" local key=$1 - jq -r "${key}" "${CONFIG_FILE}" + + local value=$(jq -r "${key}" "${CONFIG_FILE}") + + if [[ "${value}" == "null" ]]; then + echo "" + else + echo "${value}" + fi } diff --git a/ic-os/components/setupos-scripts/check-network.sh b/ic-os/components/setupos-scripts/check-network.sh index 22b752b5bdf..67ac7e614c9 100755 --- a/ic-os/components/setupos-scripts/check-network.sh +++ b/ic-os/components/setupos-scripts/check-network.sh @@ -101,14 +101,13 @@ function print_network_settings() { echo "* Printing user defined network settings..." echo " IPv6 Prefix : ${ipv6_prefix}" echo " IPv6 Gateway: ${ipv6_gateway}" - if [[ -n ${ipv4_address} && "${ipv4_address}" != "null" && - -n ${ipv4_prefix_length} && "${ipv4_prefix_length}" != "null" && - -n ${ipv4_gateway} && "${ipv4_gateway}" != "null" ]]; then + + if [[ -n ${ipv4_address} && -n ${ipv4_prefix_length} && -n ${ipv4_gateway} ]]; then echo " IPv4 Address: ${ipv4_address}" echo " IPv4 Prefix Length: ${ipv4_prefix_length}" echo " IPv4 Gateway: ${ipv4_gateway}" fi - if [[ -n ${domain_name} && "${domain_name}" != "null" ]]; then + if [[ -n ${domain_name} ]]; then echo " Domain name: ${domain_name}" fi echo " " @@ -214,13 +213,11 @@ main() { get_network_settings print_network_settings - if [[ -n ${domain_name} && "${domain_name}" != "null" ]]; then + if [[ -n ${domain_name} ]]; then validate_domain_name fi - if [[ -n ${ipv4_address} && "${ipv4_address}" != "null" && - -n ${ipv4_prefix_length} && "${ipv4_prefix_length}" != "null" && - -n ${ipv4_gateway} && "${ipv4_gateway}" != "null" ]]; then + if [[ -n ${ipv4_address} && -n ${ipv4_prefix_length} && -n ${ipv4_gateway} ]]; then setup_ipv4_network ping_ipv4_gateway fi