File: arm-wol

package info (click to toggle)
drbl 5.8.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 6,996 kB
  • sloc: sh: 43,555; perl: 8,820; xml: 867; makefile: 135
file content (58 lines) | stat: -rwxr-xr-x 1,654 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#!/bin/bash
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
#
# To arm wake on LAN for NIC in DRBL client.
#
# chkconfig: 2345 99 99
# description: To arm wake on LAN for NIC in DRBL client before it poweroffs.
# Author: Steven Shiau <steven _at_ clonezilla org>
# License: GPL
#
# For SuSE insserv
### BEGIN INIT INFO
# Provides: arm-wol
# Required-Start:
# Required-Stop:
# X-UnitedLinux-Should-Start: 
# X-UnitedLinux-Should-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: To arm wake on LAN for NIC in DRBL client before it poweroffs.
### END INIT INFO

# Append a default search path.
PATH="$PATH:/sbin:/usr/sbin:/bin:/usr/bin:/usr/X11R6/bin"
export PATH

#
if [ ! "$UID" = "0" ]; then
  echo
  echo "[$LOGNAME] You need to run this script \"`basename $0`\" as root."
  echo
  exit 1
fi

# Exclude some devices, like lo, sit0, vmnet... It's regular expression.
exluding_dev="(lo|sit[0-9]+|vmnet)"
export LC_ALL=C
if [ -d /sys/class/net/ ]; then
  # kernel support sysfs, so get the NIC devices from /sys
  NETDEVICES="$(unalias ls &>/dev/null; ls /sys/class/net/ | grep -v -E "$exluding_dev")"
elif [ -f /proc/net/dev ]; then
  # kernel do not support sysfs, so get the NIC devices from /proc
  NETDEVICES="$(cat /proc/net/dev | grep "^.*:" | cut -d: -f1 | grep -v -E "$exluding_dev")"
else
  echo "Network interface card is not found in /sys/class/net/ or /proc/net/dev!"
  echo "Program terminated!"
  exit 1
fi
echo -n "Trying to arm the wake on LAN for "
RETVAL=0
for nic in $NETDEVICES; do
  echo -n "$nic... "
  ethtool -s $nic wol g &> /dev/null
  RETVAL="$((RETVAL+$?))"
done
echo "done!"
exit $RETVAL