From adbd5ef2eaba73e17eb5b3cc269bd2bd24bf8d4a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 19 Sep 2020 08:46:47 -0500 Subject: [PATCH 1/6] acpid: Use $( rather than ` --- srcpkgs/acpid/files/handler.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index c2a12be13b1..5535b8bb38f 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -4,8 +4,8 @@ # 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` +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 $* @@ -15,7 +15,7 @@ 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##` + displaynum=$(echo $x | sed s#/tmp/.X11-unix/X##) if [ x"$XAUTHORITY" != x"" ]; then export DISPLAY=":$displaynum" fi From 5046a9c4126699f204c3c1974c63383eebbd982a Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 19 Sep 2020 08:51:12 -0500 Subject: [PATCH 2/6] acpid: Use spaces consistently --- srcpkgs/acpid/files/handler.sh | 40 ++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 19 deletions(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index 5535b8bb38f..0da0d5a094a 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -26,20 +26,20 @@ case "$1" in #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) @@ -75,16 +75,18 @@ 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 + ;; *) logger "ACPI group/action undefined: $1 / $2" ;; From 9b9486d1309285c552d6dc1f5cc305b5b1632d11 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 19 Sep 2020 08:54:27 -0500 Subject: [PATCH 3/6] acpid: Quote all parameter expansions --- srcpkgs/acpid/files/handler.sh | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index 0da0d5a094a..700ec46ffad 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -11,11 +11,11 @@ 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 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##) + displaynum=$(echo "$x" | sed s#/tmp/.X11-unix/X##) if [ x"$XAUTHORITY" != x"" ]; then export DISPLAY=":$displaynum" fi @@ -47,11 +47,11 @@ case "$1" in AC|ACAD|ADP0) case "$4" in 00000000) - echo -n $minspeed >$setspeed + echo -n "$minspeed" >"$setspeed" #/etc/laptop-mode/laptop-mode start ;; 00000001) - echo -n $maxspeed >$setspeed + echo -n "$maxspeed" >"$setspeed" #/etc/laptop-mode/laptop-mode stop ;; esac From 8501a8c44544cc098f45b7fb7cf9b3676086f221 Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 19 Sep 2020 08:55:56 -0500 Subject: [PATCH 4/6] acpid: Use a parameter expansion rather than sed --- srcpkgs/acpid/files/handler.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index 700ec46ffad..fb90b501a58 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -15,7 +15,7 @@ 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##) + displaynum=${x#/tmp/.X11-unix/X} if [ x"$XAUTHORITY" != x"" ]; then export DISPLAY=":$displaynum" fi From 37e95a80e0d2fd966904adbf4c1c3aeda7e6207c Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sat, 19 Sep 2020 08:56:19 -0500 Subject: [PATCH 5/6] acpid: 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. --- srcpkgs/acpid/files/handler.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index fb90b501a58..dd5aa6e03f8 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -47,11 +47,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 From aa3066bf879c3eeb4c8a0502fedf936afebeb8cd Mon Sep 17 00:00:00 2001 From: Matthew Martin Date: Sun, 25 Oct 2020 22:33:12 -0500 Subject: [PATCH 6/6] acpid: Add screen brightness controls --- srcpkgs/acpid/files/handler.sh | 15 +++++++++++++++ srcpkgs/acpid/template | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/srcpkgs/acpid/files/handler.sh b/srcpkgs/acpid/files/handler.sh index dd5aa6e03f8..7c23e3b94ed 100644 --- a/srcpkgs/acpid/files/handler.sh +++ b/srcpkgs/acpid/files/handler.sh @@ -4,6 +4,15 @@ # NOTE: This is a 2.6-centric script. If you use 2.4.x, you'll have to # modify it to not use /sys +# $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" @@ -87,6 +96,12 @@ case "$1" in *) 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 "