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