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", "id": "common-utils",
"version": "2.0.9", "version": "2.0.10",
"name": "Common Utilities", "name": "Common Utilities",
"documentationURL": "https://github.com/devcontainers/features/tree/main/src/common-utils", "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.", "description": "Installs a set of common command line utilities, Oh My Zsh!, and sets up a non-root user.",
......
...@@ -380,12 +380,12 @@ fi ...@@ -380,12 +380,12 @@ fi
# ********************************* # *********************************
if [ "${USERNAME}" = "root" ]; then if [ "${USERNAME}" = "root" ]; then
user_rc_path="/root" user_home="/root"
else else
user_rc_path="/home/${USERNAME}" user_home="/home/${USERNAME}"
if [ ! -d "${user_rc_path}" ]; then if [ ! -d "${user_home}" ]; then
mkdir -p "${user_rc_path}" mkdir -p "${user_home}"
chown ${USERNAME}:${group_name} "${user_rc_path}" chown ${USERNAME}:${group_name} "${user_home}"
fi fi
fi fi
...@@ -393,9 +393,9 @@ fi ...@@ -393,9 +393,9 @@ fi
possible_rc_files=( ".bashrc" ".profile" ".zshrc" ) possible_rc_files=( ".bashrc" ".profile" ".zshrc" )
for rc_file in "${possible_rc_files[@]}"; do for rc_file in "${possible_rc_files[@]}"; do
if [ -f "/etc/skel/${rc_file}" ]; then if [ -f "/etc/skel/${rc_file}" ]; then
if [ ! -e "${user_rc_path}/${rc_file}" ] || [ ! -s "${user_rc_path}/${rc_file}" ]; then if [ ! -e "${user_home}/${rc_file}" ] || [ ! -s "${user_home}/${rc_file}" ]; then
cp "/etc/skel/${rc_file}" "${user_rc_path}/${rc_file}" cp "/etc/skel/${rc_file}" "${user_home}/${rc_file}"
chown ${USERNAME}:${group_name} "${user_rc_path}/${rc_file}" chown ${USERNAME}:${group_name} "${user_home}/${rc_file}"
fi fi
fi fi
done done
...@@ -416,10 +416,10 @@ if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then ...@@ -416,10 +416,10 @@ if [ "${RC_SNIPPET_ALREADY_ADDED}" != "true" ]; then
;; ;;
esac esac
cat "${FEATURE_DIR}/scripts/rc_snippet.sh" >> ${global_rc_path} 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 if [ "${USERNAME}" != "root" ]; then
cat "${FEATURE_DIR}/scripts/bash_theme_snippet.sh" >> "/root/.bashrc" 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 fi
RC_SNIPPET_ALREADY_ADDED="true" RC_SNIPPET_ALREADY_ADDED="true"
fi fi
...@@ -442,10 +442,10 @@ if [ "${INSTALL_ZSH}" = "true" ]; then ...@@ -442,10 +442,10 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
# Adapted, simplified inline Oh My Zsh! install steps that adds, defaults to a codespaces theme. # 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. # 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 if [ ! -d "${oh_my_install_dir}" ] && [ "${INSTALL_OH_MY_ZSH}" = "true" ]; then
template_path="${oh_my_install_dir}/templates/zshrc.zsh-template" 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 umask g-w,o-w
mkdir -p ${oh_my_install_dir} mkdir -p ${oh_my_install_dir}
git clone --depth=1 \ git clone --depth=1 \
...@@ -474,6 +474,15 @@ if [ "${INSTALL_ZSH}" = "true" ]; then ...@@ -474,6 +474,15 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
fi fi
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 ** # ** 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 @@ ...@@ -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": { "alpine-3-14": {
"image": "alpine:3.14", "image": "alpine:3.14",
"remoteUser": "devcontainer", "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