PageRenderTime 6ms CodeModel.GetById 2ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/ppp/ip-down.d/0dns-down

http://github.com/brinkman83/bashrc
Shell | 83 lines | 40 code | 22 blank | 21 comment | 15 complexity | c54aa38483b4467430dd1c15ba9f4a49 MD5 | raw file
 1#! /bin/sh
 2
 3# $Id: 0dns-down,v 1.2 2004/07/31 20:49:04 john Exp $
 4
 5# 0dns-down by John Hasler 1999-2004
 6# Any possessor of a copy of this program may treat it as if it
 7# were in the public domain.  I waive all rights.
 8
 9# Rev. Apr 12 2004 to use resolvconf if installed.
10
11# 0dns-down takes down what 0dns-up sets up.
12
13# If pppconfig has been removed we are not supposed to do anything.
14test -f /usr/sbin/pppconfig || exit 0
15
16# Strip options.
17PROVIDER=`echo "$PPP_IPPARAM" | cut -d' ' -f1`
18
19ETC="/etc"
20RUNDIR="/var/cache/pppconfig"
21RESOLVCONF="$ETC/resolv.conf"
22RESOLVBAK="$RUNDIR/resolv.conf.bak.$PROVIDER"
23TEMPRESOLV="$RUNDIR/0dns.$PROVIDER"
24PPPRESOLV="$ETC/ppp/resolv"
25
26if [ -x /sbin/resolvconf ]; then
27	[ "$1" = "0dns-clean" ] && exit 0
28	test -n "$PPP_IFACE" || exit 1
29	/sbin/resolvconf -d "${PPP_IFACE}.pppconfig"
30fi
31
32umask 022
33cd "$RUNDIR" || exit 1
34
35# Are we being called by dns-clean?  If so fix up /etc/resolv.conf
36# and clean out /var/cache/pppconfig.
37
38if [ "$1" = "0dns-clean" ]
39    then 
40    # Get the name of the provider active when we went down.  Assume there was only one.
41    PROVIDER=`ls -t resolv.conf.bak.* 2>/dev/null | awk 'BEGIN {FS = "." } /resolv\.conf\.bak/ {print $NF} {exit}'`
42    # If we don't have a provider we have nothing to do.
43    if [ -n "$PROVIDER " ]
44	then
45	RESOLVBAK="$RUNDIR/resolv.conf.bak.$PROVIDER"
46	[ -s "$RESOLVBAK" ] && /bin/cp -Lp "$RESOLVBAK" "$RESOLVCONF"
47    fi
48    exit 0
49fi
50
51# If we don't have a provider we have nothing to do.
52[ -z "$PROVIDER" ] && exit 0
53
54# Is PROVIDER something we can use?
55
56test -f "$PPPRESOLV/$PROVIDER" || exit 0
57
58# It is not an error for RESOLVBAK not to exist.
59
60if [ ! -f "$RESOLVBAK" ]
61    then
62    rm -f "$TEMPRESOLV"
63    exit 0
64fi
65
66# Make sure that the resolv.conf that 0dns-up installed has not been
67# altered.  If has give up.
68
69if [ `stat -c %Y "$TEMPRESOLV"` -ne `stat -c %Y "$RESOLVCONF"` ]
70then
71    rm -f "$TEMPRESOLV" "$RESOLVBAK"
72    exit 0
73fi
74
75# Restore resolv.conf.  Follow symlinks.
76
77/bin/cp -Lp "$RESOLVBAK" "$RESOLVCONF" || exit 1
78rm -f "$RESOLVBAK" "$TEMPRESOLV"
79
80# Tell nscd about what we've done.
81
82# Restart nscd because resolv.conf has changed
83[ -x /etc/init.d/nscd ] && { /etc/init.d/nscd restart || true ; }