-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Do not update user's dotfiles #512
Description
In the scripts from script's library, often we see the function updaterc updating the user's dotfiles such as ~/.bashrc. I think we should never do that since those files will be later replaced in case the user has a dotfiles repository configured.
So I have two suggestions:
First
Instead, perform these changes to the global bashrc and zshrc files, which are respectively /etc/bash.bashrc and /etc/zsh/zshrc. Those files gets sourced by bash and zsh automatically, for all the users.
This means that for free, we would earn synchronization between root and non-root user without having to update both user's dotfiles.
Second
Update /etc/bash.bashrc and /etc/zsh/zshrc to include something like . /etc/profile, because unfortunately, in Docker, /etc/profile does not get read automatically.
Then, if you take a look at /etc/profile you'll see something like:
if [ -d /etc/profile.d ]; then
for i in /etc/profile.d/*.sh; do
if [ -r $i ]; then
. $i
fi
done
unset i
fiThis means that any .sh under /etc/profile.d/ will get sourced by /etc/profile, and this is the recommended way to customize the system-wide Linux environment.
Then, we could convert lines such as:
echo "export SDKMAN_DIR=${SDKMAN_DIR}\nsource \${SDKMAN_DIR}/bin/sdkman-init.sh" >> /home/vscode/.bashrc
echo "export SDKMAN_DIR=${SDKMAN_DIR}\nsource \${SDKMAN_DIR}/bin/sdkman-init.sh" >> /home/vscode/.zshrc
# for root
echo "export SDKMAN_DIR=${SDKMAN_DIR}\nsource \${SDKMAN_DIR}/bin/sdkman-init.sh" >> /root/.bashrc
echo "export SDKMAN_DIR=${SDKMAN_DIR}\nsource \${SDKMAN_DIR}/bin/sdkman-init.sh" >> /root/.zshrcwith:
echo "export SDKMAN_DIR=${SDKMAN_DIR}\nsource \${SDKMAN_DIR}/bin/sdkman-init.sh" >> /etc/profile.d/sdkman.shWhich has the benefits:
- Works for all users (root and non-root)
- Works for bash and zsh
- Much safer than editing the
rcdirectly