home *** CD-ROM | disk | FTP | other *** search
/ tusportal.tus.k12.pa.us / tusportal.tus.k12.pa.us.tar / tusportal.tus.k12.pa.us / Wyse / latest-image.raw / 0.img / usr / lib / hal / scripts / linux / hal-system-wol-linux < prev    next >
Text File  |  2010-05-09  |  2KB  |  85 lines

  1. #!/bin/bash
  2. #
  3. # Copyright (C) 2007 Holger Macht <holger@homac.de>
  4. #
  5. # Author: Holger Macht <holger@homac.de>
  6. #
  7. # This file is released under the GPLv2.
  8. #
  9.  
  10. SUPPORT_FLAGS=
  11. IFACE="$HAL_PROP_NET_INTERFACE"
  12.  
  13. wol_get_flags() {
  14.     SUPPORT_FLAGS=`ethtool $IFACE | awk '/Supports Wake-on:/{if ($3 ~ /g/) print $3 }'`
  15.     [ -n "$SUPPORT_FLAGS" ] && return 0
  16.     echo "org.freedesktop.Hal.Device.WakeOnLAN.NotSupported" >&2
  17.     echo "Network interface does not support Wake On LAN" >&2
  18.     exit 1
  19. }
  20.  
  21. wol_supported() {
  22.     wol_get_flags
  23.     [ -n "$SUPPORT_FLAGS" ] && return 0
  24.     return 1
  25. }
  26.  
  27. wol_enabled() {
  28.     ENABLED=`ethtool $IFACE | awk '/[^s ]Wake-on:/{if ($2 ~ /g/) print $2 }'`
  29.     [ -n "$ENABLED" ] && return 0
  30.     return 1
  31. }
  32.  
  33. wol_enable() {
  34.     wol_get_flags
  35.  
  36.     if [ -z "$SUPPORT_FLAGS" ]; then
  37.     echo "No support flags set, using default: g"
  38.     SUPPORT_FLAGS=g
  39.     fi
  40.  
  41.     ethtool -s $IFACE wol $SUPPORT_FLAGS
  42.     if [ "$?" != "0" ]; then
  43.     echo "error enabling wake on LAN for interface $IFACE"
  44.     return 1
  45.     fi
  46. }
  47.  
  48. wol_disable() {
  49.     ethtool -s $IFACE wol d
  50.     if [ "$?" != "0" ]; then
  51.     echo "error disabling wake on LAN for interface $IFACE"
  52.     return 1
  53.     fi
  54. }
  55.  
  56. which ethtool >/dev/null 2>&1
  57. if [ "$?" != "0" ]; then
  58.     echo "org.freedesktop.Hal.Device.WakeOnLan.NoEthtool" >&2
  59.     echo -e "No ethtool found in \$PATH" >&2
  60.     exit 1
  61. fi
  62.  
  63. case "`basename $0`" in
  64.     hal-system-wol-supported-linux)
  65.     wol_supported
  66.     ;;
  67.     hal-system-wol-enabled-linux)
  68.     wol_enabled
  69.     ;;
  70.     hal-system-wol-enable-linux)
  71.     if [ "$enable" = "true" ]; then
  72.         wol_enable
  73.     elif [ "$enable" = "false" ]; then
  74.         wol_disable
  75.     else
  76.         echo "org.freedesktop.Hal.Device.WakeOnLAN.InvalidArgument" >&2
  77.         echo "argument must be of boolean type" >&2
  78.         exit 1
  79.     fi
  80.     ;;
  81.     *) ;;
  82. esac
  83.  
  84. exit $?
  85.