Update ad-join-script.sh
Adding hostname changing and a bit of textual info during execution
This commit is contained in:
parent
1a2e7d37eb
commit
09f6c9f290
@ -1,5 +1,12 @@
|
|||||||
#!/bin/bash
|
#!/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
|
# Prompt the user for the necessary information
|
||||||
read -p "Administrator username (AdminUser): " admin_user
|
read -p "Administrator username (AdminUser): " admin_user
|
||||||
read -s -p "Administrator password: " admin_password
|
read -s -p "Administrator password: " admin_password
|
||||||
@ -16,28 +23,43 @@ while true; do
|
|||||||
fi
|
fi
|
||||||
done
|
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
|
# 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
|
echo "nameserver $dns_server" | sudo tee /etc/resolv.conf
|
||||||
|
|
||||||
# Install the necessary packages
|
# 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
|
apt -y install realmd sssd sssd-tools libnss-sss libpam-sss adcli samba-common-bin oddjob oddjob-mkhomedir packagekit
|
||||||
|
|
||||||
# Discover the domain
|
# Discover the domain
|
||||||
|
echo "Discovering the domain..."
|
||||||
realm discover $domain_name
|
realm discover $domain_name
|
||||||
|
|
||||||
# Join the domain using the provided information
|
# 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
|
# 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
|
sed -i 's/use_fully_qualified_names = True/use_fully_qualified_names = False/g' /etc/sssd/sssd.conf
|
||||||
|
|
||||||
# Restart the SSSD service
|
# Restart the SSSD service
|
||||||
|
echo "Restarting the SSSD service..."
|
||||||
systemctl restart sssd
|
systemctl restart sssd
|
||||||
|
|
||||||
# Add the user to the sudoers file
|
# 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
|
echo "$admin_user ALL=(ALL:ALL) ALL" | sudo tee -a /etc/sudoers
|
||||||
|
|
||||||
# Verify successful domain join by looking up the user
|
# Verify successful domain join by looking up the user
|
||||||
|
echo "Verifying domain join..."
|
||||||
if id $admin_user; then
|
if id $admin_user; then
|
||||||
echo "The server has been successfully joined to the Active Directory domain."
|
echo "The server has been successfully joined to the Active Directory domain."
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user