home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / share / avahi / enable_avahi < prev    next >
Encoding:
Text File  |  2007-03-27  |  1.3 KB  |  69 lines

  1. #!/bin/sh -e
  2.  
  3. # Author: Jonathan Riddell <jriddell@ubuntu.com>
  4. # (C) 2006  Canonical Ltd.
  5. #
  6. # Enable or disable Avahi by setting /etc/default/avahi-daemon
  7. # and restart daemon
  8. #
  9. # Argument:
  10. # 0: disable Avahi 
  11. # 1: enabled Avahi
  12. # Return 0 on success, or 1 on failure (prints error to stderr)
  13.  
  14. STATUS_SCRIPT=/usr/share/avahi/avahi_status
  15. CONF=/etc/default/avahi-daemon
  16.  
  17. [ -x $STATUS_SCRIPT ] || {
  18.     echo "Error: cannot execute $STATUS_SCRIPT" >&2
  19.     exit 1
  20. }
  21.  
  22. set +e
  23. $STATUS_SCRIPT
  24. STATUS=$?
  25. set -e
  26.  
  27. case "$1" in
  28.     0)
  29.     NEWVAL=0
  30.     ;;
  31.     1)
  32.     NEWVAL=1
  33.     ;;
  34.     *)
  35.     echo "Invalid argument (must be 0 or 1)" >&2
  36.     exit 1
  37.     ;;
  38. esac
  39.  
  40. [ $STATUS = 0 -o $STATUS = 1 ] || {
  41.     echo "Error: cannot modify custom configuration" >&2
  42.     exit 1
  43. }
  44.  
  45. # nothing to do?
  46. [ $1 != $STATUS ] || exit 0
  47.  
  48.  
  49. if [ $1 = 0 ]; then
  50.     sed -ri "s/^[[:space:]]*AVAHI_DAEMON_START=1/AVAHI_DAEMON_START=0/i" $CONF
  51.     if [ -x "/etc/init.d/avahi-daemon" ]; then
  52.         if [ -x /usr/sbin/invoke-rc.d ]; then
  53.         invoke-rc.d avahi-daemon stop || exit 0
  54.         else
  55.         /etc/init.d/avahi-daemon stop || exit 0
  56.         fi
  57.     fi
  58. else
  59.     sed -ri "s/^[[:space:]]*AVAHI_DAEMON_START=0/AVAHI_DAEMON_START=1/i" $CONF
  60.     if [ -x "/etc/init.d/avahi-daemon" ]; then
  61.         if [ -x /usr/sbin/invoke-rc.d ]; then
  62.         invoke-rc.d avahi-daemon start || exit 0
  63.         else
  64.         /etc/init.d/avahi-daemon start || exit 0
  65.         fi
  66.     fi
  67. fi
  68.     
  69.