From f5b5e6a4d60f6df73c097e4751721690eac439e4 Mon Sep 17 00:00:00 2001 From: naturedamends <120284608+naturedamends@users.noreply.github.com> Date: Sun, 13 Aug 2023 16:58:45 +0100 Subject: [PATCH] Enable installOhMyZshConfig false for upstream images. --- src/common-utils/main.sh | 29 ++++++++++++++----- ...> configure_zsh_no_template_first_step.sh} | 0 .../configure_zsh_no_template_second_step.sh | 12 ++++++++ test/common-utils/scenarios.json | 12 +++++++- 4 files changed, 45 insertions(+), 8 deletions(-) rename test/common-utils/{configure_zsh_no_template.sh => configure_zsh_no_template_first_step.sh} (100%) create mode 100644 test/common-utils/configure_zsh_no_template_second_step.sh diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index d3f7ef267..4cc1367c3 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -426,7 +426,24 @@ if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then RC_SNIPPET_ALREADY_ADDED="true" fi +echo "USERNAME: $USERNAME" +ls -la ~ +ls -la "${user_home}" + # Optionally configure zsh and Oh My Zsh! +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" + +# Given previous step configured ~/.zshrc then remove it, +# where installOhMyZshConfig is false. +# Allow upstream steps to use installOhMyZshConfig false +if [ "$MARKED_INSTALL_OH_MY_ZSH_CONFIG" = "true" ] && [ "$INSTALL_OH_MY_ZSH_CONFIG" = "false" ]; then + if [ -f "${user_rc_file}" ]; then + rm "${user_rc_file}" + fi +fi + if [ "${INSTALL_ZSH}" = "true" ]; then if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then if [ "${ADJUSTED_ID}" = "rhel" ]; then @@ -453,9 +470,6 @@ 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. 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 [ ! -d "${oh_my_install_dir}" ]; then umask g-w,o-w mkdir -p ${oh_my_install_dir} @@ -468,8 +482,7 @@ if [ "${INSTALL_ZSH}" = "true" ]; then "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 + GIT_WORK_TREE="${oh_my_install_dir}" GIT_DIR="${oh_my_install_dir}/.git" git repack -a -d -f --depth=1 --window=1 fi # Add Dev Containers theme @@ -481,9 +494,10 @@ if [ "${INSTALL_ZSH}" = "true" ]; then 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} + MARKED_INSTALL_OH_MY_ZSH_CONFIG="true" fi - # Copy to non-root user if one is specified + # Copy to alternate user if one is specified if [ "${USERNAME}" != "root" ]; then copy_to_user_files=("${oh_my_install_dir}") [ -f "$user_rc_file" ] && copy_to_user_files+=("$user_rc_file") @@ -531,6 +545,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_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" + ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}\n + MARKED_INSTALL_OH_MY_ZSH_CONFIG=${MARKED_INSTALL_OH_MY_ZSH_CONFIG}" > "${MARKER_FILE}" echo "Done!" diff --git a/test/common-utils/configure_zsh_no_template.sh b/test/common-utils/configure_zsh_no_template_first_step.sh similarity index 100% rename from test/common-utils/configure_zsh_no_template.sh rename to test/common-utils/configure_zsh_no_template_first_step.sh diff --git a/test/common-utils/configure_zsh_no_template_second_step.sh b/test/common-utils/configure_zsh_no_template_second_step.sh new file mode 100644 index 000000000..d9053c4eb --- /dev/null +++ b/test/common-utils/configure_zsh_no_template_second_step.sh @@ -0,0 +1,12 @@ +#!/bin/bash + +set -e + +# Optional: Import test library +source dev-container-features-test-lib + +# Definition specific tests +check "default-zsh-with-no-zshrc" bash -c "[ -e ~/.zshrc ]" + +# Report result +reportResults diff --git a/test/common-utils/scenarios.json b/test/common-utils/scenarios.json index 904a47bac..33693cfc4 100644 --- a/test/common-utils/scenarios.json +++ b/test/common-utils/scenarios.json @@ -115,7 +115,7 @@ } } }, - "configure_zsh_no_template": { + "configure_zsh_no_template_second_step": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", "postCreateCommand": "echo alias fnomockalias=testingmock >> /root/.zshrc", "remoteUser": "root", @@ -126,6 +126,16 @@ } } }, + "configure_zsh_no_template_first_step": { + "image": "debian:bullseye", + "remoteUser": "vscode", + "features": { + "common-utils": { + "installZsh": true, + "installOhMyZshConfig": false + } + } + }, "config-subdirectory": { "image": "alpine", "remoteUser": "devcontainer",