From 31c6730c1c6ea477496f50515ad8faf85e90b045 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 27 Oct 2023 21:57:13 +0000 Subject: [PATCH 1/4] [common-utils] Bug fix: zsp missing rc snippet --- src/common-utils/devcontainer-feature.json | 2 +- src/common-utils/main.sh | 12 ++++++++++-- test/common-utils/configure_zsh_as_default_shell.sh | 1 + test/common-utils/scenarios.json | 6 ++++-- 4 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index 181e54594..dc54e6918 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "common-utils", - "version": "2.2.0", + "version": "2.3.0", "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 71422465c..69477c3c4 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -421,6 +421,7 @@ fi # Restore user .bashrc / .profile / .zshrc defaults from skeleton file if it doesn't exist or is empty possible_rc_files=( ".bashrc" ".profile" ) [ "$INSTALL_OH_MY_ZSH_CONFIG" == "true" ] && possible_rc_files+=('.zshrc') +[ "$INSTALL_ZSH" == "true" ] && possible_rc_files+=('.zprofile') for rc_file in "${possible_rc_files[@]}"; do if [ -f "/etc/skel/${rc_file}" ]; then if [ ! -e "${user_home}/${rc_file}" ] || [ ! -s "${user_home}/${rc_file}" ]; then @@ -456,6 +457,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" + fi + if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then if [ "${ADJUSTED_ID}" = "rhel" ]; then global_rc_path="/etc/zshrc" @@ -478,12 +483,15 @@ if [ "${INSTALL_ZSH}" = "true" ]; then chsh --shell /bin/zsh ${USERNAME} fi - # Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. + # Adapted, simplified inline Oh My Zsh! install steps that adds RC snippet and defaults to a codespaces theme. # See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script. if [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then user_rc_file="${user_home}/.zshrc" oh_my_install_dir="${user_home}/.oh-my-zsh" template_path="${oh_my_install_dir}/templates/zshrc.zsh-template" + + cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${user_rc_file} + if [ ! -d "${oh_my_install_dir}" ]; then umask g-w,o-w mkdir -p ${oh_my_install_dir} @@ -507,7 +515,7 @@ if [ "${INSTALL_ZSH}" = "true" ]; then # Add devcontainer .zshrc template if [ "$INSTALL_OH_MY_ZSH_CONFIG" = "true" ]; then - echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${user_rc_file} + echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" >> ${user_rc_file} sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file} fi diff --git a/test/common-utils/configure_zsh_as_default_shell.sh b/test/common-utils/configure_zsh_as_default_shell.sh index 6a569a990..01d15227e 100644 --- a/test/common-utils/configure_zsh_as_default_shell.sh +++ b/test/common-utils/configure_zsh_as_default_shell.sh @@ -9,6 +9,7 @@ source dev-container-features-test-lib check "default-shell-is-zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print $7 }' | grep '/bin/zsh'" # check it overrides the ~/.zshrc with default dev containers template 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'" # Report result reportResults diff --git a/test/common-utils/scenarios.json b/test/common-utils/scenarios.json index bb65874e1..c1ee18dde 100644 --- a/test/common-utils/scenarios.json +++ b/test/common-utils/scenarios.json @@ -108,12 +108,14 @@ } }, "configure_zsh_as_default_shell": { - "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "image": "ubuntu", "features": { "common-utils": { + "installZsh": true, "configureZshAsDefaultShell": true } - } + }, + "remoteUser": "devcontainer" }, "configure_zsh_no_template_second_step": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", From 214ade5eeb5333cda528d9deeaf7c74a751b7841 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 27 Oct 2023 22:10:25 +0000 Subject: [PATCH 2/4] condion rc snippet --- src/common-utils/main.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 69477c3c4..254d58889 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -490,7 +490,10 @@ if [ "${INSTALL_ZSH}" = "true" ]; then oh_my_install_dir="${user_home}/.oh-my-zsh" template_path="${oh_my_install_dir}/templates/zshrc.zsh-template" - cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${user_rc_file} + if [ "${ZSH_RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then + cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${user_rc_file} + ZSH_RC_SNIPPET_ALREADY_ADDED="true" + fi if [ ! -d "${oh_my_install_dir}" ]; then umask g-w,o-w @@ -567,6 +570,7 @@ echo -e "\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ + ZSH_RC_SNIPPET_ALREADY_ADDED=${ZSH_RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" echo "Done!" From 89695979deb49bd705a7053ebd468914a1fb9639 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 27 Oct 2023 22:18:48 +0000 Subject: [PATCH 3/4] fix bug --- src/common-utils/main.sh | 13 +++---------- test/common-utils/configure_zsh_as_default_shell.sh | 1 + 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 254d58889..d1a977f9c 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -467,7 +467,7 @@ if [ "${INSTALL_ZSH}" = "true" ]; then else global_rc_path="/etc/zsh/zshrc" fi - cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> /etc/zshrc + cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${global_rc_path} ZSH_ALREADY_INSTALLED="true" fi @@ -483,18 +483,12 @@ if [ "${INSTALL_ZSH}" = "true" ]; then chsh --shell /bin/zsh ${USERNAME} fi - # Adapted, simplified inline Oh My Zsh! install steps that adds RC snippet and defaults to a codespaces theme. + # Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. # See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script. if [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then user_rc_file="${user_home}/.zshrc" oh_my_install_dir="${user_home}/.oh-my-zsh" template_path="${oh_my_install_dir}/templates/zshrc.zsh-template" - - if [ "${ZSH_RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then - cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${user_rc_file} - ZSH_RC_SNIPPET_ALREADY_ADDED="true" - fi - if [ ! -d "${oh_my_install_dir}" ]; then umask g-w,o-w mkdir -p ${oh_my_install_dir} @@ -518,7 +512,7 @@ if [ "${INSTALL_ZSH}" = "true" ]; then # Add devcontainer .zshrc template if [ "$INSTALL_OH_MY_ZSH_CONFIG" = "true" ]; then - echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" >> ${user_rc_file} + echo -e "$(cat "${template_path}")\nDISABLE_AUTO_UPDATE=true\nDISABLE_UPDATE_PROMPT=true" > ${user_rc_file} sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file} fi @@ -570,7 +564,6 @@ echo -e "\ LOCALE_ALREADY_SET=${LOCALE_ALREADY_SET}\n\ EXISTING_NON_ROOT_USER=${EXISTING_NON_ROOT_USER}\n\ RC_SNIPPET_ALREADY_ADDED=${RC_SNIPPET_ALREADY_ADDED}\n\ - ZSH_RC_SNIPPET_ALREADY_ADDED=${ZSH_RC_SNIPPET_ALREADY_ADDED}\n\ ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" echo "Done!" diff --git a/test/common-utils/configure_zsh_as_default_shell.sh b/test/common-utils/configure_zsh_as_default_shell.sh index 01d15227e..ef29dff6a 100644 --- a/test/common-utils/configure_zsh_as_default_shell.sh +++ b/test/common-utils/configure_zsh_as_default_shell.sh @@ -11,5 +11,6 @@ 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'" +cat /etc/zshrc # Report result reportResults From 6f9ccd8065796a86bc28d62355587168d7388091 Mon Sep 17 00:00:00 2001 From: Samruddhi Khandale Date: Fri, 27 Oct 2023 22:20:17 +0000 Subject: [PATCH 4/4] remove debugging step --- test/common-utils/configure_zsh_as_default_shell.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/common-utils/configure_zsh_as_default_shell.sh b/test/common-utils/configure_zsh_as_default_shell.sh index ef29dff6a..01d15227e 100644 --- a/test/common-utils/configure_zsh_as_default_shell.sh +++ b/test/common-utils/configure_zsh_as_default_shell.sh @@ -11,6 +11,5 @@ 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'" -cat /etc/zshrc # Report result reportResults