From de16da348671bd797500ab144ae56d23e88c7463 Mon Sep 17 00:00:00 2001 From: davidovski Date: Wed, 30 Mar 2022 17:54:09 +0100 Subject: fixed initd files --- extra/acpid/acpid.confd | 7 +++++++ extra/acpid/acpid.initd | 28 ++++++++++++++++++++++++++++ extra/acpid/anything | 3 +++ extra/acpid/handler.sh | 36 ++++++++++++++++++++++++++++++++++++ extra/acpid/lid-closed | 21 +++++++++++++++++++++ extra/acpid/power-supply-ac | 25 +++++++++++++++++++++++++ 6 files changed, 120 insertions(+) create mode 100644 extra/acpid/acpid.confd create mode 100644 extra/acpid/acpid.initd create mode 100644 extra/acpid/anything create mode 100644 extra/acpid/handler.sh create mode 100644 extra/acpid/lid-closed create mode 100644 extra/acpid/power-supply-ac (limited to 'extra/acpid') diff --git a/extra/acpid/acpid.confd b/extra/acpid/acpid.confd new file mode 100644 index 0000000..2b3d304 --- /dev/null +++ b/extra/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/extra/acpid/acpid.initd b/extra/acpid/acpid.initd new file mode 100644 index 0000000..c2d60f9 --- /dev/null +++ b/extra/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/extra/acpid/anything b/extra/acpid/anything new file mode 100644 index 0000000..d182898 --- /dev/null +++ b/extra/acpid/anything @@ -0,0 +1,3 @@ +# Pass all events to our one handler script +event=.* +action=/etc/acpi/handler.sh %e diff --git a/extra/acpid/handler.sh b/extra/acpid/handler.sh new file mode 100644 index 0000000..412ac02 --- /dev/null +++ b/extra/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' + +# ::: +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/extra/acpid/lid-closed b/extra/acpid/lid-closed new file mode 100644 index 0000000..57ffb71 --- /dev/null +++ b/extra/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/extra/acpid/power-supply-ac b/extra/acpid/power-supply-ac new file mode 100644 index 0000000..337aae2 --- /dev/null +++ b/extra/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 -- cgit v1.2.1