From b313a9e42bfc74b1af7c84373f7335defa14f2d9 Mon Sep 17 00:00:00 2001 From: Krzesimir Nowak Date: Thu, 12 Oct 2023 15:39:20 +0200 Subject: [PATCH] Source version.txt to get version information This guards against possible quotes. --- .github/workflows/figure-out-branch.sh | 2 +- .github/workflows/mantle-releases-main.yml | 2 +- .github/workflows/setup-flatcar-sdk.sh | 4 +--- ci-automation/image_changes.sh | 24 +++++++++++----------- common.sh | 4 ++-- 5 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.github/workflows/figure-out-branch.sh b/.github/workflows/figure-out-branch.sh index abf7365ab5..8f2d67cdb4 100755 --- a/.github/workflows/figure-out-branch.sh +++ b/.github/workflows/figure-out-branch.sh @@ -49,7 +49,7 @@ case "${channel_name}" in ;; alpha|beta|stable|lts) link="https://${channel_name}.release.flatcar-linux.net/amd64-usr/current" - major=$(curl -sSL "${link}/version.txt" | awk -F= '/FLATCAR_BUILD=/{ print $2 }') + major=$(source <(curl -sSL "${link}/version.txt"); echo "${FLATCAR_BUILD}") branch="flatcar-${major}" ;; *) diff --git a/.github/workflows/mantle-releases-main.yml b/.github/workflows/mantle-releases-main.yml index a45fc0f3c2..d319ae4753 100644 --- a/.github/workflows/mantle-releases-main.yml +++ b/.github/workflows/mantle-releases-main.yml @@ -40,7 +40,7 @@ jobs: fi rm -f lts-info else - major=$(curl -fsSL --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://${{ matrix.branch }}.release.flatcar-linux.net/amd64-usr/current/version.txt | awk -F= '/FLATCAR_BUILD=/{ print $2 }') + major=$(source <(curl -fsSL --retry-delay 1 --retry 60 --retry-connrefused --retry-max-time 60 --connect-timeout 20 https://${{ matrix.branch }}.release.flatcar-linux.net/amd64-usr/current/version.txt); echo "${FLATCAR_BUILD}") branch="flatcar-${major}" fi echo "BRANCH=${branch}" >>"${GITHUB_OUTPUT}" diff --git a/.github/workflows/setup-flatcar-sdk.sh b/.github/workflows/setup-flatcar-sdk.sh index d362ba2359..b3bf3317ff 100755 --- a/.github/workflows/setup-flatcar-sdk.sh +++ b/.github/workflows/setup-flatcar-sdk.sh @@ -42,9 +42,7 @@ if [[ "${CHANNEL}" = 'main' ]]; then fi # Pin the docker image version to that of the latest release in the channel. -docker_sdk_vernum="$(curl -s -S -f -L "${MIRROR_LINK}/version.txt" \ - | grep -m 1 FLATCAR_SDK_VERSION= | cut -d = -f 2- \ -)" +docker_sdk_vernum=$(source <(curl -s -S -f -L "${MIRROR_LINK}/version.txt"); echo "${FLATCAR_SDK_VERSION}") docker_image_from_registry_or_buildcache "${sdk_name}" "${docker_sdk_vernum}" diff --git a/ci-automation/image_changes.sh b/ci-automation/image_changes.sh index 82d9857c7e..75b980dc1c 100644 --- a/ci-automation/image_changes.sh +++ b/ci-automation/image_changes.sh @@ -235,21 +235,21 @@ function get_channel_a_and_version_a() { # -- # Gets the latest release for given channel and board. For lts channel -# gets a version of the latest LTS. -function channel_version() { +# gets a version of the latest LTS. Runs in a subshell. +function channel_version() ( local channel=${1}; shift local board=${1}; shift - curl \ - -fsSL \ - --retry-delay 1 \ - --retry 60 \ - --retry-connrefused \ - --retry-max-time 60 \ - --connect-timeout 20 \ - "https://${channel}.release.flatcar-linux.net/${board}/current/version.txt" | \ - grep -m 1 'FLATCAR_VERSION=' | cut -d = -f 2- -} + source <(curl \ + -fsSL \ + --retry-delay 1 \ + --retry 60 \ + --retry-connrefused \ + --retry-max-time 60 \ + --connect-timeout 20 \ + "https://${channel}.release.flatcar-linux.net/${board}/current/version.txt") + echo "${FLATCAR_VERSION}" +) # -- # Prints some reports using scripts from the passed path to diff --git a/common.sh b/common.sh index 0ca5346878..638ad619cd 100644 --- a/common.sh +++ b/common.sh @@ -268,8 +268,8 @@ load_environment_var() { local file="$1" name value shift for name in "$@"; do - value=$(grep "^${name}=" "${file}" | sed 's|"||g') - [[ -n "${value}" ]] && export "${value}" + value=$(source "${file}"; echo "${!name}") + [[ -n "${value}" ]] && export "${name}=${value}" done }