Browse Source

diff /etc/skel/.bashrc

main
pvincent 2 weeks ago
parent
commit
b11c71b2b7
  1. 32
      lib/initiate.bash

32
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

Loading…
Cancel
Save