Create the script that can add /etc/profile.d/
This commit is contained in:
parent
bbb24b77a6
commit
80d5d584df
|
@ -0,0 +1,26 @@
|
|||
#!/bin/bash
|
||||
|
||||
# Loop through all users with /bin/bash as their default shell
|
||||
echo "Configuring all users with /bin/bash as their default shell..."
|
||||
|
||||
while IFS=: read -r username _ _ _ _ homedir shell; do
|
||||
# Check if the shell is /bin/bash
|
||||
if [[ "$shell" == "/bin/bash" ]]; then
|
||||
# Check if the user's home directory exists and .bashrc is present
|
||||
bashrc="$homedir/.bashrc"
|
||||
if [[ -d "$homedir" && -w "$bashrc" ]]; then
|
||||
echo "Processing $username..."
|
||||
# Add the sourcing logic if not already present
|
||||
if ! grep -q "/etc/profile.d/" "$bashrc"; then
|
||||
echo 'for script in /etc/profile.d/*.sh; do if [ -r "$script" ]; then . "$script"; fi; done' >> "$bashrc"
|
||||
echo "Added sourcing logic to $bashrc"
|
||||
else
|
||||
echo "Sourcing logic already present in $bashrc"
|
||||
fi
|
||||
else
|
||||
echo "No writable .bashrc found for $username, skipping."
|
||||
fi
|
||||
fi
|
||||
done < /etc/passwd
|
||||
|
||||
echo "Configuration complete."
|
Loading…
Reference in New Issue