updated stuff
This commit is contained in:
parent
2a201e89ba
commit
d0f6bd7c9a
1 changed files with 5 additions and 8 deletions
13
bin/hosts
13
bin/hosts
|
@ -3,9 +3,6 @@
|
||||||
# Path to your hosts file
|
# Path to your hosts file
|
||||||
hostsFile="/etc/hosts"
|
hostsFile="/etc/hosts"
|
||||||
|
|
||||||
# Default IP address for host
|
|
||||||
ip="127.0.0.1"
|
|
||||||
|
|
||||||
# Hostname to add/remove.
|
# Hostname to add/remove.
|
||||||
hostname="$2"
|
hostname="$2"
|
||||||
|
|
||||||
|
@ -14,7 +11,7 @@ die() { yell "$*"; exit 111; }
|
||||||
try() { "$@" || die "cannot $*"; }
|
try() { "$@" || die "cannot $*"; }
|
||||||
|
|
||||||
remove() {
|
remove() {
|
||||||
if grep -qP "[[:space:]]$hostname" /etc/hosts; then
|
if grep -qP "[[:space:]]$hostname" "$hostsFile"; then
|
||||||
echo "$hostname found in $hostsFile. Removing now..."
|
echo "$hostname found in $hostsFile. Removing now..."
|
||||||
try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile"
|
try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile"
|
||||||
else
|
else
|
||||||
|
@ -23,15 +20,15 @@ remove() {
|
||||||
}
|
}
|
||||||
|
|
||||||
add() {
|
add() {
|
||||||
if grep -qP "[[:space:]]$hostname" /etc/hosts; then
|
if grep -qP "[[:space:]]$hostname" "$hostsFile"; then
|
||||||
yell "$hostname already exists: $(grep "$hostname" $hostsFile)"
|
yell "$hostname already exists: $(grep "$hostname" $hostsFile)"
|
||||||
else
|
else
|
||||||
echo "Adding $hostname to $hostsFile..."
|
echo "Adding $hostname to $hostsFile..."
|
||||||
try printf "%s\t%s\n" "$ip" "$hostname" | sudo tee -a "$hostsFile" > /dev/null
|
try printf "%s\t%s\n" "127.0.0.1" "$hostname" | sudo tee -a "$hostsFile" > /dev/null
|
||||||
|
|
||||||
if grep -q "$hostname" /etc/hosts; then
|
if grep -q "$hostname" "$hostsFile"; then
|
||||||
echo "$hostname was added succesfully:"
|
echo "$hostname was added succesfully:"
|
||||||
grep "$hostname" /etc/hosts
|
grep "$hostname" "$hostsFile"
|
||||||
else
|
else
|
||||||
die "Failed to add $hostname"
|
die "Failed to add $hostname"
|
||||||
fi
|
fi
|
||||||
|
|
Loading…
Add table
Reference in a new issue