File: resolvconf

package info (click to toggle)
totd 1.4-4.3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 712 kB
  • ctags: 512
  • sloc: ansic: 5,840; sh: 2,929; perl: 116; makefile: 113
file content (64 lines) | stat: -rw-r--r-- 1,521 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/bin/sh

set -e

[ -x /usr/sbin/totd ] || exit 0
[ -x /lib/resolvconf/list-records ] || exit 1

TOTD_CONF=/etc/totd.conf

# Stores arguments (minus duplicates) in RSLT, separated by spaces
# Doesn't work properly if an argument itself contain whitespace
uniquify()
{
	RSLT=""
	while [ "$1" ] ; do
		for E in $RSLT ; do
			[ "$1" = "$E" ] && { shift ; continue 2 ; }
		done
		RSLT="${RSLT:+$RSLT }$1"
		shift
	done
}

ETCRESOLVCONF="/etc/resolvconf"
TMP_FILE="${ETCRESOLVCONF}/run/totd_new.$$"
clean_up() { rm -f "$TMP_FILE" ; }
trap clean_up EXIT
rm -f "$TMP_FILE"

# Get list of records, excluding all those for the loopback interface
RSLVCNFFILES="$(/lib/resolvconf/list-records | sed -e '/^lo$/d' -e '/^lo[.]/d')"

### Compile semicolon-separated list nameservers ###
NMSRVRS=""
if [ "$RSLVCNFFILES" ] ; then
	uniquify $(sed -n -e 's/^[[:space:]]*nameserver[[:space:]]\+//p' $RSLVCNFFILES)
	NMSRVRS="$RSLT"
fi

echo ";; totd.conf generated by $0" > "$TMP_FILE"

if [ -f $TOTD_CONF ]; then
	cat $TOTD_CONF \
		| sed -e 's/forwarder[[:space:]]\+//g' \
		| sed -e '/^$/d'
		>> $TMP_FILE
fi

for N in $NMSRVRS; do echo "forwarder $N" >> "$TMP_FILE" ; done

if [ "$1" = "-i" ] ; then
        mv -f "$TMP_FILE" "$TOTD_CONF"
        exit 0
fi

if [ -x /usr/bin/diff ] && [ -f "$TOTD_CONF" ] && \
	/usr/bin/diff -q "$TOTD_CONF" "$TMP_FILE" > /dev/null ; then
        # No change
	rm -f "$TMP_FILE"
else
        mv -f "$TMP_FILE" "$TOTD_CONF"
	[ -x /etc/init.d/totd ] && /etc/init.d/totd restart > /dev/null 2>&1 \
		|| :
fi