Last active
December 12, 2017 03:05
-
-
Save amaya382/f705c43559175857285d6d71713d2a0e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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