1
0
mirror of https://github.com/octoleo/hosts.git synced 2024-11-22 04:45:11 +00:00

[TASK] Add list mode

This commit is contained in:
Dominique Feyer 2011-11-16 11:20:25 +01:00
parent d1edb3dd30
commit ff7f431bd7

21
host-manager Normal file → Executable file
View File

@ -2,10 +2,11 @@
# Idea and interface taken from https://github.com/macmade/host-manager # Idea and interface taken from https://github.com/macmade/host-manager
path="/etc/hosts" path="/etc/hosts"
addusage="Usage: `basename $0` -add host address" addusage="Usage: `basename $0` --add host address"
remusage="Usage: `basename $0` -remove host" remusage="Usage: `basename $0` --remove host"
listusage="Usage: `basename $0` --list [127.]"
case "$1" in case "$1" in
-add) --add)
if [ $# -eq 3 ]; then if [ $# -eq 3 ]; then
if [[ -n $(grep "^$3.*[^A-Za-z0-9\.]$2$" ${path}) ]]; then if [[ -n $(grep "^$3.*[^A-Za-z0-9\.]$2$" ${path}) ]]; then
echo "Duplicate address/host combination, ${path} unchanged." echo "Duplicate address/host combination, ${path} unchanged."
@ -16,14 +17,22 @@ case "$1" in
echo $addusage; echo $addusage;
fi fi
;; ;;
-remove) --remove)
if [ $# -eq 2 ]; then if [ $# -eq 2 ]; then
sed -i '' -e "s/^[^#].*[^A-Za-z0-9\.]$2$//g" -e "/^$/ d" ${path} sed -i '' "s/^[^#].*[^A-Za-z0-9\.]$2$//g;/^$/d" ${path}
else else
echo $remusage; echo $remusage;
fi fi
;; ;;
--list)
if [ $# -eq 2 ]; then
grep "^$2" ${path}
else
cat ${path} | grep -v "^#"
fi
;;
*) *)
echo $addusage; echo $addusage;
echo $remusage; echo $remusage;
esac echo $listusage;
esac