From 12a0c75b960e76efdac760c73c3a0c6a79e252bc Mon Sep 17 00:00:00 2001 From: Valentin Lab Date: Sun, 10 Sep 2023 11:43:06 +0200 Subject: [PATCH] fix: [base] avoid appending new bits of code in ``~/.bash_profile`` This script was not idempotent, and that was an oversight. --- .../base-0k/hooks/install.d/30-customize.sh | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/precise/base-0k/hooks/install.d/30-customize.sh b/precise/base-0k/hooks/install.d/30-customize.sh index 83b8878..ec4d336 100755 --- a/precise/base-0k/hooks/install.d/30-customize.sh +++ b/precise/base-0k/hooks/install.d/30-customize.sh @@ -18,13 +18,21 @@ parse_git_branch() { export PS1="\[\033[0;37m\][\[\033[1;30m\]\u\[\033[0;37m\]@\[\033[1;30m\]\H\[\033[0;37m\]]-[\[\033[1;34m\]\w\[\033[0;37m\]]\\\$(parse_git_branch)\n\[\033[1;37m\]\\$ \[\033[0;37m\]" EOF -if [ -f /root/.bashrc.pre-install ]; then - cp /root/.bashrc.pre-install /root/.bashrc -else - cp /root/.bashrc /root/.bashrc.pre-install -fi +protect_pre_install() { + local filename="$1" + if [ -f "$filename".pre-install ]; then + cp "$filename".pre-install "$filename" + else + if ! [ -e "$filename" ]; then + touch "$filename" + fi + cp "$filename" "$filename".pre-install + fi +} +protect_pre_install "/root/.bashrc" + if ! type -p fzf; then @@ -119,6 +127,9 @@ export FZF_CTRL_T_COMMAND="$FZF_DEFAULT_COMMAND" EOF + +protect_pre_install "/root/.bash_profile" + cat <> /root/.bash_profile ## XXXvlab: