diff /etc/skel/.bashrc
This commit is contained in:
+26
-12
@@ -27,30 +27,44 @@ function install_required_packages {
|
|||||||
|
|
||||||
function fix_users_bashrc {
|
function fix_users_bashrc {
|
||||||
if [[ -f /etc/skel/.bashrc ]] && ! cmp -s /etc/skel/.bashrc "$MIAOU_BASH_DIR"/etc/skel/.bashrc; then
|
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"
|
local appended_regex="^${skel_count_lines}a"
|
||||||
|
|
||||||
# for pre-existant users
|
# for pre-existant users
|
||||||
build_associative_user_homes
|
build_associative_user_homes
|
||||||
for user in "${!USER_HOMES[@]}"; do
|
for user in "${!USER_HOMES[@]}"; do
|
||||||
local user_bashrc="${USER_HOMES[$user]}/.bashrc"
|
local user_bashrc="${USER_HOMES[$user]}/.bashrc"
|
||||||
|
echo "read: $user_bashrc"
|
||||||
[[ ! -f "$user_bashrc" ]] && continue
|
[[ ! -f "$user_bashrc" ]] && continue
|
||||||
cmp -s "$user_bashrc" /etc/skel/.bashrc && continue
|
cmp -s /etc/skel/.bashrc "$user_bashrc" && continue
|
||||||
|
|
||||||
local first_change
|
local first_change
|
||||||
first_change=$(diff /etc/skel/.bashrc "$user_bashrc" | head -n1)
|
if first_change=$(diff /etc/skel/.bashrc "$user_bashrc" | head -n1); then
|
||||||
|
:
|
||||||
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
|
else
|
||||||
local backup="$user_bashrc".ORIGINAL
|
if [[ $first_change =~ $appended_regex ]]; then
|
||||||
sudo -u "$user" -- mv "$user_bashrc" "$backup"
|
if new_lines=$(diff /etc/skel/.bashrc "$user_bashrc" | grep '^> ' | sed 's/^> //'); then
|
||||||
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"
|
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
|
fi
|
||||||
done
|
done
|
||||||
sudo mv /etc/skel/.bashrc /etc/skel/.bashrc.ORIGINAL
|
sudo mv /etc/skel/.bashrc /etc/skel/.bashrc.ORIGINAL
|
||||||
|
echo 'fixing users .bashrc...DONE'
|
||||||
fi
|
fi
|
||||||
sudo ln -sf "$MIAOU_BASH_DIR"/etc/skel/.bashrc /etc/skel/.bashrc
|
sudo ln -sf "$MIAOU_BASH_DIR"/etc/skel/.bashrc /etc/skel/.bashrc
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user