Skip to content

Instantly share code, notes, and snippets.

@luckylittle
Created June 27, 2024 01:13
Show Gist options
  • Save luckylittle/5844f3d9a1313376d15657149dda4da0 to your computer and use it in GitHub Desktop.
Save luckylittle/5844f3d9a1313376d15657149dda4da0 to your computer and use it in GitHub Desktop.
Replace the /etc/hosts file with different versions
#!/bin/bash
# Paths to the different hosts files
HOSTS_ADBLOCKER="/etc/hosts_adblocker"
HOSTS_DEFAULT="/etc/hosts_default"
HOSTS="/etc/hosts"
# Function to replace the /etc/hosts file
replace_hosts() {
local selected_file=$1
if [ -f "$selected_file" ]; then
sudo cp "$selected_file" "$HOSTS"
echo "Replaced $HOSTS with $selected_file"
else
echo "Error: $selected_file does not exist."
exit 1
fi
}
# Prompt the user to choose the hosts file
echo "Choose the hosts file you want to use:"
echo "1) Adblocker hosts file"
echo "2) Default hosts file"
read -p "Enter your choice (1 or 2): " choice
# Replace the hosts file based on the user's choice
case $choice in
1)
replace_hosts "$HOSTS_ADBLOCKER"
;;
2)
replace_hosts "$HOSTS_DEFAULT"
;;
*)
echo "Invalid choice. Exiting."
exit 1
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment