summaryrefslogtreecommitdiff
path: root/repo/system/acpid
diff options
context:
space:
mode:
Diffstat (limited to 'repo/system/acpid')
-rw-r--r--repo/system/acpid/acpid.confd7
-rw-r--r--repo/system/acpid/acpid.initd28
-rw-r--r--repo/system/acpid/acpid.xibuild37
-rw-r--r--repo/system/acpid/anything3
-rw-r--r--repo/system/acpid/handler.sh36
-rw-r--r--repo/system/acpid/lid-closed21
-rw-r--r--repo/system/acpid/power-supply-ac25
7 files changed, 157 insertions, 0 deletions
diff --git a/repo/system/acpid/acpid.confd b/repo/system/acpid/acpid.confd
new file mode 100644
index 0000000..2b3d304
--- /dev/null
+++ b/repo/system/acpid/acpid.confd
@@ -0,0 +1,7 @@
+# Configuration file for /etc/init.d/acpid (from acpid package)
+
+# Additional arguments to pass to acpid.
+command_args="--logevents"
+
+# Uncomment to use process supervisor.
+#supervisor="supervise-daemon"
diff --git a/repo/system/acpid/acpid.initd b/repo/system/acpid/acpid.initd
new file mode 100644
index 0000000..c2d60f9
--- /dev/null
+++ b/repo/system/acpid/acpid.initd
@@ -0,0 +1,28 @@
+#!/sbin/openrc-run
+
+description="The ACPI Daemon"
+
+extra_started_commands="reload"
+description_reload="Reload configuration"
+
+command="/sbin/acpid"
+command_args="--foreground ${command_args:-}"
+command_background="yes"
+pidfile="/run/$RC_SVCNAME.pid"
+
+depend() {
+ need dev localmount
+ after hwdrivers modules
+ provide acpid
+ keyword -vserver -lxc
+}
+
+reload() {
+ ebegin "Reloading $RC_SVCNAME configuration"
+ if [ "$supervisor" ]; then
+ $supervisor "$RC_SVCNAME" --signal HUP
+ else
+ start-stop-daemon --pidfile "$pidfile" --signal HUP
+ fi
+ eend $?
+}
diff --git a/repo/system/acpid/acpid.xibuild b/repo/system/acpid/acpid.xibuild
new file mode 100644
index 0000000..f960ac0
--- /dev/null
+++ b/repo/system/acpid/acpid.xibuild
@@ -0,0 +1,37 @@
+#!/bin/sh
+
+MAKEDEPS="make"
+DEPS="musl"
+
+PKG_VER=2.0.33
+SOURCE=https://downloads.sourceforge.net/acpid2/acpid-$PKG_VER.tar.xz
+DESC="Daemon for battery, power, and thermal readings"
+
+ADDITIONAL="
+ acpid.confd
+ acpid.initd
+ anything
+ handler.sh
+ lid-closed
+ power-supply-ac
+"
+build () {
+ ./configure --prefix=/usr \
+ --docdir=/usr/share/doc/acpid-$PKG_VER &&
+ make
+}
+
+package () {
+ make DESTDIR=$PKG_DEST install
+ install -m755 -d $PKG_DEST/etc/acpi/events &&
+ cp -r samples $PKG_DEST/usr/share/doc/acpid-$PKG_VER
+
+ install -D -m 755 handler.sh etc/acpi/handler.sh
+ install -D -m 644 anything etc/acpi/events/anything
+ install -D -m 755 power-supply-ac usr/share/acpid/
+ install -D -m 755 lid-closed usr/share/acpid/
+
+ install -D -m 755 acpid.initd etc/init.d/acpid
+ install -D -m 644 acpid.confd etc/conf.d/acpid
+
+}
diff --git a/repo/system/acpid/anything b/repo/system/acpid/anything
new file mode 100644
index 0000000..d182898
--- /dev/null
+++ b/repo/system/acpid/anything
@@ -0,0 +1,3 @@
+# Pass all events to our one handler script
+event=.*
+action=/etc/acpi/handler.sh %e
diff --git a/repo/system/acpid/handler.sh b/repo/system/acpid/handler.sh
new file mode 100644
index 0000000..412ac02
--- /dev/null
+++ b/repo/system/acpid/handler.sh
@@ -0,0 +1,36 @@
+#!/bin/sh
+# vim: set ts=4:
+#
+# This is the default ACPI handler script that is configured in
+# /etc/acpi/events/anything to be called for every ACPI event.
+# You can edit it and add your own actions; treat it as a configuration file.
+#
+PATH="/usr/share/acpid:$PATH"
+alias log='logger -t acpid'
+
+# <dev-class>:<dev-name>:<notif-value>:<sup-value>
+case "$1:$2:$3:$4" in
+
+button/power:PWRF:*)
+ log 'Power button pressed'
+ # Shutdown the system unless it has a lid (notebook).
+ [ -e /proc/acpi/button/lid/LID ] || poweroff
+;;
+button/sleep:SLPB:*)
+ log 'Sleep button pressed'
+ # Suspend to RAM.
+ zzz
+;;
+button/lid:*:close:*)
+ log 'Lid closed'
+ # Suspend to RAM if AC adapter is not connected.
+ power-supply-ac || zzz
+;;
+ac_adapter:*:*:*0)
+ log 'AC adapter unplugged'
+ # Suspend to RAM if notebook's lid is closed.
+ lid-closed && zzz
+;;
+esac
+
+exit 0
diff --git a/repo/system/acpid/lid-closed b/repo/system/acpid/lid-closed
new file mode 100644
index 0000000..57ffb71
--- /dev/null
+++ b/repo/system/acpid/lid-closed
@@ -0,0 +1,21 @@
+#!/bin/sh
+# This script exits with status 0 if the latop's lid is closed, 1 if opened,
+# 10 if /proc/acpi/button/lid/LID/state does not exist or is not readable.
+set -u
+
+STATE_FILE='/proc/acpi/button/lid/LID/state'
+
+verbose=false
+[ "${1:-}" = '-v' ] && verbose=true
+
+if ! [ -r "$STATE_FILE" ]; then
+ $verbose && echo "$STATE_FILE does not exist or is not readable!" >&2
+ exit 10
+fi
+
+read -r _ state < "$STATE_FILE" || exit 10
+
+[ "$state" = 'closed' ]; rc=$?
+
+$verbose && echo $rc
+exit $rc
diff --git a/repo/system/acpid/power-supply-ac b/repo/system/acpid/power-supply-ac
new file mode 100644
index 0000000..337aae2
--- /dev/null
+++ b/repo/system/acpid/power-supply-ac
@@ -0,0 +1,25 @@
+#!/bin/sh
+# This script exits with status 0 when the computer is on AC power (or no AC
+# power supply found), 1 otherwise (i.e. running on battery).
+set -u
+
+verbose=false
+[ "${1:-}" = '-v' ] && verbose=true
+
+# If we do not have any power supplies, assume we are on AC.
+rc=0
+
+# Iterate through power supplies sysfs knows about.
+for ps in /sys/class/power_supply/*; do
+ [ -r $ps/online ] || continue
+ # We know we have an AC adaptor, our default return changes to failed.
+ rc=1
+
+ if [ "$(cat $ps/online)" -eq 1 ]; then
+ rc=0
+ break
+ fi
+done
+
+$verbose && echo $rc
+exit $rc