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 01/11] 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", From 6e635a6ea0afee640bf51adcb5a758e39c7dcbea Mon Sep 17 00:00:00 2001 From: naturedamends <120284608+naturedamends@users.noreply.github.com> Date: Sun, 13 Aug 2023 21:54:43 +0100 Subject: [PATCH 02/11] Update configure_zsh_no_template_second_step.sh --- test/common-utils/configure_zsh_no_template_second_step.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common-utils/configure_zsh_no_template_second_step.sh b/test/common-utils/configure_zsh_no_template_second_step.sh index d9053c4eb..d26874d3a 100644 --- a/test/common-utils/configure_zsh_no_template_second_step.sh +++ b/test/common-utils/configure_zsh_no_template_second_step.sh @@ -6,7 +6,7 @@ set -e source dev-container-features-test-lib # Definition specific tests -check "default-zsh-with-no-zshrc" bash -c "[ -e ~/.zshrc ]" +check "default-zsh-with-no-zshrc" bash -c "[ ! -e ~/.zshrc ]" # Report result reportResults From f279594dbc3577bac5b9e74a4a5ab862c5d96eb4 Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Tue, 15 Aug 2023 12:57:27 +0000 Subject: [PATCH 03/11] Correct testing and user file permissions. --- src/common-utils/devcontainer-feature.json | 2 +- src/common-utils/main.sh | 24 +++++++++---------- .../configure_zsh_no_template_first_step.sh | 5 +--- .../configure_zsh_no_template_second_step.sh | 6 +++-- test/common-utils/scenarios.json | 6 ++--- 5 files changed, 21 insertions(+), 22 deletions(-) diff --git a/src/common-utils/devcontainer-feature.json b/src/common-utils/devcontainer-feature.json index d70848278..4eaef2128 100644 --- a/src/common-utils/devcontainer-feature.json +++ b/src/common-utils/devcontainer-feature.json @@ -1,6 +1,6 @@ { "id": "common-utils", - "version": "2.1.0", + "version": "2.1.1", "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 4cc1367c3..1a973acad 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -426,10 +426,6 @@ 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" @@ -438,7 +434,7 @@ 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 [ "$OH_MY_ZSH_CONFIG_INSTALLED" = "true" ] && [ "$INSTALL_OH_MY_ZSH_CONFIG" = "false" ]; then if [ -f "${user_rc_file}" ]; then rm "${user_rc_file}" fi @@ -490,19 +486,23 @@ if [ "${INSTALL_ZSH}" = "true" ]; then cp -f "${FEATURE_DIR}/scripts/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" ln -sf "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme" + copy_to_user_files=() # 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} - MARKED_INSTALL_OH_MY_ZSH_CONFIG="true" + copy_to_user_files+=("${oh_my_install_dir}") + [ -f "$user_rc_file" ] && copy_to_user_files+=("$user_rc_file") + chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" + OH_MY_ZSH_CONFIG_INSTALLED="true" fi # 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") + if [ "${USERNAME}" != "root" ] && (( ${#copy_to_user_files[@]} != 0 )); then cp -rf "${copy_to_user_files[@]}" /root - chown -R ${USERNAME}:${group_name} "${oh_my_install_dir}" "${user_rc_file}" + root_files=("/root/.oh-my-zsh") + [ -f /root/.zshrc ] && root_files+=("/root/.zshrc") + chown -R root:root "${root_files[@]}" fi fi fi @@ -545,7 +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}\n - MARKED_INSTALL_OH_MY_ZSH_CONFIG=${MARKED_INSTALL_OH_MY_ZSH_CONFIG}" > "${MARKER_FILE}" + ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}\n\ + OH_MY_ZSH_CONFIG_INSTALLED=${OH_MY_ZSH_CONFIG_INSTALLED}" > "${MARKER_FILE}" echo "Done!" diff --git a/test/common-utils/configure_zsh_no_template_first_step.sh b/test/common-utils/configure_zsh_no_template_first_step.sh index c62cae967..d26874d3a 100644 --- a/test/common-utils/configure_zsh_no_template_first_step.sh +++ b/test/common-utils/configure_zsh_no_template_first_step.sh @@ -6,10 +6,7 @@ set -e source dev-container-features-test-lib # Definition specific tests -function file_not_overridden() { - cat ~/.zshrc | grep 'alias fnomockalias=' | grep testingmock -} -check "default-zsh-with-no-zshrc" file_not_overridden +check "default-zsh-with-no-zshrc" bash -c "[ ! -e ~/.zshrc ]" # Report result reportResults diff --git a/test/common-utils/configure_zsh_no_template_second_step.sh b/test/common-utils/configure_zsh_no_template_second_step.sh index d26874d3a..734fa66e9 100644 --- a/test/common-utils/configure_zsh_no_template_second_step.sh +++ b/test/common-utils/configure_zsh_no_template_second_step.sh @@ -4,9 +4,11 @@ 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 ]" +function file_not_overridden() { + cat $1 | grep 'alias fnomockalias=' | grep testingmock +} +check "default-zsh-with-no-zshrc" file_not_overridden /home/devcontainer/.zshrc # Report result reportResults diff --git a/test/common-utils/scenarios.json b/test/common-utils/scenarios.json index 33693cfc4..d7b296d41 100644 --- a/test/common-utils/scenarios.json +++ b/test/common-utils/scenarios.json @@ -117,8 +117,8 @@ }, "configure_zsh_no_template_second_step": { "image": "mcr.microsoft.com/devcontainers/base:ubuntu", - "postCreateCommand": "echo alias fnomockalias=testingmock >> /root/.zshrc", - "remoteUser": "root", + "postCreateCommand": "echo alias fnomockalias=testingmock >> /home/devcontainer/.zshrc", + "remoteUser": "devcontainer", "features": { "common-utils": { "installZsh": true, @@ -128,7 +128,7 @@ }, "configure_zsh_no_template_first_step": { "image": "debian:bullseye", - "remoteUser": "vscode", + "remoteUser": "devcontainer", "features": { "common-utils": { "installZsh": true, From b40bbd6e4effdbccd8795c58279ad362a0aab9bb Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Tue, 15 Aug 2023 14:28:05 +0000 Subject: [PATCH 04/11] Handle more edge cases. --- src/common-utils/main.sh | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 1a973acad..de32583ce 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -437,6 +437,7 @@ template_path="${oh_my_install_dir}/templates/zshrc.zsh-template" if [ "$OH_MY_ZSH_CONFIG_INSTALLED" = "true" ] && [ "$INSTALL_OH_MY_ZSH_CONFIG" = "false" ]; then if [ -f "${user_rc_file}" ]; then rm "${user_rc_file}" + OH_MY_ZSH_CONFIG_INSTALLED="false" fi fi @@ -466,6 +467,8 @@ 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 + copy_to_user_files=() + copy_to_user_files+=("${oh_my_install_dir}") if [ ! -d "${oh_my_install_dir}" ]; then umask g-w,o-w mkdir -p ${oh_my_install_dir} @@ -491,17 +494,19 @@ 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} - copy_to_user_files+=("${oh_my_install_dir}") - [ -f "$user_rc_file" ] && copy_to_user_files+=("$user_rc_file") - chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" + copy_to_user_files+=("$user_rc_file") OH_MY_ZSH_CONFIG_INSTALLED="true" + local_omz_config_installed="true" fi + # Set permissions of new zsh for current user + chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" + # Copy to alternate user if one is specified if [ "${USERNAME}" != "root" ] && (( ${#copy_to_user_files[@]} != 0 )); then cp -rf "${copy_to_user_files[@]}" /root root_files=("/root/.oh-my-zsh") - [ -f /root/.zshrc ] && root_files+=("/root/.zshrc") + [ "$local_omz_config_installed" = "true" ] && root_files+=("/root/.zshrc") chown -R root:root "${root_files[@]}" fi fi From 431729ffdc7fee44c334dbf2c0d6bfb991bdd532 Mon Sep 17 00:00:00 2001 From: naturedamends <120284608+naturedamends@users.noreply.github.com> Date: Tue, 15 Aug 2023 22:49:41 +0100 Subject: [PATCH 05/11] Update main.sh --- src/common-utils/main.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index de32583ce..37f02ddbf 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -489,7 +489,6 @@ if [ "${INSTALL_ZSH}" = "true" ]; then cp -f "${FEATURE_DIR}/scripts/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" ln -sf "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme" - copy_to_user_files=() # 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} From 108ab538eb1341c95aa00fcc9befe3de892344da Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Wed, 16 Aug 2023 20:37:55 +0000 Subject: [PATCH 06/11] Improve edge cases, clean up. --- src/common-utils/main.sh | 43 +++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index 37f02ddbf..cc9052ad9 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -442,6 +442,8 @@ if [ "$OH_MY_ZSH_CONFIG_INSTALLED" = "true" ] && [ "$INSTALL_OH_MY_ZSH_CONFIG" = fi if [ "${INSTALL_ZSH}" = "true" ]; then + umask g-w,o-w + if [ "${ZSH_ALREADY_INSTALLED}" != "true" ]; then if [ "${ADJUSTED_ID}" = "rhel" ]; then global_rc_path="/etc/zshrc" @@ -464,14 +466,11 @@ 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. - # See https://github.com/ohmyzsh/ohmyzsh/blob/master/tools/install.sh for official script. if [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then - copy_to_user_files=() - copy_to_user_files+=("${oh_my_install_dir}") if [ ! -d "${oh_my_install_dir}" ]; then - umask g-w,o-w mkdir -p ${oh_my_install_dir} + # 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. git clone --depth=1 \ -c core.eol=lf \ -c core.autocrlf=false \ @@ -479,34 +478,42 @@ if [ "${INSTALL_ZSH}" = "true" ]; then -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 - GIT_WORK_TREE="${oh_my_install_dir}" GIT_DIR="${oh_my_install_dir}/.git" 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 - 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 -sf "${oh_my_install_dir}/custom/themes/devcontainers.zsh-theme" "${oh_my_install_dir}/custom/themes/codespaces.zsh-theme" + # Add dev containers theme + zsh_theme_dir_target="${oh_my_install_dir}/custom/themes" + devcontainers_theme_target="${zsh_theme_dir_target}/devcontainers.zsh-theme" + codespaces_theme_target="${zsh_theme_dir_target}/codespaces.zsh-theme" + theme_template_path="${FEATURE_DIR}/scripts/devcontainers.zsh-theme" + mkdir -p "${zsh_theme_dir_target}" + cp -f "${theme_template_path}" "${devcontainers_theme_target}" + cp -f "${theme_template_path}" "${codespaces_theme_target}" # 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} - copy_to_user_files+=("$user_rc_file") OH_MY_ZSH_CONFIG_INSTALLED="true" - local_omz_config_installed="true" fi - # Set permissions of new zsh for current user + # Prepare build file paths + copy_to_user_files=("${oh_my_install_dir}") + root_file_paths=("/root/.oh-my-zsh") + if [ "$INSTALL_OH_MY_ZSH_CONFIG" = "true" ]; then + root_file_paths+=("/root/.zshrc") + copy_to_user_files+=("$user_rc_file") + fi + + # Set zsh file permissions for current user chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" # Copy to alternate user if one is specified - if [ "${USERNAME}" != "root" ] && (( ${#copy_to_user_files[@]} != 0 )); then + if [ "${USERNAME}" != "root" ]; then cp -rf "${copy_to_user_files[@]}" /root - root_files=("/root/.oh-my-zsh") - [ "$local_omz_config_installed" = "true" ] && root_files+=("/root/.zshrc") - chown -R root:root "${root_files[@]}" + chown -R root:root "${root_file_paths[@]}" fi fi fi From 4c68aee6b0313c8e7bdba391d8f6aab93c458d91 Mon Sep 17 00:00:00 2001 From: naturedamends <120284608+naturedamends@users.noreply.github.com> Date: Wed, 16 Aug 2023 23:00:36 +0100 Subject: [PATCH 07/11] Update main.sh --- src/common-utils/main.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index cc9052ad9..debe108d5 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -507,14 +507,14 @@ if [ "${INSTALL_ZSH}" = "true" ]; then copy_to_user_files+=("$user_rc_file") fi - # Set zsh file permissions for current user - chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" - # Copy to alternate user if one is specified if [ "${USERNAME}" != "root" ]; then cp -rf "${copy_to_user_files[@]}" /root chown -R root:root "${root_file_paths[@]}" fi + + # Set zsh file permissions for current user + chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" fi fi From dc73b2d9ba27d33ad17fe570b6e40679e9ac5585 Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Thu, 17 Aug 2023 18:51:49 +0000 Subject: [PATCH 08/11] Change testing and coding standards. --- src/common-utils/main.sh | 61 ++++++++++++++++++++------------------- test/common-utils/test.sh | 2 ++ 2 files changed, 33 insertions(+), 30 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index debe108d5..a0e4bb3fd 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -427,13 +427,17 @@ if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then fi # 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" +omz_rc_filename=".zshrc" +omz_source_dirname=".oh-my-zsh" +user_rc_file="${user_home}/${omz_rc_filename}" +user_omz_install_dir="${user_home}/${omz_source_dirname}" +template_path="${user_omz_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 +# Given previous step configured ~/.zshrc, +# When installOhMyZshConfig is false, done before INSTALL_ZSH since +# Or where installOhMyZshconfig false, and installZsh false +# Then remove the file if [ "$OH_MY_ZSH_CONFIG_INSTALLED" = "true" ] && [ "$INSTALL_OH_MY_ZSH_CONFIG" = "false" ]; then if [ -f "${user_rc_file}" ]; then rm "${user_rc_file}" @@ -467,54 +471,51 @@ if [ "${INSTALL_ZSH}" = "true" ]; then fi if [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then - if [ ! -d "${oh_my_install_dir}" ]; then - mkdir -p ${oh_my_install_dir} - # 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. + # 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. + omz_added_filesnames=("${omz_source_dirname}") + if [ ! -d "${user_omz_install_dir}" ]; then + mkdir -p ${user_omz_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 + "https://github.com/ohmyzsh/ohmyzsh" "${user_omz_install_dir}" 2>&1 # Shrink git while still enabling updates - GIT_WORK_TREE="${oh_my_install_dir}" GIT_DIR="${oh_my_install_dir}/.git" git repack\ + GIT_WORK_TREE="${user_omz_install_dir}" GIT_DIR="${user_omz_install_dir}/.git" git repack\ -a -d -f --depth=1 --window=1 fi # Add dev containers theme - zsh_theme_dir_target="${oh_my_install_dir}/custom/themes" - devcontainers_theme_target="${zsh_theme_dir_target}/devcontainers.zsh-theme" - codespaces_theme_target="${zsh_theme_dir_target}/codespaces.zsh-theme" + user_omz_theme_filepath="${user_omz_install_dir}/custom/themes" + user_devcontainer_theme_target="${user_omz_theme_filepath}/devcontainers.zsh-theme" + user_codespaces_theme_target="${user_omz_theme_filepath}/codespaces.zsh-theme" theme_template_path="${FEATURE_DIR}/scripts/devcontainers.zsh-theme" - mkdir -p "${zsh_theme_dir_target}" - cp -f "${theme_template_path}" "${devcontainers_theme_target}" - cp -f "${theme_template_path}" "${codespaces_theme_target}" + mkdir -p "${user_omz_theme_filepath}" + cp -f "${theme_template_path}" "${user_devcontainer_theme_target}" + cp -f "${theme_template_path}" "${user_codespaces_theme_target}" # 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} OH_MY_ZSH_CONFIG_INSTALLED="true" + omz_added_filesnames+=("${omz_rc_filename}") fi - # Prepare build file paths - copy_to_user_files=("${oh_my_install_dir}") - root_file_paths=("/root/.oh-my-zsh") - if [ "$INSTALL_OH_MY_ZSH_CONFIG" = "true" ]; then - root_file_paths+=("/root/.zshrc") - copy_to_user_files+=("$user_rc_file") - fi + user_omz_filepaths=( "${omz_added_filesnames[@]/#/$user_home/}" ) - # Copy to alternate user if one is specified if [ "${USERNAME}" != "root" ]; then - cp -rf "${copy_to_user_files[@]}" /root - chown -R root:root "${root_file_paths[@]}" + # Copy files to alternate user if one is specified + cp -rf "${user_omz_filepaths[@]}" /root + # Set permissions for root user + chown -R root:root "${omz_added_filesnames[@]/#//root/}" fi - - # Set zsh file permissions for current user - chown -R ${USERNAME}:${group_name} "${copy_to_user_files[@]}" + + # Set permissions for current user + chown -R "${USERNAME}:${group_name}" "${user_omz_filepaths[@]}" fi fi diff --git a/test/common-utils/test.sh b/test/common-utils/test.sh index 5e16a33c7..c720b175f 100755 --- a/test/common-utils/test.sh +++ b/test/common-utils/test.sh @@ -13,6 +13,8 @@ check "zsh" zsh --version check "ps" ps --version check "Oh My Zsh! theme" test -e $HOME/.oh-my-zsh/custom/themes/devcontainers.zsh-theme check "zsh theme symlink" test -e $HOME/.oh-my-zsh/custom/themes/codespaces.zsh-theme +check "zsh theme filename" test -e $HOME/.oh-my-zsh/custom/themes/codespaces.zsh-theme +check "oh-my-zsh executes" zsh -c 'source $HOME/.zshrc && echo $0 | grep zsh' # Report result reportResults \ No newline at end of file From 3150f0d1f1ff3144a32fbeda7b815bb5733e0775 Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Thu, 17 Aug 2023 18:56:46 +0000 Subject: [PATCH 09/11] Remove old test. --- test/common-utils/test.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/test/common-utils/test.sh b/test/common-utils/test.sh index c720b175f..743d6664f 100755 --- a/test/common-utils/test.sh +++ b/test/common-utils/test.sh @@ -12,7 +12,6 @@ check "git" git --version check "zsh" zsh --version check "ps" ps --version check "Oh My Zsh! theme" test -e $HOME/.oh-my-zsh/custom/themes/devcontainers.zsh-theme -check "zsh theme symlink" test -e $HOME/.oh-my-zsh/custom/themes/codespaces.zsh-theme check "zsh theme filename" test -e $HOME/.oh-my-zsh/custom/themes/codespaces.zsh-theme check "oh-my-zsh executes" zsh -c 'source $HOME/.zshrc && echo $0 | grep zsh' From 836f9e9aa7d3fd89d26066cb4ddcb40ceef8c233 Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Fri, 18 Aug 2023 14:45:50 +0000 Subject: [PATCH 10/11] Remove removing files. --- src/common-utils/main.sh | 49 +++++++++++++++------------------------- 1 file changed, 18 insertions(+), 31 deletions(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index a0e4bb3fd..cda7a71e7 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -376,6 +376,15 @@ if [ "${USERNAME}" != "root" ] && [ "${EXISTING_NON_ROOT_USER}" != "${USERNAME}" EXISTING_NON_ROOT_USER="${USERNAME}" fi +# ********************************* +# ** Ensure config directory ** +# ********************************* +user_config_dir="${user_home}/.config" +if [ ! -d "${user_config_dir}" ]; then + mkdir -p "${user_config_dir}" + chown ${USERNAME}:${group_name} "${user_config_dir}" +fi + # ********************************* # ** Shell customization section ** # ********************************* @@ -427,24 +436,6 @@ if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then fi # Optionally configure zsh and Oh My Zsh! -omz_rc_filename=".zshrc" -omz_source_dirname=".oh-my-zsh" -user_rc_file="${user_home}/${omz_rc_filename}" -user_omz_install_dir="${user_home}/${omz_source_dirname}" -template_path="${user_omz_install_dir}/templates/zshrc.zsh-template" - -# Allow upstream steps to use installOhMyZshConfig false -# Given previous step configured ~/.zshrc, -# When installOhMyZshConfig is false, done before INSTALL_ZSH since -# Or where installOhMyZshconfig false, and installZsh false -# Then remove the file -if [ "$OH_MY_ZSH_CONFIG_INSTALLED" = "true" ] && [ "$INSTALL_OH_MY_ZSH_CONFIG" = "false" ]; then - if [ -f "${user_rc_file}" ]; then - rm "${user_rc_file}" - OH_MY_ZSH_CONFIG_INSTALLED="false" - fi -fi - if [ "${INSTALL_ZSH}" = "true" ]; then umask g-w,o-w @@ -473,6 +464,8 @@ if [ "${INSTALL_ZSH}" = "true" ]; then if [ "${INSTALL_OH_MY_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. + omz_source_dirname=".oh-my-zsh" + user_omz_install_dir="${user_home}/${omz_source_dirname}" omz_added_filesnames=("${omz_source_dirname}") if [ ! -d "${user_omz_install_dir}" ]; then mkdir -p ${user_omz_install_dir} @@ -497,13 +490,16 @@ if [ "${INSTALL_ZSH}" = "true" ]; then cp -f "${theme_template_path}" "${user_devcontainer_theme_target}" cp -f "${theme_template_path}" "${user_codespaces_theme_target}" - # 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} + # Add devcontainer .zshrc template + omz_rc_filename=".zshrc" + user_rc_file="${user_home}/${omz_rc_filename}" + omz_zshrc_template_path="${user_omz_install_dir}/templates/zshrc.zsh-template" + echo -e "$(cat "${omz_zshrc_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_ZSH_CONFIG_INSTALLED="true" omz_added_filesnames+=("${omz_rc_filename}") fi + # TODO remove installed files from previous step user_omz_filepaths=( "${omz_added_filesnames[@]/#/$user_home/}" ) @@ -519,14 +515,6 @@ if [ "${INSTALL_ZSH}" = "true" ]; then fi fi -# ********************************* -# ** Ensure config directory ** -# ********************************* -user_config_dir="${user_home}/.config" -if [ ! -d "${user_config_dir}" ]; then - mkdir -p "${user_config_dir}" - chown ${USERNAME}:${group_name} "${user_config_dir}" -fi # **************************** # ** Utilities and commands ** @@ -557,7 +545,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_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}\n\ - OH_MY_ZSH_CONFIG_INSTALLED=${OH_MY_ZSH_CONFIG_INSTALLED}" > "${MARKER_FILE}" + ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}\n" > "${MARKER_FILE}" echo "Done!" From 1724e1477585c4356ca08d425499881261dea4bf Mon Sep 17 00:00:00 2001 From: natured_amends0p Date: Fri, 18 Aug 2023 14:52:16 +0000 Subject: [PATCH 11/11] Lines to previous state. --- src/common-utils/main.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/common-utils/main.sh b/src/common-utils/main.sh index cda7a71e7..1c87b0372 100644 --- a/src/common-utils/main.sh +++ b/src/common-utils/main.sh @@ -545,6 +545,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_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}\n" > "${MARKER_FILE}" + ZSH_ALREADY_INSTALLED=${ZSH_ALREADY_INSTALLED}" > "${MARKER_FILE}" echo "Done!"