Skip to content

Instantly share code, notes, and snippets.

@tdg5
Created June 5, 2014 13:13
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 tdg5/faf0a09ddcd69cc54fd8 to your computer and use it in GitHub Desktop.
Save tdg5/faf0a09ddcd69cc54fd8 to your computer and use it in GitHub Desktop.
init.d script to manage acpi wakeup devices for Surface Pro
#! /bin/sh
### BEGIN INIT INFO
# Provides: acpi_wakeup
# Required-Start: $remote_fs $syslog $all
# Required-Stop: 0 6
# Default-Start: 1 2 3 4 5
# Default-Stop:
# Short-Description: Disable acpi wakeup for given devices
### END INIT INFO
DEVICES_REGEXP="(EHC1|EHC2|XHC).*enabled"
AWK_CMD='BEGIN {FS = "\t"}; '"/$DEVICES_REGEXP/ { print \$1}"
PATH=/sbin:/usr/sbin:/bin:/usr/bin
. /lib/init/vars.sh
. /lib/lsb/init-functions
status() {
if [ -e /proc/acpi/wakeup ]; then
if [ ! "$(cat /proc/acpi/wakeup | awk "$AWK_CMD")" = "" ]; then
echo "ACPI Wakeup devices have not been set"
exit 1
else
echo "ACPI Wakeup devices have been set"
exit 0
fi
else
echo "/proc/acpi/wakeup is not available"
exit 1
fi
}
case "$1" in
force-reload|reload|restart|start)
if [ -e /proc/acpi/wakeup ]; then
ACTIVE_DEVICES=$(cat /proc/acpi/wakeup | awk "$AWK_CMD")
for DEVICE in $ACTIVE_DEVICES; do
echo $DEVICE > /proc/acpi/wakeup
done
status
fi
;;
status)
status
;;
stop)
echo "Warning: Stop action is noop."
status
;;
*)
echo "Usage: $0 force-reload|reload|restart|start|status|stop" >&2
exit 3
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment