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.",
......
...@@ -68,7 +68,7 @@ install_debian_packages() { ...@@ -68,7 +68,7 @@ install_debian_packages() {
manpages \ manpages \
manpages-dev \ manpages-dev \
init-system-helpers" init-system-helpers"
# Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian # Needed for adding manpages-posix and manpages-posix-dev which are non-free packages in Debian
if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then if [ "${ADD_NON_FREE_PACKAGES}" = "true" ]; then
# Bring in variables from /etc/os-release like VERSION_CODENAME # Bring in variables from /etc/os-release like VERSION_CODENAME
...@@ -78,7 +78,7 @@ install_debian_packages() { ...@@ -78,7 +78,7 @@ install_debian_packages() {
sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list sed -i -E "s/deb-src http:\/\/(deb|httpredir)\.debian\.org\/debian ${VERSION_CODENAME}-updates main/deb http:\/\/\1\.debian\.org\/debian ${VERSION_CODENAME}-updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list sed -i "s/deb-src http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}\/updates main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list sed -i "s/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list
sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list sed -i "s/deb-src http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main/deb http:\/\/deb\.debian\.org\/debian ${VERSION_CODENAME}-backports main contrib non-free/" /etc/apt/sources.list
# Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html # Handle bullseye location for security https://www.debian.org/releases/bullseye/amd64/release-notes/ch-information.en.html
sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list sed -i "s/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main/deb http:\/\/security\.debian\.org\/debian-security ${VERSION_CODENAME}-security main contrib non-free/" /etc/apt/sources.list
...@@ -133,13 +133,13 @@ install_debian_packages() { ...@@ -133,13 +133,13 @@ install_debian_packages() {
# Ensure at least the en_US.UTF-8 UTF-8 locale is available = common need for both applications and things like the agnoster ZSH theme. # Ensure at least the en_US.UTF-8 UTF-8 locale is available = common need for both applications and things like the agnoster ZSH theme.
if [ "${LOCALE_ALREADY_SET}" != "true" ] && ! grep -o -E '^\s*en_US.UTF-8\s+UTF-8' /etc/locale.gen > /dev/null; then if [ "${LOCALE_ALREADY_SET}" != "true" ] && ! grep -o -E '^\s*en_US.UTF-8\s+UTF-8' /etc/locale.gen > /dev/null; then
echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen echo "en_US.UTF-8 UTF-8" >> /etc/locale.gen
locale-gen locale-gen
LOCALE_ALREADY_SET="true" LOCALE_ALREADY_SET="true"
fi fi
# Clean up # Clean up
apt-get -y clean apt-get -y clean
rm -rf /var/lib/apt/lists/* rm -rf /var/lib/apt/lists/*
} }
...@@ -254,7 +254,7 @@ install_alpine_packages() { ...@@ -254,7 +254,7 @@ install_alpine_packages() {
# Install man pages - package name varies between 3.12 and earlier versions # Install man pages - package name varies between 3.12 and earlier versions
if apk info man > /dev/null 2>&1; then if apk info man > /dev/null 2>&1; then
apk add --no-cache man man-pages apk add --no-cache man man-pages
else else
apk add --no-cache mandoc man-pages apk add --no-cache mandoc man-pages
fi fi
...@@ -324,7 +324,7 @@ fi ...@@ -324,7 +324,7 @@ fi
if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then if [ "${USERNAME}" = "auto" ] || [ "${USERNAME}" = "automatic" ]; then
if [ "${_REMOTE_USER}" != "root" ]; then if [ "${_REMOTE_USER}" != "root" ]; then
USERNAME="${_REMOTE_USER}" USERNAME="${_REMOTE_USER}"
else else
USERNAME="" USERNAME=""
POSSIBLE_USERS=("devcontainer" "vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)") POSSIBLE_USERS=("devcontainer" "vscode" "node" "codespace" "$(awk -v val=1000 -F ":" '$3==val{print $1}' /etc/passwd)")
for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do for CURRENT_USER in "${POSSIBLE_USERS[@]}"; do
...@@ -346,12 +346,12 @@ fi ...@@ -346,12 +346,12 @@ fi
group_name="${USERNAME}" group_name="${USERNAME}"
if id -u ${USERNAME} > /dev/null 2>&1; then if id -u ${USERNAME} > /dev/null 2>&1; then
# User exists, update if needed # User exists, update if needed
if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then if [ "${USER_GID}" != "automatic" ] && [ "$USER_GID" != "$(id -g $USERNAME)" ]; then
group_name="$(id -gn $USERNAME)" group_name="$(id -gn $USERNAME)"
groupmod --gid $USER_GID ${group_name} groupmod --gid $USER_GID ${group_name}
usermod --gid $USER_GID $USERNAME usermod --gid $USER_GID $USERNAME
fi fi
if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then if [ "${USER_UID}" != "automatic" ] && [ "$USER_UID" != "$(id -u $USERNAME)" ]; then
usermod --uid $USER_UID $USERNAME usermod --uid $USER_UID $USERNAME
fi fi
else else
...@@ -361,7 +361,7 @@ else ...@@ -361,7 +361,7 @@ else
else else
groupadd --gid $USER_GID $USERNAME groupadd --gid $USER_GID $USERNAME
fi fi
if [ "${USER_UID}" = "automatic" ]; then if [ "${USER_UID}" = "automatic" ]; then
useradd -s /bin/bash --gid $USERNAME -m $USERNAME useradd -s /bin/bash --gid $USERNAME -m $USERNAME
else else
useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME useradd -s /bin/bash --uid $USER_UID --gid $USERNAME -m $USERNAME
...@@ -379,13 +379,13 @@ fi ...@@ -379,13 +379,13 @@ fi
# ** Shell customization section ** # ** Shell customization section **
# ********************************* # *********************************
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