aboutsummaryrefslogtreecommitdiff
path: root/src/common-utils/main.sh
diff options
context:
space:
mode:
Diffstat (limited to 'src/common-utils/main.sh')
-rw-r--r--src/common-utils/main.sh51
1 files changed, 31 insertions, 20 deletions
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