From beb56109dd9fe11373701dad0a36abefeb68d401 Mon Sep 17 00:00:00 2001 From: pvincent Date: Thu, 20 Aug 2026 17:36:45 +0400 Subject: [PATCH] diff /etc/skel/.bashrc --- lib/initiate.bash | 38 ++++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/lib/initiate.bash b/lib/initiate.bash index 2776049..67e01d1 100644 --- a/lib/initiate.bash +++ b/lib/initiate.bash @@ -27,30 +27,44 @@ function install_required_packages { function fix_users_bashrc { if [[ -f /etc/skel/.bashrc ]] && ! cmp -s /etc/skel/.bashrc "$MIAOU_BASH_DIR"/etc/skel/.bashrc; then - local skel_count_lines=$(wc -l /etc/skel/.bashrc) + echo 'fixing users .bashrc...' + local skel_count_lines + skel_count_lines=$(wc -l /etc/skel/.bashrc | cut -d' ' -f1) + local appended_regex="^${skel_count_lines}a" + # for pre-existant users build_associative_user_homes for user in "${!USER_HOMES[@]}"; do local user_bashrc="${USER_HOMES[$user]}/.bashrc" + echo "read: $user_bashrc" [[ ! -f "$user_bashrc" ]] && continue - cmp -s "$user_bashrc" /etc/skel/.bashrc && continue + cmp -s /etc/skel/.bashrc "$user_bashrc" && continue local first_change - first_change=$(diff /etc/skel/.bashrc "$user_bashrc" | head -n1) - - if [[ $first_change =~ $appended_regex ]]; then - sudo -u "$user" -- cp "$MIAOU_BASH_DIR"/etc/skel/.bashrc "$user_bashrc" - diff /etc/skel/.bashrc "$user_bashrc" | grep '^> ' | sed 's/^> //' | tee -a "$user_bashrc" - echo "INFO: .bashrc for user <$user> merged succesfully" + if first_change=$(diff /etc/skel/.bashrc "$user_bashrc" | head -n1); then + : 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" + if [[ $first_change =~ $appended_regex ]]; then + if new_lines=$(diff /etc/skel/.bashrc "$user_bashrc" | grep '^> ' | sed 's/^> //'); then + : + else + # echo -e "$new_lines" + + 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 + 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 fi done sudo mv /etc/skel/.bashrc /etc/skel/.bashrc.ORIGINAL + echo 'fixing users .bashrc...DONE' fi sudo ln -sf "$MIAOU_BASH_DIR"/etc/skel/.bashrc /etc/skel/.bashrc }