Unverified Commit 1869e593 authored by Stephen A. Imhoff's avatar Stephen A. Imhoff Committed by GitHub

Create .config directory in common-utils (#547)

* Add test case for mounted subdirectory.

* Correct some trailing whitespace.

* Correct variable name to better reflect status as user home path.

* Add config directory creation.

* Remove extra debug line.

* Bump feature version.

* Mount host user home directory as "subdirectory"

* Correct test naming, run test in explicit bash shell.
parent 4420cd5d
{
"id": "common-utils",
"version": "2.0.9",
"version": "2.0.10",
"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.",
......
......@@ -380,12 +380,12 @@ fi
# *********************************
if [ "${USERNAME}" = "root" ]; then
user_rc_path="/root"
user_home="/root"
else
user_rc_path="/home/${USERNAME}"
if [ ! -d "${user_rc_path}" ]; then
mkdir -p "${user_rc_path}"
chown ${USERNAME}:${group_name} "${user_rc_path}"
user_home="/home/${USERNAME}"
if [ ! -d "${user_home}" ]; then
mkdir -p "${user_home}"
chown ${USERNAME}:${group_name} "${user_home}"
fi
fi
......@@ -393,9 +393,9 @@ fi
possible_rc_files=( ".bashrc" ".profile" ".zshrc" )
for rc_file in "${possible_rc_files[@]}"; do
if [ -f "/etc/skel/${rc_file}" ]; then
if [ ! -e "${user_rc_path}/${rc_file}" ] || [ ! -s "${user_rc_path}/${rc_file}" ]; then
cp "/etc/skel/${rc_file}" "${user_rc_path}/${rc_file}"
chown ${USERNAME}:${group_name} "${user_rc_path}/${rc_file}"
if [ ! -e "${user_home}/${rc_file}" ] || [ ! -s "${user_home}/${rc_file}" ]; then
cp "/etc/skel/${rc_file}" "${user_home}/${rc_file}"
chown ${USERNAME}:${group_name} "${user_home}/${rc_file}"
fi
fi
done
......@@ -416,10 +416,10 @@ if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then
;;
esac
cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${global_rc_path}
cat "${FEATURE_DIR}/scripts/bash_theme_snippet.sh" >> "${user_rc_path}/.bashrc"
cat "${FEATURE_DIR}/scripts/bash_theme_snippet.sh" >> "${user_home}/.bashrc"
if [ "${USERNAME}" != "root" ]; then
cat "${FEATURE_DIR}/scripts/bash_theme_snippet.sh" >> "/root/.bashrc"
chown ${USERNAME}:${group_name} "${user_rc_path}/.bashrc"
chown ${USERNAME}:${group_name} "${user_home}/.bashrc"
fi
RC_SNIPPET_ALREADY_ADDED="true"
fi
......@@ -442,10 +442,10 @@ 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_rc_path}/.oh-my-zsh"
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"
user_rc_file="${user_rc_path}/.zshrc"
user_rc_file="${user_home}/.zshrc"
umask g-w,o-w
mkdir -p ${oh_my_install_dir}
git clone --depth=1 \
......@@ -474,6 +474,15 @@ 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 **
# ****************************
......
#!/bin/bash
set -e
# Optional: Import test library
source dev-container-features-test-lib
# Definition specific tests
check "owned-config-sub-directory" bash -c "ls -ld ~/.config/subdirectory | awk '{print $3}' | grep 'devcontainer'"
check "owned-config-directory" bash -c "ls -ld ~/.config | awk '{print $3}' | grep 'devcontainer'"
# Report result
reportResults
......@@ -115,6 +115,16 @@
}
}
},
"config-subdirectory": {
"image": "alpine",
"remoteUser": "devcontainer",
"features": {
"common-utils": {}
},
"mounts": [
"source=${localEnv:HOME},target=/home/devcontainer/.config/subdirectory,type=bind,readonly"
]
},
"alpine-3-14": {
"image": "alpine:3.14",
"remoteUser": "devcontainer",
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment