Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

init-user: Safeguarded linking directories and files #922

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions vscode/rootfs/etc/s6-overlay/s6-rc.d/init-user/run
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ readonly ZSH_HISTORY_PERSISTANT_FILE=/data/.zsh_history

# Links some common directories to the user's home folder for convenience
for dir in "${DIRECTORIES[@]}"; do
ln -s "/${dir}" "${HOME}/${dir}" \
ln -sn "/${dir}" "${HOME}/${dir}" \
|| bashio::log.warning "Failed linking common directory: ${dir}"
done

# Some links to old locations, to not mess with the user's muscle memory
ln -s "/config" "${HOME}/config" \
ln -sn "/config" "${HOME}/config" \
|| bashio::log.warning "Failed linking common directory: ${HOME}/config"
ln -s "/config" "/homeassistant" \
ln -sn "/config" "/homeassistant" \
|| bashio::log.warning "Failed linking common directory: /homeassistant"

# Store SSH settings in add-on data folder
Expand All @@ -31,7 +31,7 @@ if ! bashio::fs.directory_exists "${SSH_USER_PATH}"; then
|| bashio::exit.nok \
'Failed setting permissions on persistent .ssh folder'
fi
ln -s "${SSH_USER_PATH}" ~/.ssh
ln -sn "${SSH_USER_PATH}" ~/.ssh || bashio::log.warning "Failed linking .ssh"

# Sets up ZSH shell
touch "${ZSH_HISTORY_PERSISTANT_FILE}" \
Expand All @@ -58,7 +58,7 @@ if ! bashio::fs.file_exists "${GIT_USER_PATH}/.gitconfig"; then
touch "${GIT_USER_PATH}/.gitconfig" \
|| bashio::exit.nok 'Failed to create .gitconfig'
fi
ln -s "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig
ln -s "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig || bashio::log.warning "Failed linking .gitconfig"
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Add missing --no-dereference flag for consistency.

The -n flag is missing in this ln command, making it inconsistent with other link commands in the script.

-ln -s "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig || bashio::log.warning "Failed linking .gitconfig"
+ln -sn "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig || bashio::log.warning "Failed linking .gitconfig"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
ln -s "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig || bashio::log.warning "Failed linking .gitconfig"
ln -sn "${GIT_USER_PATH}/.gitconfig" ~/.gitconfig || bashio::log.warning "Failed linking .gitconfig"


# Install user configured/requested packages
if bashio::config.has_value 'packages'; then
Expand Down