Skip to content

Instantly share code, notes, and snippets.

@nexus166
Last active July 3, 2019 16:32
Show Gist options
  • Select an option

  • Save nexus166/0f8cadeae848d7c01a64371b5f6dba6e to your computer and use it in GitHub Desktop.

Select an option

Save nexus166/0f8cadeae848d7c01a64371b5f6dba6e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set +xv -eo pipefail
enabled=
for _dev in $(realpath /sys/bus/usb/devices/*/power/wakeup); do
state="$(< ${_dev})";
printf "[%s]\t%s\n" "${state}" "${_dev}";
if [[ "${state}" == "enabled" ]]; then
enabled+=" ${_dev}";
fi
done
for _enabled in ${enabled}; do
printf 'disabled' > "${_enabled}" & printf '\n\nDISABLED\t%s\n' "${_enabled}";
done
if [[ ! -f /lib/systemd/system/nowakeup.service ]] && [[ "$(id -u)" == 0 ]]; then
cat << 'EOSVC' > /lib/systemd/system/nowakeup.service
[Unit]
Description=DISABLE automatic system WAKEUP with external devices
Before=network-pre.target
After=sysinit.target
[Service]
Type=oneshot
ExecStart=/usr/local/bin/nowakeup
[Install]
WantedBy=basic.target
EOSVC
systemctl enable nowakeup
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment