Skip to content

Commit

Permalink
Apply WOL to all interfadces (epoptes#186)
Browse files Browse the repository at this point in the history
  • Loading branch information
eltoukos committed Jul 25, 2023
1 parent 98ba08e commit a6a1bb9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -412,3 +412,7 @@ Implement Client.info().
Follow mentor advice to resolve existing upstream epoptes issues reported on
github, in place of the aforementioned blocked tasks. Resolve "server.crt is
blank" (#194).

### 2023-07-25

Apply WOL to all available Ethernet interfaces (#186).
34 changes: 16 additions & 18 deletions epoptes-client/epoptes-client
Original file line number Diff line number Diff line change
Expand Up @@ -145,25 +145,23 @@ wait_for_dns() {
done
}

# Set WoL to the desired state for all currently available Ethernet adapters
apply_wol() {
local def_iface _ip

if [ "$UID" -eq 0 ] && [ -n "$WOL" ] && [ -x /sbin/ethtool ] &&
[ "$EPOPTES_CLIENT_APPLIED_WOL" != True ]; then
export EPOPTES_CLIENT_APPLIED_WOL=True
# Copied from client-functions, these map from server_ip to def_iface
read -r def_iface _ip <<EOF
$(ip route get "$server_ip" | sed -n 's/.*dev *\([^ ]*\).*src *\([^ ]*\).*/\1 \2/p')
EOF
test "${def_iface:-lo}" != "lo" || read -r def_iface _ip <<EOF
$(ip route get 192.168.67.0 | sed -n 's/.*dev *\([^ ]*\).*src *\([^ ]*\).*/\1 \2/p')
EOF
if [ "${def_iface:-lo}" != "lo" ]; then
# Only set WOL if def_iface is both != '' and != 'lo'.
echo "Setting WOL=$WOL for $def_iface"
ethtool -s "$def_iface" wol "$WOL"
fi
fi
local tarwol fpath iface

test "$UID" -eq 0 || return 0
# Set target WOL to "g" if WOL is unset
tarwol=${WOL-g}
# Return if WOL="ignore" or WOL=""
test "${tarwol:-ignore}" != "ignore" || return 0
test -x /sbin/ethtool || return 0
# Only handle devices with a physical MAC address
for fpath in /sys/class/net/*/device/net/*/address; do
test -f "$fpath" || continue
iface=${fpath%/address}
iface=${iface##*/}
ethtool -s "$iface" wol "$tarwol"
done
}

# Main.
Expand Down

0 comments on commit a6a1bb9

Please sign in to comment.