diff /etc/skel/.bashrc
This commit is contained in:
+26
-12
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user