Skip to content

Commit

Permalink
[common-utils] Bug fix: zsh missing rc snippet (#736)
Browse files Browse the repository at this point in the history
* [common-utils] Bug fix: zsp missing rc snippet

* condion rc snippet

* fix bug

* remove debugging step
  • Loading branch information
samruddhikhandale authored Oct 27, 2023
1 parent 4c2c9f7 commit 719901a
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/common-utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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.",
Expand Down
7 changes: 6 additions & 1 deletion src/common-utils/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -456,13 +457,17 @@ 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"
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

Expand Down
1 change: 1 addition & 0 deletions test/common-utils/configure_zsh_as_default_shell.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 4 additions & 2 deletions test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit 719901a

Please sign in to comment.