From b11c71b2b727c03bfdc516e908dea1e5e7cd83e1 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 20 Aug 2026 17:48:28 +0400 Subject: [PATCH] diff /etc/skel/.bashrc --- lib/initiate.bash | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/lib/initiate.bash b/lib/initiate.bash index 468e963..d9843ad 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -37,29 +37,27 @@ function fix_users_bashrc { build_associative_user_homes for user in "${!USER_HOMES[@]}"; do local user_bashrc="${USER_HOMES[$user]}/.bashrc" + local first_change echo "read: $user_bashrc" [[ ! -f "$user_bashrc" ]] && continue - cmp -s /etc/skel/.bashrc "$user_bashrc" && continue - - local first_change - if first_change=$(diff /etc/skel/.bashrc "$user_bashrc" | head -n1); then - echo 'no change' + if cmp -s /etc/skel/.bashrc "$user_bashrc"; then + echo 'no change: replaced by skel' sudo -u "$user" -- cp "$MIAOU_BASH_DIR"/etc/skel/.bashrc "$user_bashrc" - else - if [[ $first_change =~ $appended_regex ]]; then - if new_lines=$(diff /etc/skel/.bashrc "$user_bashrc" | grep '^> ' | sed 's/^> //'); then - echo 'no new lines' - else - sudo -u "$user" -- cp "$MIAOU_BASH_DIR"/etc/skel/.bashrc "$user_bashrc" - echo -e "$new_lines" | sudo -u "$user" -- tee -a "$user_bashrc" - echo "INFO: .bashrc for user <$user> merged succesfully" - fi + elif first_change=$(diff /etc/skel/.bashrc "$user_bashrc" | head -n1); then + echo 'no change: should not occur' + elif [[ $first_change =~ $appended_regex ]]; then + if new_lines=$(diff /etc/skel/.bashrc "$user_bashrc" | grep '^> ' | sed 's/^> //'); then + echo 'no new lines: should not occur' else - local backup="$user_bashrc".ORIGINAL - sudo -u "$user" -- mv "$user_bashrc" "$backup" sudo -u "$user" -- cp "$MIAOU_BASH_DIR"/etc/skel/.bashrc "$user_bashrc" - >&2 echo "WARN: .bashrc for user <$user> has forked from skeleton, please resolve conflict manually from backup: $backup" + echo -e "$new_lines" | sudo -u "$user" -- tee -a "$user_bashrc" + echo "INFO: .bashrc for user <$user> merged succesfully" fi + else + local backup="$user_bashrc".ORIGINAL + sudo -u "$user" -- mv "$user_bashrc" "$backup" + sudo -u "$user" -- cp "$MIAOU_BASH_DIR"/etc/skel/.bashrc "$user_bashrc" + >&2 echo "WARN: .bashrc for user <$user> has forked from skeleton, please resolve conflict manually from backup: $backup" fi done sudo mv /etc/skel/.bashrc /etc/skel/.bashrc.ORIGINAL