Update ad-join-script.sh

Adding hostname changing and a bit of textual info during execution
This commit is contained in:
jeanGaston 2023-10-30 18:50:34 +01:00 committed by GitHub
parent 1a2e7d37eb
commit 09f6c9f290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,5 +1,12 @@
#!/bin/bash
# Enable verbose output
set -x
# Prompt the user for the hostname
read -p "Enter the hostname for the server: " hostname
echo
# Prompt the user for the necessary information
read -p "Administrator username (AdminUser): " admin_user
read -s -p "Administrator password: " admin_password
@ -16,28 +23,43 @@ while true; do
fi
done
# Display hostname change information
echo "Changing the hostname to: $hostname.$domain_name"
# Change the hostname
hostnamectl set-hostname $hostname
echo "$hostname.$domain_name" | sudo tee -a /etc/hostname
# Change the DNS server settings in /etc/resolv.conf
echo "Changing DNS server to: $dns_server"
echo "nameserver $dns_server" | sudo tee /etc/resolv.conf
# Install the necessary packages
echo "Installing required packages..."
apt -y install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
# Discover the domain
echo "Discovering the domain..."
realm discover $domain_name
# Join the domain using the provided information
echo $admin_password | realm join -U $admin_user $domain_name
echo "Joining the domain..."
echo $admin_password | realm join -U $admin_user $domain_name --computer-ou=OU=Computers,DC=example,DC=com
# Modify the sssd.conf configuration
echo "Modifying sssd.conf..."
sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf
# Restart the SSSD service
echo "Restarting the SSSD service..."
systemctl restart sssd
# Add the user to the sudoers file
echo "Adding the user to the sudoers file..."
echo "$admin_user ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers
# Verify successful domain join by looking up the user
echo "Verifying domain join..."
if id $admin_user; then
echo "The server has been successfully joined to the Active Directory domain."
else