Skip to content

Commit b654aff

Browse files
the78moleCopilotv-Kaniska244claude
authored
Adding OhMyZsh-Theme Option to common-utils feature (#1564)
* Initial plan * Add ohMyZshTheme option to common-utils feature Co-authored-by: the78mole <7723396+the78mole@users.noreply.github.com> * Add test scenario for custom zsh theme Co-authored-by: the78mole <7723396+the78mole@users.noreply.github.com> * Add validation for theme name to prevent injection attacks Co-authored-by: the78mole <7723396+the78mole@users.noreply.github.com> * Bump version from 2.5.7 to 2.5.8 * Add support for additional non-root user groups in common-utils feature * Bump version to 2.6.0 in devcontainer feature * "Add/update ko-fi sponsorship to $KOIFI" * Fix FUNDING.yml: ko-fi -> ko_fi (underscore) * common-utils: drop stray FUNDING.yml, bump to 2.7.0 The FUNDING.yml was added to this fork by accident and never belonged in PR #1564. It was malformed anyway — the first line held two U+FFFD replacement characters left over from an unexpanded shell variable. Upstream carries no FUNDING.yml, so the file is simply removed. Bump common-utils 2.6.0 -> 2.7.0: upstream released `sudoers` as 2.6.0, while this fork's 2.6.0 already carried `ohMyZshTheme` and `addGroups`. After the merge the same version number would describe two different option sets, so the merged feature needs its own version. * test(common-utils): move add-groups scenario off EOL debian:11 The add-groups scenario pinned debian:bullseye. Debian 11 is end-of-life and its security pool is no longer served, so the scenario now fails while installing sudo/git/gnupg2: E: Failed to fetch http://deb.debian.org/debian-security/pool/updates/ main/s/sudo/sudo_1.9.5p2-3+deb11u4_amd64.deb Upstream removed debian:11 from the CI matrices for this reason (#1736); this was the last reference left in the repository. Switched to debian:trixie, already the most used Debian image in this scenario file. Nothing in add-groups.sh is release-specific. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> * test(common-utils): use debian:bookworm for add-groups scenario Follow-up to the previous commit, which moved the scenario off EOL debian:bullseye to debian:trixie. A maintainer asked for bookworm (12) in review, so use that instead: #1564 (review comment on scenarios.json:139) Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: Kaniska <kaniska244@github.com> Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent d5f6a88 commit b654aff

7 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎src/common-utils/README.md‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,12 @@ Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-r
1919
| configureZshAsDefaultShell | Change default shell to ZSH? | boolean | false |
2020
| installOhMyZsh | Install Oh My Zsh!? | boolean | true |
2121
| installOhMyZshConfig | Allow installing the default dev container .zshrc templates? | boolean | true |
22+
| ohMyZshTheme | Oh My Zsh theme to use (e.g., 'robbyrussell', 'agnoster', 'fino'). Default is 'devcontainers'. | string | devcontainers |
2223
| upgradePackages | Upgrade OS packages? | boolean | true |
2324
| username | Enter name of a non-root user to configure or none to skip | string | automatic |
2425
| userUid | Enter UID for non-root user | string | automatic |
2526
| userGid | Enter GID for non-root user | string | automatic |
27+
| addGroups | Comma-separated list of additional groups to add the non-root user to. Groups are created if needed. | string | |
2628
| sudoers | Add sudoers entry for the non-root user | boolean | true |
2729
| nonFreePackages | Add packages from non-free Debian repository? (Debian only) | boolean | false |
2830

‎src/common-utils/devcontainer-feature.json‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"id": "common-utils",
3-
"version": "2.6.0",
3+
"version": "2.7.0",
44
"name": "Common Utilities",
55
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils",
66
"description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
@@ -25,6 +25,11 @@
2525
"default": true,
2626
"description": "Allow installing the default dev container .zshrc templates?"
2727
},
28+
"ohMyZshTheme": {
29+
"type": "string",
30+
"default": "devcontainers",
31+
"description": "Oh My Zsh theme to use (e.g., 'robbyrussell', 'agnoster', 'fino'). Default is 'devcontainers'."
32+
},
2833
"upgradePackages": {
2934
"type": "boolean",
3035
"default": true,
@@ -60,6 +65,11 @@
6065
"default": "automatic",
6166
"description": "Enter GID for non-root user"
6267
},
68+
"addGroups": {
69+
"type": "string",
70+
"default": "",
71+
"description": "Comma-separated list of additional groups to add the non-root user to. Groups are created if needed."
72+
},
6373
"sudoers": {
6474
"type": "boolean",
6575
"default": true,

‎src/common-utils/install.sh‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ INSTALL_ZSH="${INSTALLZSH:-"true"}"
1313
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
1414
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
1515
INSTALL_OH_MY_ZSH_CONFIG="${INSTALLOHMYZSHCONFIG:-"true"}"
16+
OH_MY_ZSH_THEME="${OHMYZSHTHEME:-"devcontainers"}"
1617
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
1718
USERNAME="${USERNAME:-"automatic"}"
1819
USER_UID="${UID:-"automatic"}"
1920
USER_GID="${GID:-"automatic"}"
21+
ADD_GROUPS="${ADDGROUPS:-""}"
2022
ADD_NON_FREE_PACKAGES="${NONFREEPACKAGES:-"false"}"
2123
INSTALL_SSL="${INSTALLSSL:-"true"}"
2224

‎src/common-utils/main.sh‎

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,12 @@ INSTALL_ZSH="${INSTALLZSH:-"true"}"
1313
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
1414
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
1515
INSTALL_OH_MY_ZSH_CONFIG="${INSTALLOHMYZSHCONFIG:-"true"}"
16+
OH_MY_ZSH_THEME="${OHMYZSHTHEME:-"devcontainers"}"
1617
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
1718
USERNAME="${USERNAME:-"automatic"}"
1819
USER_UID="${USERUID:-"automatic"}"
1920
USER_GID="${USERGID:-"automatic"}"
21+
ADD_GROUPS="${ADDGROUPS:-""}"
2022
SUDOERS="${SUDOERS:-"true"}"
2123
ADD_NON_FREE_PACKAGES="${NONFREEPACKAGES:-"false"}"
2224
INSTALL_SSL="${INSTALLSSL:-"true"}"
@@ -471,6 +473,22 @@ else
471473
fi
472474
fi
473475

476+
if [ "${USERNAME}" != "root" ] && [ -n "${ADD_GROUPS}" ]; then
477+
IFS=',' read -ra EXTRA_GROUPS <<< "${ADD_GROUPS}"
478+
for extra_group in "${EXTRA_GROUPS[@]}"; do
479+
extra_group="$(echo "${extra_group}" | xargs)"
480+
if [ -z "${extra_group}" ]; then
481+
continue
482+
fi
483+
484+
if ! getent group "${extra_group}" > /dev/null 2>&1; then
485+
groupadd "${extra_group}"
486+
fi
487+
488+
usermod -a -G "${extra_group}" "${USERNAME}"
489+
done
490+
fi
491+
474492
# Add add sudo support for non-root user
475493
if [ "$SUDOERS" = "true" ]; then
476494
if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" ]; then
@@ -596,7 +614,13 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
596614
if ! [ -f "${template_path}" ] || ! grep -qF "$(head -n 1 "${template_path}")" "${user_rc_file}"; then
597615
echo -e "$(cat "${template_path}")\nzstyle ':omz:update' mode disabled" > ${user_rc_file}
598616
fi
599-
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
617+
# Validate theme name to prevent injection (allow alphanumeric, hyphens, underscores, and dots)
618+
if echo "${OH_MY_ZSH_THEME}" | grep -qE '^[a-zA-Z0-9_.-]+$'; then
619+
sed -i -e "s/ZSH_THEME=.*/ZSH_THEME=\"${OH_MY_ZSH_THEME}\"/g" ${user_rc_file}
620+
else
621+
echo "Warning: Invalid theme name '${OH_MY_ZSH_THEME}'. Using default 'devcontainers' theme."
622+
sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
623+
fi
600624
fi
601625

602626
# Copy to non-root user if one is specified

‎test/common-utils/add-groups.sh‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source dev-container-features-test-lib
6+
7+
check "non-root user" id alternate
8+
check "dialout group exists" getent group dialout
9+
check "plugdev group exists" getent group plugdev
10+
check "alternate in dialout" bash -lc "id -nG alternate | tr ' ' '\n' | grep -Fx dialout"
11+
check "alternate in plugdev" bash -lc "id -nG alternate | tr ' ' '\n' | grep -Fx plugdev"
12+
13+
reportResults
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
# Optional: Import test library
6+
source dev-container-features-test-lib
7+
8+
# Definition specific tests
9+
check "zsh" zsh --version
10+
check "oh-my-zsh installed" test -d $HOME/.oh-my-zsh
11+
check "zsh theme is fino" grep 'ZSH_THEME="fino"' ~/.zshrc
12+
check "default shell is zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print \$7 }' | grep '/bin/zsh'"
13+
14+
# Report result
15+
reportResults

‎test/common-utils/scenarios.json‎

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,15 @@
135135
}
136136
}
137137
},
138+
"add-groups": {
139+
"image": "debian:bookworm",
140+
"features": {
141+
"common-utils": {
142+
"username": "alternate",
143+
"addGroups": "dialout,plugdev"
144+
}
145+
}
146+
},
138147
"username-default": {
139148
"image": "debian:trixie",
140149
"features": {
@@ -312,6 +321,18 @@
312321
"common-utils": {}
313322
}
314323
},
324+
"custom-zsh-theme": {
325+
"image": "ubuntu:jammy",
326+
"remoteUser": "devcontainer",
327+
"features": {
328+
"common-utils": {
329+
"installZsh": true,
330+
"installOhMyZsh": true,
331+
"ohMyZshTheme": "fino",
332+
"configureZshAsDefaultShell": true
333+
}
334+
}
335+
},
315336
"ubi-8": {
316337
"image": "registry.access.redhat.com/ubi8/ubi:8.10",
317338
"remoteUser": "devcontainer",

0 commit comments

Comments
 (0)