aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authornaturedamends <120284608+naturedamends@users.noreply.github.com>2023-08-12 02:01:57 +0300
committerGitHub <noreply@github.com>2023-08-12 02:01:57 +0300
commitbe082b0ef5f0f3795708cd1a6c37a427d8c0bb73 (patch)
tree431f504174ec7e2ab094c6868d4fbe0b096eaaf3 /src
parent9e75db9a1dbcc245f94707c0917470143c17595b (diff)
Common utils: Add config to remove zsh rc files from (#614)feature_common-utils_2.1.0
* Add config to remove zsh rc files from common-utils. * Bump version and add config to install script. * Checks preventing excess writing to .zshrc. * Change devcontainer feature option name. * Coding standards. * Favour adding feature via config and default to overriding .zshrc with dev-container default template. * Update devcontainer-feature.json * Update devcontainer-feature.json * Update src/common-utils/devcontainer-feature.json Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com> * Update src/common-utils/devcontainer-feature.json Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com> * Testing for using devcontainer .zshrc template file. * Coding standards. * Coding standards. * Update configure_zsh_as_default_shell_no_template.sh * Grammar in configure_zsh_as_default_shell.sh * Testing accounts for marked file cache (#4) * Account for mark file in testing. * Remove some debugging and tests back * Add back tests? * Update configure_zsh_no_template.sh --------- Co-authored-by: Samruddhi Khandale <samruddhikhandale@github.com>
Diffstat (limited to 'src')
-rw-r--r--src/common-utils/devcontainer-feature.json7
-rwxr-xr-xsrc/common-utils/install.sh1
-rw-r--r--src/common-utils/main.sh51
3 files changed, 38 insertions, 21 deletions
diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json
index a924aa7..d708482 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.1.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.",
@@ -20,6 +20,11 @@
"default": true,
"description": "Install Oh My Zsh!?"
},
+ "installOhMyZshConfig": {
+ "type": "boolean",
+ "default": true,
+ "description": "Allow installing the default dev container .zshrc templates?"
+ },
"upgradePackages": {
"type": "boolean",
"default": true,
diff --git a/src/common-utils/install.sh b/src/common-utils/install.sh
index d08a2f2..8f1ece4 100755
--- a/src/common-utils/install.sh
+++ b/src/common-utils/install.sh
@@ -12,6 +12,7 @@ set -e
INSTALL_ZSH="${INSTALLZSH:-"true"}"
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
+INSTALL_OH_MY_ZSH_CONFIG="${INSTALLOHMYZSHCONFIG:-"true"}"
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"automatic"}"
USER_UID="${UID:-"automatic"}"
diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh
index 6d5ac07..d3f7ef2 100644
--- a/src/common-utils/main.sh
+++ b/src/common-utils/main.sh
@@ -12,6 +12,7 @@ set -e
INSTALL_ZSH="${INSTALLZSH:-"true"}"
CONFIGURE_ZSH_AS_DEFAULT_SHELL="${CONFIGUREZSHASDEFAULTSHELL:-"false"}"
INSTALL_OH_MY_ZSH="${INSTALLOHMYZSH:-"true"}"
+INSTALL_OH_MY_ZSH_CONFIG="${INSTALLOHMYZSHCONFIG:-"true"}"
UPGRADE_PACKAGES="${UPGRADEPACKAGES:-"true"}"
USERNAME="${USERNAME:-"automatic"}"
USER_UID="${USERUID:-"automatic"}"
@@ -390,7 +391,8 @@ else
fi
# Restore user .bashrc / .profile / .zshrc defaults from skeleton file if it doesn't exist or is empty
-possible_rc_files=( ".bashrc" ".profile" ".zshrc" )
+possible_rc_files=( ".bashrc" ".profile" )
+[ "$INSTALL_OH_MY_ZSH_CONFIG" == "true" ] && possible_rc_files+=('.zshrc')
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
@@ -450,33 +452,42 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
# 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.
- oh_my_install_dir="${user_home}/.oh-my-zsh"
- if [ ! -d "${oh_my_install_dir}" ] && [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then
- template_path="${oh_my_install_dir}/templates/zshrc.zsh-template"
+ if [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then
user_rc_file="${user_home}/.zshrc"
- umask g-w,o-w
- mkdir -p ${oh_my_install_dir}
- git clone --depth=1 \
- -c core.eol=lf \
- -c core.autocrlf=false \
- -c fsck.zeroPaddedFilemode=ignore \
- -c fetch.fsck.zeroPaddedFilemode=ignore \
- -c receive.fsck.zeroPaddedFilemode=ignore \
- "https://github.com/ohmyzsh/ohmyzsh" "${oh_my_install_dir}" 2>&1
- 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}
+ oh_my_install_dir="${user_home}/.oh-my-zsh"
+ template_path="${oh_my_install_dir}/templates/zshrc.zsh-template"
+ if [ ! -d "${oh_my_install_dir}" ]; then
+ umask g-w,o-w
+ mkdir -p ${oh_my_install_dir}
+ git clone --depth=1 \
+ -c core.eol=lf \
+ -c core.autocrlf=false \
+ -c fsck.zeroPaddedFilemode=ignore \
+ -c fetch.fsck.zeroPaddedFilemode=ignore \
+ -c receive.fsck.zeroPaddedFilemode=ignore \
+ "https://github.com/ohmyzsh/ohmyzsh" "${oh_my_install_dir}" 2>&1
+
+ # Shrink git while still enabling updates
+ cd "${oh_my_install_dir}"
+ git repack -a -d -f --depth=1 --window=1
+ fi
# Add Dev Containers theme
mkdir -p ${oh_my_install_dir}/custom/themes
cp -f "${FEATURE_DIR}/scripts/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme"
- ln -s "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme"
+ ln -sf "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme"
+
+ # 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}
+ sed -i -e 's/ZSH_THEME=.*/ZSH_THEME="devcontainers"/g' ${user_rc_file}
+ fi
- # Shrink git while still enabling updates
- cd "${oh_my_install_dir}"
- git repack -a -d -f --depth=1 --window=1
# Copy to non-root user if one is specified
if [ "${USERNAME}" != "root" ]; then
- cp -rf "${user_rc_file}" "${oh_my_install_dir}" /root
+ copy_to_user_files=("${oh_my_install_dir}")
+ [ -f "$user_rc_file" ] && copy_to_user_files+=("$user_rc_file")
+ cp -rf "${copy_to_user_files[@]}" /root
chown -R ${USERNAME}:${group_name} "${oh_my_install_dir}" "${user_rc_file}"
fi
fi