summaryrefslogtreecommitdiff
path: root/root/usr/bin/changedns
blob: edc48bc9932589bc2caa42541f3083e3d1054730 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/bin/sh

arg0="`basename $0`"	# base portion of our filename
arg1="$1"
tmpfile="/tmp/resolv.conf.$$"

usage ( ) {
	echo "usage: $arg0 -a|-r {ip} [{ip}...]"
	rm -f $tmpfile
	exit 1
}


[ "$#" -le 1 ] && usage

shift

[ ! -e "/etc/resolv.conf" ] && touch /etc/resolv.conf
cp /etc/resolv.conf $tmpfile

case "$arg1" in
	"-a")
		for ip in "$@"; do
		    echo $ip
			grep -sq "^nameserver $ip\$" $tmpfile || echo "nameserver $ip" >>$tmpfile
		done
	;;
	"-r")
		for ip in "$@"; do
			grep -v "^nameserver $ip\$" $tmpfile >$tmpfile.2
			mv $tmpfile.2 $tmpfile
		done
	;;
	*)
		usage
	;;
esac

[ -e $tmpfile ] && cp $tmpfile /etc/resolv.conf
rm -f $tmpfile

exit 0