aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorSávio Carlos Martins Costa2018-06-14 15:13:26 -0300
committerSávio Carlos Martins Costa2018-06-14 15:13:26 -0300
commita8516573f70cc5001b6b31849d79acd5a63edce9 (patch)
tree299c805f8ba76bece896a95c2d51096171933a36
downloadaur-a8516573f70cc5001b6b31849d79acd5a63edce9.tar.gz
version 0.2.2
-rw-r--r--.SRCINFO18
-rw-r--r--PKGBUILD25
-rw-r--r--README.md28
-rw-r--r--wakeup-triggers.conf24
-rw-r--r--wakeup-triggers.service11
-rw-r--r--wakeup-triggers.sh60
6 files changed, 166 insertions, 0 deletions
diff --git a/.SRCINFO b/.SRCINFO
new file mode 100644
index 000000000000..373e5b5006b4
--- /dev/null
+++ b/.SRCINFO
@@ -0,0 +1,18 @@
+pkgbase = wakeup-triggers
+ pkgdesc = Let the user set the wakeup triggers of system suspension
+ pkgver = 0.2.2
+ pkgrel = 1
+ url = https://gitlab.com/saviocmc/wakeup-triggers
+ arch = any
+ license = MIT
+ depends = systemd
+ backup = etc/wakeup-triggers.conf
+ source = wakeup-triggers.sh
+ source = wakeup-triggers.conf
+ source = wakeup-triggers.service
+ sha512sums = 9166fc3b572764bb79005a3738805005d133165c9bfd03a04bcd98199805564d87cec3de85e858aeafa31ffc11baefdd4e37587e000613688c41a4ebdc7e591a
+ sha512sums = aed7df02adcf97ff8c62060f6c9f1f3a6772e2f320b294de22f8d7f4c83a8f52318936c6b58a022fa2b6bbf85339f9becaa9992083c6a80aed04f9baa925a0bb
+ sha512sums = 47afe6a17a83453c5235c27dcb8111700506921a9eac91c056fd2f09c1b2f08a1382aaa6b3f7cac05fe49958caf42b3c5df84a284f4859f74ddc9469edfacead
+
+pkgname = wakeup-triggers
+
diff --git a/PKGBUILD b/PKGBUILD
new file mode 100644
index 000000000000..302238f19a50
--- /dev/null
+++ b/PKGBUILD
@@ -0,0 +1,25 @@
+# Maintainer: Sávio Costa <saviocmc at protonmail dot com>
+pkgname=wakeup-triggers
+pkgver=0.2.2
+pkgrel=1
+pkgdesc='Let the user set the wakeup triggers of system suspension'
+arch=('any')
+url=https://gitlab.com/saviocmc/wakeup-triggers
+license=(MIT)
+depends=(systemd)
+source=(wakeup-triggers.sh wakeup-triggers.conf wakeup-triggers.service)
+sha512sums=(
+ '9166fc3b572764bb79005a3738805005d133165c9bfd03a04bcd98199805564d87cec3de85e858aeafa31ffc11baefdd4e37587e000613688c41a4ebdc7e591a'
+ 'aed7df02adcf97ff8c62060f6c9f1f3a6772e2f320b294de22f8d7f4c83a8f52318936c6b58a022fa2b6bbf85339f9becaa9992083c6a80aed04f9baa925a0bb'
+ '47afe6a17a83453c5235c27dcb8111700506921a9eac91c056fd2f09c1b2f08a1382aaa6b3f7cac05fe49958caf42b3c5df84a284f4859f74ddc9469edfacead'
+)
+backup=('etc/wakeup-triggers.conf')
+
+package() {
+ mkdir -p $pkgdir/usr/bin
+ install -Dm755 wakeup-triggers.sh $pkgdir/usr/bin/
+ mkdir -p $pkgdir/usr/lib/systemd/system
+ install -Dm644 wakeup-triggers.service $pkgdir/usr/lib/systemd/system/
+ mkdir -p $pkgdir/etc
+ install -Dm644 wakeup-triggers.conf $pkgdir/etc
+} \ No newline at end of file
diff --git a/README.md b/README.md
new file mode 100644
index 000000000000..d175c93ddb5f
--- /dev/null
+++ b/README.md
@@ -0,0 +1,28 @@
+# Wakeup Triggers
+
+This project is basically a [systemd](https://wiki.archlinux.org/index.php/Systemd) unit file that calls a simple script that disable all wakeup triggers but the ones specified by the user in a [config file](wakeup-triggers.conf).
+
+This is useful when the file ``/proc/acpi/wakeup`` has a lot of wakeup triggers enable by default. This can cause the system to resume from suspension very easy (like when a USB device is unplugged).
+
+This problem is listed [here](https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Instantaneous_wakeups_from_suspend) in the Arch Wiki article about System Suspension and Hibernation and the script used here was based on the work-around solution described there.
+
+The "start" function of the script [wakeup-triggers.sh](wakeup-triggers.sh) disable all the default enabled triggers leaving just the ones the user wants, specified in the config file. The "stop" function of the script restores the original triggers.
+
+To discover what triggers your system supports, take a look at the file ``/proc/acpi/wakeup``. Each line represents a trigger. There you can see also which of them are enabled by default in your system. Once you decide which ones you want to be activated by this service, put in the [config file](wakeup-triggers.conf) the name of the associated device (the letters in the first column of the line, eg. "PWRB" for the power button press or "LID" for the laptop's lid opening).
+
+The config file is placed in ``/etc/wakeup-triggers.conf``. It came with two triggers enabled by default, the power button (PWRB) and the LID (LID0) for laptops. The sleep button (SLPB) is commented with '#' and will not be enable. This is just to show how you can activate and deactivate triggers easily by commenting the lines (putting or removing the '#'). After changing the config file, the service must be restarted. It can be done by systemd by typing ``sudo systemctl restart wakeup-triggers.service``.
+
+This project has a [PKGBUILD](https://wiki.archlinux.org/index.php/PKGBUILD) file that can be used to create a package with [makepkg](https://wiki.archlinux.org/index.php/Makepkg). The package can be then installed with [pacman](https://www.archlinux.org/pacman) on a Arch Linux system.
+
+In order to the script run on every boot, the [wakeup-triggers.service](wakeup-triggers.service) unit must be enable in systemd.
+
+So, to clone, package, install and enable this project, just run:
+
+```
+git clone https://gitlab.com/saviocmc/wakeup-triggers.git
+cd wakeup-triggers
+makepkg -ci
+sudo systemctl enable wakeup-triggers.service
+```
+
+The script should now run on next boot
diff --git a/wakeup-triggers.conf b/wakeup-triggers.conf
new file mode 100644
index 000000000000..e810169aa706
--- /dev/null
+++ b/wakeup-triggers.conf
@@ -0,0 +1,24 @@
+# This is configuration file to the service "wakeup-triggers".
+# A wakeup trigger is an event that triggers the wakeup of the system when
+# it is suspended. Here you can specify which triggers the service must enable.
+#
+# To discover what triggers your system supports, take a look at the file
+# /proc/acpi/wakeup
+#
+# Each line represents a trigger. There you can see also which of them are
+# enabled by default in your system. Once you decide which ones you want to
+# be activated by this service, put here in this file the name of the associated
+# device (the letters in the first column of the line).
+#
+# Some examples are given below.
+
+
+# PWRB is the Power Button trigger
+PWRB
+
+# LID0 is the trigger related to the opening of the laptop's LID
+LID0
+
+# SLPB is the Sleep Button trigger (deactivated by default, to activate it
+# just remove the '#' in front of it and restart the service)
+#SLPB \ No newline at end of file
diff --git a/wakeup-triggers.service b/wakeup-triggers.service
new file mode 100644
index 000000000000..1c4dfb02b4b9
--- /dev/null
+++ b/wakeup-triggers.service
@@ -0,0 +1,11 @@
+[Unit]
+Description=Let the user set the wakeup triggers of system suspension
+
+[Service]
+Type=oneshot
+RemainAfterExit=yes
+ExecStart=/usr/bin/wakeup-triggers.sh start
+ExecStop=/usr/bin/wakeup-triggers.sh stop
+
+[Install]
+WantedBy=multi-user.target
diff --git a/wakeup-triggers.sh b/wakeup-triggers.sh
new file mode 100644
index 000000000000..5a5c6e75d55c
--- /dev/null
+++ b/wakeup-triggers.sh
@@ -0,0 +1,60 @@
+#!/usr/bin/bash
+
+# This is a script to disable all wakeup triggers but the power button (PWRB)
+# Based on the workaround provided for the problem described on Arch Wiki
+# https://wiki.archlinux.org/index.php/Power_management/Suspend_and_hibernate#Instantaneous_wakeups_from_suspend
+#
+# @author Sávio Carlos Martins Costa (saviocmc at protonmail dot com)
+
+# Sets the character of separation to be the new line \n (the default is a space)
+IFS=$'\n'
+
+WAKEUP=/proc/acpi/wakeup
+CONFIG=/etc/wakeup-triggers.conf
+BACKUP=/tmp/wakeup-triggers
+
+backupAndDisableAllCurrentTriggers() {
+ enabledTriggers=($(cat $WAKEUP | grep "enable"))
+ for trigger in "${enabledTriggers[@]}"; do
+ triggerCode=${trigger:0:4}
+ echo $triggerCode >> $BACKUP
+ echo $triggerCode > $WAKEUP
+ done
+}
+
+enableSelectedTriggers() {
+ selectedTriggers=($(cat $CONFIG | grep --invert-match '#' ))
+ for trigger in "${selectedTriggers[@]}"; do
+ echo $trigger > $WAKEUP
+ done
+}
+
+restoreBackup() {
+ enabledTriggers=($(cat $WAKEUP | grep "enable"))
+ for trigger in "${enabledTriggers[@]}"; do
+ triggerCode=${trigger:0:4}
+ echo $triggerCode > $WAKEUP
+ done
+ backupTriggers=($(cat $BACKUP))
+ for trigger in "${backupTriggers[@]}"; do
+ echo $trigger > $WAKEUP
+ done
+ rm $BACKUP
+}
+
+start() {
+ backupAndDisableAllCurrentTriggers
+ enableSelectedTriggers
+ exit 0
+}
+
+stop () {
+ restoreBackup
+ exit 0
+}
+
+case "$1" in
+ "start") start;;
+ "stop") stop;;
+ *) exit 1;;
+esac \ No newline at end of file