-
Notifications
You must be signed in to change notification settings - Fork 617
Common-utils: various cleaning things from other pr. #653
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f5b5e6a
6e635a6
f279594
b40bbd6
431729f
108ab53
4c68aee
dc73b2d
3150f0d
836f9e9
1724e14
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 ** | ||
| # ********************************* | ||
|
|
@@ -428,6 +437,8 @@ fi | |
|
|
||
| # Optionally configure zsh and Oh My Zsh! | ||
| 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" | ||
|
|
@@ -450,57 +461,60 @@ 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 | ||
| 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} | ||
| # 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} | ||
| 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 | ||
| cd "${oh_my_install_dir}" | ||
| git repack -a -d -f --depth=1 --window=1 | ||
| 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 | ||
| 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 | ||
| 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 "${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} | ||
| # 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} | ||
| omz_added_filesnames+=("${omz_rc_filename}") | ||
| fi | ||
| # TODO remove installed files from previous step | ||
|
|
||
| user_omz_filepaths=( "${omz_added_filesnames[@]/#/$user_home/}" ) | ||
|
|
||
| # Copy to non-root 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") | ||
| cp -rf "${copy_to_user_files[@]}" /root | ||
| chown -R ${USERNAME}:${group_name} "${oh_my_install_dir}" "${user_rc_file}" | ||
| # 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/}" | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious, why is this needed?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Security. User scripts making it into root and being sourced. Would be tempted to copy from a mktmp-d. To prevent copying any unknown files Ie custom shell scripts Nvm. I will close pr. |
||
| fi | ||
|
|
||
| # Set permissions for current user | ||
| chown -R "${USERNAME}:${group_name}" "${user_omz_filepaths[@]}" | ||
| 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 ** | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,8 @@ 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 | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would take the meaning of -e and symlink to mean xor... not sure Samruddhi Khandale (@samruddhikhandale) |
||
| check "oh-my-zsh executes" zsh -c 'source $HOME/.zshrc && echo $0 | grep zsh' | ||
|
|
||
| # Report result | ||
| reportResults | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
features/src/common-utils/main.sh
Lines 392 to 400 in 1724e14
user_home, hence, should this be added after that?Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah good catch. I want a clean home directory, so if im going to program this, I want it before any rc files. Not sure how much of a pain this is going to be
I came to the conclusion that you would not want any related flags in common-utils
Is the shell-setup feature going to be in features repo?
Then would it be prudent to add a flag to prevent any rc generation here
Thus you can enable the following to get equal functionality:
Common-utils rc false
Shell-setup shell zsh
I'm not familiar with any other fancy shells. Other than one I heard of that has a consistent output table format.
Would you consider adding a shell-setup to the features repo?
Sorry for bad grammar on tablet