Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add wake on lan toggle ujust per (#1708) #2151

Merged
merged 7 commits into from
Jan 27, 2025
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,65 @@ toggle-bt-mic:
echo "No changes were made."
fi

# enable or disable wake-on-lan functionality
toggle-wol:
#!/usr/bin/bash
INTERFACE=$(ip link show | awk '/state UP/ {print $2}' | tr -d ':' | grep -E '^(en|eth)')
if [[ -z "$INTERFACE" ]]; then
echo -e "${bold}No active Ethernet interface found.${normal}"
echo "Please ensure your Ethernet connection is enabled or connected."
echo "Exiting without making any changes."
exit 0
fi
CONFIG_FILE="/etc/udev/rules.d/81-wol.rules"
SERVICE_FILE="/etc/systemd/system/force-wol.service"
WOL_STATUS=$(sudo ethtool $INTERFACE | grep "Wake-on" | awk '{print $2}')
CURRENT_STATE="Disabled"
if [[ "$WOL_STATUS" == "g" ]]; then
CURRENT_STATE="Enabled"
fi
echo "Wake-on-LAN is currently: ${bold}${CURRENT_STATE}${normal}"
echo "Enable, Disable Wake-on-LAN, Create Service, or Exit without saving?"
xXJSONDeruloXx marked this conversation as resolved.
Show resolved Hide resolved
echo "Note: Create service if Enabling is not persistent."
OPTION=$(ugum choose Enable Disable Create-Service Exit)
if [[ "${OPTION,,}" == "enable" ]]; then
echo "You chose to enable Wake-on-LAN."
echo "Requesting root privileges..."
sudo ethtool -s $INTERFACE wol g
if ! grep -q "$INTERFACE" "$CONFIG_FILE" 2>/dev/null; then
echo "Creating udev rule to make this setting persistent..."
echo "ACTION==\"add\", SUBSYSTEM==\"net\", NAME==\"$INTERFACE\", RUN+=\"/usr/bin/ethtool -s \$name wol g\"" | sudo tee "$CONFIG_FILE" > /dev/null
fi
echo "Wake-on-LAN has been ${green}${bold}enabled${normal}."
elif [[ "${OPTION,,}" == "disable" ]]; then
echo "You chose to disable Wake-on-LAN."
echo "Requesting root privileges..."
sudo ethtool -s $INTERFACE wol d
if [[ -f "$CONFIG_FILE" ]]; then
echo "Removing udev rule to disable persistence..."
sudo rm -f "$CONFIG_FILE"
fi
echo "Wake-on-LAN has been ${red}${bold}disabled${normal}."
elif [[ "${OPTION,,}" == "Create-Service" ]]; then
echo "You chose to create a systemd service for enabling WOL at boot."
echo "Requesting root privileges..."
sudo bash -c "cat > $SERVICE_FILE" <<EOF
[Unit]
Description=Force Enable Wake-on-LAN
After=network-online.target
[Service]
Type=oneshot
ExecStart=/sbin/ethtool -s $INTERFACE wol g
[Install]
WantedBy=network-online.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable force-wol.service
echo "Systemd service created and enabled at boot: ${green}${bold}force-wol.service${normal}"
else
echo "No changes were made."
fi

toggle-i915-sleep-fix:
#!/usr/bin/bash
# Explain the purpose of the script
Expand Down