Skip to content

Instantly share code, notes, and snippets.

@ErvalhouS
Last active December 28, 2020 12:43
Show Gist options
  • Save ErvalhouS/e18c69a5fe223c3e4a0e9f5d50c827f6 to your computer and use it in GitHub Desktop.
Save ErvalhouS/e18c69a5fe223c3e4a0e9f5d50c827f6 to your computer and use it in GitHub Desktop.
This gist makes it possible to maintain `.test` domains working on your windows + WSL setup
#!/bin/bash
ip_address=`hostname -I`
for host_name in hubstaff.test account.hubstaff.test app.hubstaff.test tasks.hubstaff.test talent.hubstaff.test
do
matches_in_hosts="$(grep -n " $host_name" /etc/hosts | cut -f1 -d:)"
host_entry="${ip_address} ${host_name}"
if [ ! -z "$matches_in_hosts" ]
then
echo "Replacing existing record for $host_name"
while read -r line_number; do
sudo sed -i "${line_number}s/.*${host_name}$/${host_entry}/" /etc/hosts
done <<< "$matches_in_hosts"
else
echo "Adding record for $host_name"
echo "$host_entry" | sudo tee -a /etc/hosts > /dev/null
fi
done
echo "Done :)"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment