From def3a41f576ceffebdff8266b41b8589a2512ac2 Mon Sep 17 00:00:00 2001 From: Philipp Wagner Date: Wed, 6 Dec 2023 02:02:58 +0100 Subject: [PATCH 1/2] Fix common-utils installation on RHEL (and friends) (#772) * Fix indentation in common-utils/main.sh * common-utils: Fix install error on RHEL On RHEL (and derivatives) the installation of the common-utils feature could fail if the feature ran before (i.e., `PACKAGES_ALREADY_INSTALLED` is set) and if either `INSTALL_ZSH` is false, or zsh was installed earlier and `ZSH_ALREADY_INSTALLED` is true. In these cases the script the `package_list` is empty, and `dnf` terminates with the following error message: ``` usage: dnf install [-c [config file]] [-q] [-v] [--version] [--installroot [path]] [--nodocs] [--noplugins] [--enableplugin [plugin]] [--disableplugin [plugin]] [--releasever RELEASEVER] [--setopt SETOPTS] [--skip-broken] [-h] [--allowerasing] [-b | --nobest] [-C] [-R [minutes]] [-d [debug level]] [--debugsolver] [--showduplicates] [-e ERRORLEVEL] [--obsoletes] [--rpmverbosity [debug level name]] [-y] [--assumeno] [--enablerepo [repo]] [--disablerepo [repo] | --repo [repo]] [--enable | --disable] [-x [package]] [--disableexcludes [repo]] [--repofrompath [repo,path]] [--noautoremove] [--nogpgcheck] [--color COLOR] [--refresh] [-4] [-6] [--destdir DESTDIR] [--downloadonly] [--comment COMMENT] [--bugfix] [--enhancement] [--newpackage] [--security] [--advisory ADVISORY] [--bz BUGZILLA] [--cve CVES] [--sec-severity {Critical,Important,Moderate,Low}] [--forcearch ARCH] PACKAGE [PACKAGE ...] dnf install: error: the following arguments are required: PACKAGE ``` Fix the problem by running `dnf` only with a non-zero `package_list`. --- src/common-utils/main.sh | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index d1a977f..a291f98 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -189,11 +189,11 @@ install_redhat_packages() { 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 + # 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 @@ -222,7 +222,9 @@ install_redhat_packages() { package_list="${package_list} zsh" fi - ${install_cmd} -y install ${package_list} + if [ -n "${package_list}" ]; then + ${install_cmd} -y install ${package_list} + fi # Get to latest versions of all packages if [ "${UPGRADE_PACKAGES}" = "true" ]; then From 3ea4d6bbd7864bcf7b5a91fdeeb66e4f5a6f46c0 Mon Sep 17 00:00:00 2001 From: Josh Spicer Date: Thu, 7 Dec 2023 10:49:18 -0800 Subject: [PATCH 2/2] Fix `.zprofile` is owned by root (#775) * revert behavior of sourcing .profile in .zprofile https://github.com/devcontainers/features/pull/736/files#diff-3e71c0a0669a0410f7dd0d8f2b83f3b6bf6b525d3eabd354f19f32822da669fcR460-R463 * add test * increment version * create empty .zprofile is not present, and fix test * temporarily add back .profile to .zprofile (only if file did not exist) --- src/common-utils/devcontainer-feature.json | 2 +- src/common-utils/main.sh | 6 ++++-- test/common-utils/configure_zsh_as_default_shell.sh | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index dc54e69..329f8de 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "common-utils", - "version": "2.3.0", + "version": "2.3.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 a291f98..26f0a75 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -459,8 +459,10 @@ fi # Optionally configure zsh and Oh My Zsh! if [ "${INSTALL_ZSH}" = "true" ]; then - if [ ! -f "${user_home}/.zprofile" ] || ! grep -Fxq 'source $HOME/.profile' "${user_home}/.zprofile" ; then - echo 'source $HOME/.profile' >> "${user_home}/.zprofile" + if [ ! -f "${user_home}/.zprofile" ]; then + touch "${user_home}/.zprofile" + echo 'source $HOME/.profile' >> "${user_home}/.zprofile" # TODO: Reconsider adding '.profile' to '.zprofile' + chown ${USERNAME}:${group_name} "${user_home}/.zprofile" fi if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then diff --git a/test/common-utils/configure_zsh_as_default_shell.sh b/test/common-utils/configure_zsh_as_default_shell.sh index 01d1522..21b1210 100644 --- a/test/common-utils/configure_zsh_as_default_shell.sh +++ b/test/common-utils/configure_zsh_as_default_shell.sh @@ -11,5 +11,7 @@ check "default-shell-is-zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print check "default-zshrc-is-dev-container-template" bash -c "cat ~/.zshrc | grep ZSH_THEME | grep devcontainers" check "zsh-path-contains-local-bin" zsh -l -c "echo $PATH | grep '/home/devcontainer/.local/bin'" +check "Ensure .zprofile is owned by remoteUser" bash -c "stat -c '%U' /home/devcontainer/.zprofile | grep devcontainer" + # Report result reportResults