#!/bin/bash

# Check if the script is run with root privileges
if [ "$EUID" -ne 0 ]; then
  echo "Please run as root."
  exit 1
fi

# Get the current hostname
current_hostname=$(hostname)

# Check if the current hostname is empty or not
if [ -z "$current_hostname" ]; then
  echo "Error: Unable to retrieve current hostname."
  exit 1
fi

# Define the new hostname based on the current hostname
case $current_hostname in
  "please enter the current hostname of the machine 1")
    new_hostname="please enter new hostname you want set"
    ;;
  "please enter the current hostname of the machine 2")
    new_hostname="please enter new hostname you want set"
    ;;
  # Add more cases for additional hostnames
  *)
    # If the current hostname doesn't match any known cases, no changes are made
    echo "Hostname is not in the list. No changes made."
    exit 0
    ;;
esac

# Change the hostname in /etc/hostname
echo "$new_hostname" > /etc/hostname

# Change the hostname in /etc/hosts
sed -i "s/127.0.1.1.*/127.0.1.1\t$new_hostname/" /etc/hosts

# Notify the user to reboot for the changes to take effect
echo "Hostname changed from $current_hostname to $new_hostname. Please reboot your system for the changes to take effect."
