Skip to content

Instantly share code, notes, and snippets.

@witoldsz
Last active November 13, 2017 16:29
Show Gist options
  • Save witoldsz/8c2ae1cf89b683ce6931a8100025580c to your computer and use it in GitHub Desktop.
Save witoldsz/8c2ae1cf89b683ce6931a8100025580c to your computer and use it in GitHub Desktop.
Wake up using ONLY power button

The script scans /proc/acpi/wakeup for all enabled entries, excluding power button and some custom hardware (like sleep buttons) and disables that entries. Especially useful if your computer wakes up on mouse movement or keyboard.

Prerequisites

  • ghc
  • cabal
  • text Haskell library

#Ubuntu:

  • sudo apt-get install ghc cabal-install
  • cabal update
  • cabal install text

Run script:

sudo ./script.hs

The script will alter /proc/acpi/wakeup. It won't affect it upon system restart, so the script has to be launched on system startup or before entering sleep mode to persist.

P.S.

There is also the bash version. It does not need ghc, cabal or text Haskell lib.

#!/usr/bin/env runhaskell
{-# LANGUAGE OverloadedStrings #-}
import qualified Data.Text.IO as TIO
import qualified Data.Text as T
import Data.Function
main :: IO ()
main = do
file <- TIO.readFile "/proc/acpi/wakeup"
file
& T.lines
& filter (T.isInfixOf "enabled")
& filter (not . T.isInfixOf "PWRB")
& filter (not . T.isInfixOf "platform")
& map (head . T.words)
& mapM_ (TIO.writeFile "/proc/acpi/wakeup")
#!/bin/bash
for x in $(grep enabled /proc/acpi/wakeup | cut -f1 | grep -v PWRB | grep -v platform)
do
echo $x | sudo tee /proc/acpi/wakeup
done
Device S-state Status Sysfs node
LID S4 *enabled platform:PNP0C0D:00
SLPB S3 *enabled platform:PNP0C0E:00
IGBE S4 *enabled pci:0000:00:1f.6
PXSX S4 *disabled pci:0000:03:00.0
PXSX S4 *disabled
PXSX S4 *disabled
PXSX S4 *disabled
PXSX S4 *disabled pci:0000:04:00.0
*disabled platform:rtsx_pci_sdmmc.0
*disabled platform:rtsx_pci_ms.0
PXSX S4 *disabled
XHCI S3 *enabled pci:0000:00:14.0
Device S-state Status Sysfs node
RP01 S4 *disabled pci:0000:00:1c.0
PXSX S4 *disabled
RP06 S4 *disabled pci:0000:00:1c.5
PXSX S4 *enabled pci:0000:02:00.0
RP07 S4 *disabled pci:0000:00:1c.6
PXSX S4 *disabled pci:0000:03:00.0
GLAN S4 *disabled
EHC1 S4 *enabled pci:0000:00:1d.0
EHC2 S4 *enabled pci:0000:00:1a.0
XHC S4 *enabled pci:0000:00:14.0
HDEF S4 *disabled pci:0000:00:1b.0
PEG0 S4 *disabled
PEGP S4 *disabled
PEG1 S4 *disabled
PEG2 S4 *disabled
PWRB S3 *enabled
@witoldsz
Copy link
Author

witoldsz commented Aug 16, 2017

Which version looks better?

main = do
  map (head . words)
    . filter (T.isInfixOf "enabled")
    . filter (T.isInfixOf "enabled")
    . filter (not . T.isInfixOf "PWRB")
    . lines
    <$> readFile "/proc/acpi/wakeup"
    >>= mapM_ (writeFile "/proc/acpi/wakeup")

vs

main = do
  file <- readFile "/proc/acpi/wakeup"
  file
    & lines
    & filter (T.isInfixOf "enabled")
    & filter (not . T.isInfixOf "PWRB")
    & filter (not . T.isInfixOf "platform")
    & map (head . words)
    & mapM_ (writeFile "/proc/acpi/wakeup")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment