From c101203b25cc1add4e0ef5b15e5108e138772e88 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 19 Sep 2020 08:46:47 -0500 Subject: [PATCH] acpid: cleanup handler * Use $( rather than ` * Use spaces consistently * Quote all parameter expansions * Use a parameter expansion rather than sed * Use printf instead of echo echo with arguments is not well defined by POSIX. Additionally if the variable starts with -, the results are further undefined. Use printf to avoid all issues. * Add screen brightness controls * drop all dbus/xauth nonsense (by Piraty) Closes: #25909 [via git-merge-pr] --- srcpkgs/acpid/files/handler.sh | 76 ++++++++++++++++++---------------- srcpkgs/acpid/template | 2 +- 2 files changed, 41 insertions(+), 37 deletions(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index c2a12be13b1..df6b28a0966 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -4,42 +4,38 @@ # NOTE: This is a 2.6-centric script. If you use 2.4.x, you'll have to # modify it to not use /sys -minspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq` -maxspeed=`cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq` +# $1 should be + or - to step up or down the brightness. +step_backlight() { + for backlight in /sys/class/backlight/*/; do + [ -d "$backlight" ] || continue + step=$(( $(cat "$backlight/max_brightness") / 20 )) + printf '%s' "$(( $(cat "$backlight/brightness") $1 step ))" >"$backlight/brightness" + done +} + +minspeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_min_freq) +maxspeed=$(cat /sys/devices/system/cpu/cpu0/cpufreq/cpuinfo_max_freq) setspeed="/sys/devices/system/cpu/cpu0/cpufreq/scaling_setspeed" -set $* - -PID=$(pgrep dbus-launch) -export USER=$(ps -o user --no-headers $PID) -USERHOME=$(getent passwd $USER | cut -d: -f6) -export XAUTHORITY="$USERHOME/.Xauthority" -for x in /tmp/.X11-unix/*; do - displaynum=`echo $x | sed s#/tmp/.X11-unix/X##` - if [ x"$XAUTHORITY" != x"" ]; then - export DISPLAY=":$displaynum" - fi -done case "$1" in button/power) - #echo "PowerButton pressed!">/dev/tty5 case "$2" in PBTN|PWRF) - logger "PowerButton pressed: $2, shutting down..." - shutdown -P now - ;; - *) logger "ACPI action undefined: $2" ;; + logger "PowerButton pressed: $2, shutting down..." + shutdown -P now + ;; + *) logger "ACPI action undefined: $2" ;; esac ;; button/sleep) case "$2" in SBTN|SLPB) - # suspend-to-ram - logger "Sleep Button pressed: $2, suspending..." - zzz - ;; - *) logger "ACPI action undefined: $2" ;; + # suspend-to-ram + logger "Sleep Button pressed: $2, suspending..." + zzz + ;; + *) logger "ACPI action undefined: $2" ;; esac ;; ac_adapter) @@ -47,11 +43,11 @@ case "$1" in AC|ACAD|ADP0) case "$4" in 00000000) - echo -n $minspeed >$setspeed + printf '%s' "$minspeed" >"$setspeed" #/etc/laptop-mode/laptop-mode start ;; 00000001) - echo -n $maxspeed >$setspeed + printf '%s' "$maxspeed" >"$setspeed" #/etc/laptop-mode/laptop-mode stop ;; esac @@ -75,16 +71,24 @@ case "$1" in esac ;; button/lid) - case "$3" in - close) - # suspend-to-ram - logger "LID closed, suspending..." - zzz - ;; - open) logger "LID opened" ;; - *) logger "ACPI action undefined (LID): $2";; - esac - ;; + case "$3" in + close) + # suspend-to-ram + logger "LID closed, suspending..." + zzz + ;; + open) + logger "LID opened" + ;; + *) logger "ACPI action undefined (LID): $2";; + esac + ;; + video/brightnessdown) + step_backlight - + ;; + video/brightnessup) + step_backlight + + ;; *) logger "ACPI group/action undefined: $1 / $2" ;; diff --git a/srcpkgs/acpid/template b/srcpkgs/acpid/template index 8312d0e4e15..a45294f1c57 100644 --- a/srcpkgs/acpid/template +++ b/srcpkgs/acpid/template @@ -1,7 +1,7 @@ # Template file for 'acpid' pkgname=acpid version=2.0.32 -revision=1 +revision=2 build_style=gnu-configure short_desc="The ACPI Daemon (acpid) With Netlink Support" maintainer="Enno Boland "