diff --git a/base/ubi9/.copy-files b/base/ubi9/.copy-files new file mode 100644 index 00000000..f59b35e5 --- /dev/null +++ b/base/ubi9/.copy-files @@ -0,0 +1,20 @@ +# This file contains a list directories or files to copy over from /home/tooling to /home/user in entrypoint.sh. +# +# For example, the following will copy /home/tooling/testfile to /home/user/testfile: +# ./testfile +# +# The goal of this file is to copy over files that cannot be used as symbolic links created by stow. +# For example, Vim does not permit .viminfo to be a symbolic link for security reasons, therefore it is copied +# over to /home/user manually without stow. +# +# When copying over directories or files from /home/tooling to /home/user using this file, remember to add the +# directory or file to .stow-local-ignore so that a symbolic link is not created. + + +# Vim does not permit .viminfo to be a symbolic link for security reasons, so manually copy it +.viminfo + +# We have to restore bash-related files back onto /home/user/ (since they will have been overwritten by the PVC) +# but we don't want them to be symbolic links (so that they persist on the PVC) +.bashrc +.bash_profile diff --git a/base/ubi9/entrypoint.sh b/base/ubi9/entrypoint.sh index 0e2920f3..45dc9389 100644 --- a/base/ubi9/entrypoint.sh +++ b/base/ubi9/entrypoint.sh @@ -1,5 +1,10 @@ #!/bin/bash +# Replace /home/tooling/* path to /home/user/* path +replace_user_home() { + echo "$1" | sed "s|^/home/tooling|$HOME|" +} + # Ensure $HOME exists when starting if [ ! -d "${HOME}" ]; then mkdir -p "${HOME}" @@ -15,11 +20,20 @@ if [ ! -d "${HOME}/.config/containers" ]; then fi fi -# Create Sym Link for Composer Keys in /home/tooling/.config -if [ -d /home/tooling/.config/composer ] && [ ! -d "${HOME}/.config/composer" ]; then - mkdir -p ${HOME}/.config/composer - ln -s /home/tooling/.config/composer/keys.dev.pub ${HOME}/.config/composer/keys.dev.pub - ln -s /home/tooling/.config/composer/keys.tags.pub ${HOME}/.config/composer/keys.tags.pub +# Find files under /home/tooling/.config and create symlinks. The /home/tooling/.config folder +# is ignored by stow with the .stow-local-ignore file +if [ -d /home/tooling/.config ]; then + for file in $(find /home/tooling/.config -type f); do + tooling_dir=$(dirname "$file") + + # Create dir in /home/user if it does not exist already + mkdir -p $(replace_user_home "$tooling_dir") + + # Create symbolic link if it does not exist already + if [ ! -f $(replace_user_home $file) ]; then + ln -s $file $(replace_user_home $file) + fi + done fi # Setup $PS1 for a consistent and reasonable prompt