diff /etc/skel/.bashrc
This commit is contained in:
+19
-10
@@ -26,24 +26,33 @@ function install_required_packages {
|
||||
}
|
||||
|
||||
function fix_users_bashrc {
|
||||
# for new users
|
||||
if ! cmp -s /etc/skel/.bashrc "$MIAOU_BASH_DIR"/etc/skel/.bashrc; then
|
||||
[[ -f /etc/skel/.bashrc ]] && sudo mv /etc/skel/.bashrc /etc/skel/.bashrc.ORIGINAL
|
||||
sudo ln -sf "$MIAOU_BASH_DIR"/etc/skel/.bashrc /etc/skel/.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)
|
||||
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"
|
||||
[[ ! -f "$user_bashrc" ]] && next
|
||||
cmp -s "$user_bashrc" "$MIAOU_BASH_DIR"/etc/skel/.bashrc && next
|
||||
cmp -s "$user_bashrc" /etc/skel/.bashrc && next
|
||||
|
||||
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"
|
||||
local first_change
|
||||
first_change=$(diff /etc/skel/.bashrc "$user" | 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"
|
||||
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
|
||||
fi
|
||||
sudo ln -sf "$MIAOU_BASH_DIR"/etc/skel/.bashrc /etc/skel/.bashrc
|
||||
}
|
||||
|
||||
function link_etc {
|
||||
|
||||
Reference in New Issue
Block a user