updated stuff
This commit is contained in:
parent
c427c918d4
commit
fa06d6afcc
11 changed files with 34 additions and 2115 deletions
26
bin/hosts
26
bin/hosts
|
@ -14,28 +14,28 @@ die() { yell "$*"; exit 111; }
|
|||
try() { "$@" || die "cannot $*"; }
|
||||
|
||||
remove() {
|
||||
if [ -n "$(grep -P "[[:space:]]$hostname" /etc/hosts)" ]; then
|
||||
echo "$hostname found in $hostsFile. Removing now...";
|
||||
try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile";
|
||||
if grep -qP "[[:space:]]$hostname" /etc/hosts; then
|
||||
echo "$hostname found in $hostsFile. Removing now..."
|
||||
try sudo sed -ie "/[[:space:]]$hostname/d" "$hostsFile"
|
||||
else
|
||||
yell "$hostname was not found in $hostsFile";
|
||||
yell "$hostname was not found in $hostsFile"
|
||||
fi
|
||||
}
|
||||
|
||||
add() {
|
||||
if [ -n "$(grep -P "[[:space:]]$hostname" /etc/hosts)" ]; then
|
||||
yell "$hostname, already exists: $(grep $hostname $hostsFile)";
|
||||
if grep -qP "[[:space:]]$hostname" /etc/hosts; then
|
||||
yell "$hostname already exists: $(grep "$hostname" $hostsFile)"
|
||||
else
|
||||
echo "Adding $hostname to $hostsFile...";
|
||||
try printf "%s\t%s\n" "$ip" "$hostname" | sudo tee -a "$hostsFile" > /dev/null;
|
||||
echo "Adding $hostname to $hostsFile..."
|
||||
try printf "%s\t%s\n" "$ip" "$hostname" | sudo tee -a "$hostsFile" > /dev/null
|
||||
|
||||
if [ -n "$(grep $hostname /etc/hosts)" ]; then
|
||||
echo "$hostname was added succesfully:";
|
||||
echo "$(grep $hostname /etc/hosts)";
|
||||
if grep -q "$hostname" /etc/hosts; then
|
||||
echo "$hostname was added succesfully:"
|
||||
grep "$hostname" /etc/hosts
|
||||
else
|
||||
die "Failed to add $hostname";
|
||||
die "Failed to add $hostname"
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
$@
|
||||
"$@"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue