From 59fbaa756b274eb777db04440f69ebf13b839ef0 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 11 Aug 2023 22:52:43 +0000 Subject: [PATCH 1/4] [common-utils]: Bug fix: Installs zsh on an image built with installZsh:false --- src/common-utils/main.sh | 275 ++++++++++++++++++++------------------- 1 file changed, 144 insertions(+), 131 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 6d5ac0719..22ee4ca85 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -27,7 +27,10 @@ install_debian_packages() { # Ensure apt is in non-interactive to avoid prompts export DEBIAN_FRONTEND=noninteractive - local package_list="apt-utils \ + local package_list="" + if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then + package_list="${package_list} \ + apt-utils \ openssh-client \ gnupg2 \ dirmngr \ @@ -69,6 +72,34 @@ install_debian_packages() { manpages-dev \ init-system-helpers" + # Include libssl1.1 if available + if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then + package_list="${package_list} libssl1.1" + fi + + # Include libssl3 if available + if [[ ! -z $(apt-cache --names-only search ^libssl3$) ]]; then + package_list="${package_list} libssl3" + fi + + # Include appropriate version of libssl1.0.x if available + local libssl_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') + if [ "$(echo "$libssl_package" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then + if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then + # Debian 9 + package_list="${package_list} libssl1.0.2" + elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then + # Ubuntu 18.04 + package_list="${package_list} libssl1.0.0" + fi + fi + + # Include git if not already installed (may be more recent than distro version) + if ! type git > /dev/null 2>&1; then + package_list="${package_list} git" + fi + fi + # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then # Bring in variables from /etc/os-release like VERSION_CODENAME @@ -87,33 +118,6 @@ install_debian_packages() { package_list="${package_list} manpages-posix manpages-posix-dev" fi - # Include libssl1.1 if available - if [[ ! -z $(apt-cache --names-only search ^libssl1.1$) ]]; then - package_list="${package_list} libssl1.1" - fi - - # Include libssl3 if available - if [[ ! -z $(apt-cache --names-only search ^libssl3$) ]]; then - package_list="${package_list} libssl3" - fi - - # Include appropriate version of libssl1.0.x if available - local libssl_package=$(dpkg-query -f '${db:Status-Abbrev}\t${binary:Package}\n' -W 'libssl1\.0\.?' 2>&1 || echo '') - if [ "$(echo "$libssl_package" | grep -o 'libssl1\.0\.[0-9]:' | uniq | sort | wc -l)" -eq 0 ]; then - if [[ ! -z $(apt-cache --names-only search ^libssl1.0.2$) ]]; then - # Debian 9 - package_list="${package_list} libssl1.0.2" - elif [[ ! -z $(apt-cache --names-only search ^libssl1.0.0$) ]]; then - # Ubuntu 18.04 - package_list="${package_list} libssl1.0.0" - fi - fi - - # Include git if not already installed (may be more recent than distro version) - if ! type git > /dev/null 2>&1; then - package_list="${package_list} git" - fi - # Install the list of packages echo "Packages to verify are installed: ${package_list}" rm -rf /var/lib/apt/lists/* @@ -138,6 +142,8 @@ install_debian_packages() { LOCALE_ALREADY_SET="true" fi + PACKAGES_ALREADY_INSTALLED="true" + # Clean up apt-get -y clean rm -rf /var/lib/apt/lists/* @@ -145,54 +151,57 @@ install_debian_packages() { # RedHat / RockyLinux / CentOS / Fedora packages install_redhat_packages() { - local package_list="\ - gawk \ - openssh-clients \ - gnupg2 \ - iproute \ - procps \ - lsof \ - net-tools \ - psmisc \ - wget \ - ca-certificates \ - rsync \ - unzip \ - zip \ - nano \ - vim-minimal \ - less \ - jq \ - openssl-libs \ - krb5-libs \ - libicu \ - zlib \ - sudo \ - sed \ - grep \ - which \ - man-db \ - strace" - - # rockylinux:9 installs 'curl-minimal' which clashes with 'curl' - # Install 'curl' for every OS except this rockylinux:9 - if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then - package_list="${package_list} curl" - fi + local package_list="" + if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then + package_list="${package_list} \ + gawk \ + openssh-clients \ + gnupg2 \ + iproute \ + procps \ + lsof \ + net-tools \ + psmisc \ + wget \ + ca-certificates \ + rsync \ + unzip \ + zip \ + nano \ + vim-minimal \ + less \ + jq \ + openssl-libs \ + krb5-libs \ + libicu \ + zlib \ + sudo \ + sed \ + grep \ + which \ + man-db \ + strace" + + # rockylinux:9 installs 'curl-minimal' which clashes with 'curl' + # Install 'curl' for every OS except this rockylinux:9 + if [[ "${ID}" = "rocky" ]] && [[ "${VERSION}" != *"9."* ]]; then + package_list="${package_list} curl" + fi - # Install OpenSSL 1.0 compat if needed - if ${install_cmd} -q list compat-openssl10 >/dev/null 2>&1; then - package_list="${package_list} compat-openssl10" - fi + # Install OpenSSL 1.0 compat if needed + if ${install_cmd} -q list compat-openssl10 >/dev/null 2>&1; then + package_list="${package_list} compat-openssl10" + fi - # Install lsb_release if available - if ${install_cmd} -q list redhat-lsb-core >/dev/null 2>&1; then - package_list="${package_list} redhat-lsb-core" - fi + # Install lsb_release if available + if ${install_cmd} -q list redhat-lsb-core >/dev/null 2>&1; then + package_list="${package_list} redhat-lsb-core" + fi - # Install git if not already installed (may be more recent than distro version) - if ! type git > /dev/null 2>&1; then - package_list="${package_list} git" + # Install git if not already installed (may be more recent than distro version) + if ! type git > /dev/null 2>&1; then + package_list="${package_list} git" + fi fi # Install zsh if needed @@ -210,63 +219,70 @@ install_redhat_packages() { if [ "${UPGRADE_PACKAGES}" = "true" ]; then ${install_cmd} upgrade -y fi + + PACKAGES_ALREADY_INSTALLED="true" } # Alpine Linux packages install_alpine_packages() { apk update - apk add --no-cache \ - openssh-client \ - gnupg \ - procps \ - lsof \ - htop \ - net-tools \ - psmisc \ - curl \ - wget \ - rsync \ - ca-certificates \ - unzip \ - zip \ - nano \ - vim \ - less \ - jq \ - libgcc \ - libstdc++ \ - krb5-libs \ - libintl \ - libssl1.1 \ - lttng-ust \ - tzdata \ - userspace-rcu \ - zlib \ - sudo \ - coreutils \ - sed \ - grep \ - which \ - ncdu \ - shadow \ - strace - # Install man pages - package name varies between 3.12 and earlier versions - if apk info man > /dev/null 2>&1; then - apk add --no-cache man man-pages - else - apk add --no-cache mandoc man-pages - fi + if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then + apk add --no-cache \ + openssh-client \ + gnupg \ + procps \ + lsof \ + htop \ + net-tools \ + psmisc \ + curl \ + wget \ + rsync \ + ca-certificates \ + unzip \ + zip \ + nano \ + vim \ + less \ + jq \ + libgcc \ + libstdc++ \ + krb5-libs \ + libintl \ + libssl1.1 \ + lttng-ust \ + tzdata \ + userspace-rcu \ + zlib \ + sudo \ + coreutils \ + sed \ + grep \ + which \ + ncdu \ + shadow \ + strace + + # Install man pages - package name varies between 3.12 and earlier versions + if apk info man > /dev/null 2>&1; then + apk add --no-cache man man-pages + else + apk add --no-cache mandoc man-pages + fi - # Install git if not already installed (may be more recent than distro version) - if ! type git > /dev/null 2>&1; then - apk add --no-cache git + # Install git if not already installed (may be more recent than distro version) + if ! type git > /dev/null 2>&1; then + apk add --no-cache git + fi fi # Install zsh if needed if [ "${INSTALL_ZSH}" = "true" ] && ! type zsh > /dev/null 2>&1; then apk add --no-cache zsh fi + + PACKAGES_ALREADY_INSTALLED="true" } # ****************** @@ -305,20 +321,17 @@ else fi # Install packages for appropriate OS -if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then - case "${ADJUSTED_ID}" in - "debian") - install_debian_packages - ;; - "rhel") - install_redhat_packages - ;; - "alpine") - install_alpine_packages - ;; - esac - PACKAGES_ALREADY_INSTALLED="true" -fi +case "${ADJUSTED_ID}" in + "debian") + install_debian_packages + ;; + "rhel") + install_redhat_packages + ;; + "alpine") + install_alpine_packages + ;; +esac # If in automatic mode, determine if a user already exists, if not use vscode if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then From 9e76e9cf5c9a37f4dde430ad1b6381a98d4fc316 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 11 Aug 2023 22:53:43 +0000 Subject: [PATCH 2/4] version bump --- src/common-utils/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index a924aa77a..b27c21f60 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "common-utils", - "version": "2.0.11", + "version": "2.0.12", "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.", From 48eb523713ea0b76b42c8e320e4ac07a2931c33c Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Mon, 14 Aug 2023 23:23:09 +0000 Subject: [PATCH 3/4] nit: fix merge conflicts --- src/common-utils/main.sh | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 1544c9f18..5e3f79dd8 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -153,6 +153,12 @@ install_debian_packages() { # RedHat / RockyLinux / CentOS / Fedora packages install_redhat_packages() { local package_list="" + local remove_epel="false" + local install_cmd=dnf + if ! type dnf > /dev/null 2>&1; then + install_cmd=yum + fi + if [ "${PACKAGES_ALREADY_INSTALLED}" != "true" ]; then package_list="${package_list} \ gawk \ @@ -183,11 +189,6 @@ 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 @@ -208,6 +209,12 @@ install_redhat_packages() { if ! type git > /dev/null 2>&1; then package_list="${package_list} git" fi + + # Install EPEL repository if needed (required to install 'jq' for CentOS) + if ! ${install_cmd} -q list jq >/dev/null 2>&1; then + ${install_cmd} -y install epel-release + remove_epel="true" + fi fi # Install zsh if needed @@ -215,13 +222,6 @@ install_redhat_packages() { package_list="${package_list} zsh" fi - # 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 @@ -232,6 +232,8 @@ install_redhat_packages() { if [[ "${remove_epel}" = "true" ]]; then ${install_cmd} -y remove epel-release fi + + PACKAGES_ALREADY_INSTALLED="true" } # Alpine Linux packages From a70d69133ec148e0c6ae5c03da5c5fc05e515054 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 25 Aug 2023 16:40:45 -0700 Subject: [PATCH 4/4] Version bump --- src/common-utils/devcontainer-feature.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index 747be3074..869812be6 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.2", + "version": "2.1.3", "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.",