Add update_hosts_file funtion to update hosts file.
This commit is contained in:
parent
34dd7d9344
commit
af395f3725
19
setup.sh
19
setup.sh
@ -12,6 +12,22 @@ prompt_for_hostname() {
|
|||||||
read -p "Please enter the desired hostname: " hostname
|
read -p "Please enter the desired hostname: " hostname
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Function to add hostname and IP to /etc/hosts
|
||||||
|
update_hosts_file() {
|
||||||
|
local ip_address
|
||||||
|
ip_address=$(hostname -I | awk '{print $1}')
|
||||||
|
echo "Updating /etc/hosts with IP $ip_address and hostname $hostname..."
|
||||||
|
|
||||||
|
# Check if the entry already exists
|
||||||
|
if grep -q "$ip_address" /etc/hosts; then
|
||||||
|
echo "Entry for $ip_address already exists in /etc/hosts."
|
||||||
|
sed -i "s/.*$hostname/$ip_address $hostname/" /etc/hosts
|
||||||
|
else
|
||||||
|
echo "$ip_address $hostname" >> /etc/hosts
|
||||||
|
echo "Added $ip_address $hostname to /etc/hosts."
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Function to prompt for Docker installation
|
# Function to prompt for Docker installation
|
||||||
prompt_for_docker_install() {
|
prompt_for_docker_install() {
|
||||||
read -p "Would you like to install Docker CE? (y/n): " install_docker
|
read -p "Would you like to install Docker CE? (y/n): " install_docker
|
||||||
@ -90,6 +106,9 @@ prompt_for_hostname
|
|||||||
echo "Setting hostname to $hostname..."
|
echo "Setting hostname to $hostname..."
|
||||||
hostnamectl set-hostname "$hostname"
|
hostnamectl set-hostname "$hostname"
|
||||||
|
|
||||||
|
# Update /etc/hosts
|
||||||
|
update_hosts_file
|
||||||
|
|
||||||
# Create a limited user account
|
# Create a limited user account
|
||||||
create_user_account
|
create_user_account
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user