From f90cb26c7f15659f3e2be8061295997df2bb76cc Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Mon, 14 Aug 2023 16:12:47 -0700 Subject: [PATCH] Common-utils: Fixes "No package jq available" errors for CentOS (#644) * add checks for "jq" * install epel-release if necessary * clean up epel-release post installation of "jq" --- src/common-utils/devcontainer-feature.json | 2 +- src/common-utils/main.sh | 18 +++++++++++++++--- test/common-utils/centos-7.sh | 1 + test/common-utils/fedora.sh | 1 + test/common-utils/mariner.sh | 1 + test/common-utils/rocky-8.sh | 1 + test/common-utils/rocky-9.sh | 1 + 7 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index d70848278..4eaef2128 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "common-utils", - "version": "2.1.0", + "version": "2.1.1", "name": "Common Utilities", "documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils", "description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.", diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index d3f7ef267..3731994de 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -175,6 +175,11 @@ install_redhat_packages() { man-db \ strace" + local install_cmd=dnf + if ! type dnf > /dev/null 2>&1; then + install_cmd=yum + fi + # rockylinux:9 installs 'curl-minimal' which clashes with 'curl' # Install 'curl' for every OS except this rockylinux:9 if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then @@ -201,16 +206,23 @@ install_redhat_packages() { package_list="${package_list} zsh" fi - local install_cmd=dnf - if ! type dnf > /dev/null 2>&1; then - install_cmd=yum + # Install EPEL repository if needed (required to install 'jq' for CentOS) + local remove_epel="false" + if ! ${install_cmd} -q list jq >/dev/null 2>&1; then + ${install_cmd} -y install epel-release + remove_epel="true" fi + ${install_cmd} -y install ${package_list} # Get to latest versions of all packages if [ "${UPGRADE_PACKAGES}" = "true" ]; then ${install_cmd} upgrade -y fi + + if [[ "${remove_epel}" = "true" ]]; then + ${install_cmd} -y remove epel-release + fi } # Alpine Linux packages diff --git a/test/common-utils/centos-7.sh b/test/common-utils/centos-7.sh index a81ae2f3e..69f01d1ed 100755 --- a/test/common-utils/centos-7.sh +++ b/test/common-utils/centos-7.sh @@ -9,6 +9,7 @@ source dev-container-features-test-lib . /etc/os-release check "non-root user" test "$(whoami)" = "devcontainer" check "distro" test "${VERSION_ID}" = "7" +check "jq" jq --version # Report result reportResults \ No newline at end of file diff --git a/test/common-utils/fedora.sh b/test/common-utils/fedora.sh index b32a7f112..67706d49a 100755 --- a/test/common-utils/fedora.sh +++ b/test/common-utils/fedora.sh @@ -9,6 +9,7 @@ source dev-container-features-test-lib . /etc/os-release check "non-root user" test "$(whoami)" = "devcontainer" check "distro" test "${ID}" = "fedora" +check "jq" jq --version # Report result reportResults \ No newline at end of file diff --git a/test/common-utils/mariner.sh b/test/common-utils/mariner.sh index ab6cb6e13..b0d2c91e4 100755 --- a/test/common-utils/mariner.sh +++ b/test/common-utils/mariner.sh @@ -9,6 +9,7 @@ source dev-container-features-test-lib . /etc/os-release check "non-root user" test "$(whoami)" = "devcontainer" check "distro" test "${ID}" = "mariner" +check "jq" jq --version # Report result reportResults \ No newline at end of file diff --git a/test/common-utils/rocky-8.sh b/test/common-utils/rocky-8.sh index be1223b3c..d08731824 100755 --- a/test/common-utils/rocky-8.sh +++ b/test/common-utils/rocky-8.sh @@ -10,6 +10,7 @@ source dev-container-features-test-lib check "non-root user" test "$(whoami)" = "devcontainer" check "distro" test "${PLATFORM_ID}" = "platform:el8" check "curl" curl --version +check "jq" jq --version # Report result reportResults \ No newline at end of file diff --git a/test/common-utils/rocky-9.sh b/test/common-utils/rocky-9.sh index 452c1935f..cb2b339e1 100755 --- a/test/common-utils/rocky-9.sh +++ b/test/common-utils/rocky-9.sh @@ -10,6 +10,7 @@ source dev-container-features-test-lib check "non-root user" test "$(whoami)" = "devcontainer" check "distro" test "${PLATFORM_ID}" = "platform:el9" check "curl" curl --version +check "jq" jq --version # Report result reportResults \ No newline at end of file