#!/bin/sh
# $Id: wakeonlan.sh,v 1.1 2006/03/29 12:35:14 eha Exp eha $
# =============================================================================
# 
# Slackware script for customized setup of network interfaces.
# Parameters:
# $1  : interface name
# $2  : <pre|post|stop>
#
# If the script ends with 'RETURN=1', then rc.inet1 will omit further
# processing of the if_up / if_down function for this interface.
# You can use that for instance if you want total control over your interface
# configuration; put all your functionality in the pre() function and let that
# end with a "RETURN=1".
#
# =============================================================================
# 
# This is an example script that sets the wake-on-lan property for the network
# card.Use the wakeonlan package to send a "wakeonlan magic packet" to your 
# computer when it is powered off. If the network card supports WOL, then the
# computer should power on after receiving the magic packet..
# Setting WOL only seems to work after the network interface was deactivated,
# So, this is conveniently done when Slackware shuts down by using the "post"
# action of the script, because Slackware calls "rc.inet1 stop" at shutdown.
#
# A Slackware package for wakeonlan is available at
# http://www.slackware.com/~alien/slackbuilds/wakeonlan/
#
# Eric Hameleers <alien@slackware.com>
#
# =============================================================================
# 

INTERFACE=$1
ACTION=$2
RETURN=${RETURN:-0}

pre() {
  # Nothing to do here
  return
}

post() {
  # Nothing to do here
  return
}

stop() {
  # Set the WOL property
  /usr/sbin/ethtool -s ${INTERFACE} wol g
}

case "$ACTION" in
'pre')
  pre
  ;;
'post')
  post
  ;;
'stop')
  stop
  ;;
*)
  echo "usage $0 <INTERFACE> <pre|post|stop>"
esac

# This script must NEVER call 'exit' !
# It can end with 'return' so that the calling script rc.inet1 will stop further
# processing of the parent function (if_up or if_down).
# To end the script with 'return' you should set RETURN=1 in one of the
# "pre|post|stop" functions, where ever you deem it appropriate.

