From 80d5d584df77af91ee6705bec549d3764a7afa87 Mon Sep 17 00:00:00 2001 From: colin Date: Mon, 9 Dec 2024 16:02:53 -0500 Subject: [PATCH] Create the script that can add /etc/profile.d/ --- src/include.d.sh | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 src/include.d.sh diff --git a/src/include.d.sh b/src/include.d.sh new file mode 100644 index 0000000..1552362 --- /dev/null +++ b/src/include.d.sh @@ -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." \ No newline at end of file