Skip to content

Instantly share code, notes, and snippets.

@amaya382
Last active December 12, 2017 03:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save amaya382/f705c43559175857285d6d71713d2a0e to your computer and use it in GitHub Desktop.
Save amaya382/f705c43559175857285d6d71713d2a0e to your computer and use it in GitHub Desktop.
#!/bin/sh -eu
BRD='10.255.255.255' # for searching interface
enable_wol() {
sudo ethtool -s $1 wol g
sudo sh -c 'cat << EOF > /etc/systemd/system/wol@.service
[Unit]
Description=Wake-on-LAN for %i
Requires=network.target
After=network.target
[Service]
ExecStart=ethtool -s %i wol g
Type=oneshot
[Install]
WantedBy=multi-user.target
EOF'
sudo systemctl enable wol@$1
echo "Enabled ($1)"
}
sudo apt update
sudo apt install -y ethtool
INTERFACE=`ip -o a | grep ${BRD} | cut -d' ' -f2`
[ "`sudo ethtool ${INTERFACE} | grep -oP '(?<=^\sWake-on:\s).'`" = 'g' \
-a \
-f '/etc/systemd/system/wol@.service' ] \
&& echo "Already set (${INTERFACE})" \
|| enable_wol ${INTERFACE}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment