~mil/sxmo-devel

This thread contains a patchset. You're looking at the original emails, but you may wish to use the patch review UI. Review patch
3 3

[PATCH sxmo-utils] sxmo_led.sh switch to brightnessctl

Details
Message ID
<20230829185706.30016-2-contact@willowbarraco.fr>
DKIM signature
pass
Download raw message
Patch: +4 -43
Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
---
 scripts/core/sxmo_led.sh                      | 34 +++----------------
 scripts/deviceprofiles/README.md              |  8 -----
 .../sxmo_deviceprofile_longcheer,l8150.sh     |  1 -
 .../sxmo_deviceprofile_purism,librem5r4.sh    |  4 ---
 4 files changed, 4 insertions(+), 43 deletions(-)

diff --git a/scripts/core/sxmo_led.sh b/scripts/core/sxmo_led.sh
index 82ee540..d39db1d 100755
--- a/scripts/core/sxmo_led.sh
+++ b/scripts/core/sxmo_led.sh
@@ -5,22 +5,6 @@
# shellcheck source=scripts/core/sxmo_common.sh
. sxmo_common.sh

get_type() {
	# Get type from variable name created dynamically from the color,
	# e.g. $SXMO_LED_RED_TYPE
	eval type='$'SXMO_LED_"$(echo "$1" | tr '[:lower:]' '[:upper:]')"_TYPE

	# Defaults
	if [ -z "$type" ]; then
		case $1 in
			red|green|blue) type="indicator" ;;
			white) type="flash" ;;
		esac
	fi

	printf %s "$type"
}

get_led() {
	color="$1"

@@ -30,10 +14,9 @@ get_led() {
	}
	[ $# -lt 1 ] && usage

	type="$(get_type "$color")";

	value="$(cat "/sys/class/leds/$color:$type/brightness")"
	max="$(cat "/sys/class/leds/$color:$type/max_brightness")"
	# need brightnessctl release after 0.5.1 to have --percentage
	value="$(brightnessctl -d "$color:*" get)"
	max="$(brightnessctl -d "$color:*" max)"
	printf "scale=0; %s / %s * 100\n" "$value" "$max" | bc -l
}

@@ -47,16 +30,7 @@ set_led() {
	color="$1"
	percent="$2"

	type="$(get_type "$color")";

	if [ ! -d "/sys/class/leds/$color:$type" ]; then
		echo "LED does not exist: /sys/class/leds/$color:$type"
		exit 1
	fi

	max="$(cat "/sys/class/leds/$color:$type/max_brightness")"
	brightness="$(echo "($percent / 100.0) * $max" | bc -l)"
	printf "%0.f\n" "$brightness" > "/sys/class/leds/$color:$type/brightness"
	brightnessctl -q -d "$color:*" set "$percent%"
}

set_leds() {
diff --git a/scripts/deviceprofiles/README.md b/scripts/deviceprofiles/README.md
index 116fdc7..4abbce2 100644
--- a/scripts/deviceprofiles/README.md
+++ b/scripts/deviceprofiles/README.md
@@ -52,14 +52,6 @@ ### Screen-related

SXMO_DISABLE_LEDS		| Disable leds (1 or 0) [default: 0]

SXMO_LED_WHITE_TYPE		| LED device type, i.e., the part after the colon in the path: `/sys/class/leds/<color>:<type>` [default: status]

SXMO_LED_BLUE_TYPE		| LED device type, i.e., the part after the colon in the path: `/sys/class/leds/<color>:<type>` [default: status]

SXMO_LED_RED_TYPE		| LED device type, i.e., the part after the colon in the path: `/sys/class/leds/<color>:<type>` [default: status]

SXMO_LED_GREEN_TYPE		| LED device type, i.e., the part after the colon in the path: `/sys/class/leds/<color>:<type>` [default: status]

SXMO_SWAY_SCALE		| Screen scale for hidpi screens. Can be fractional [SWAY-ONLY].

### Music-related
diff --git a/scripts/deviceprofiles/sxmo_deviceprofile_longcheer,l8150.sh b/scripts/deviceprofiles/sxmo_deviceprofile_longcheer,l8150.sh
index 246070e..2765d1c 100755
--- a/scripts/deviceprofiles/sxmo_deviceprofile_longcheer,l8150.sh
+++ b/scripts/deviceprofiles/sxmo_deviceprofile_longcheer,l8150.sh
@@ -8,6 +8,5 @@ export SXMO_POWER_BUTTON="0:0:pm8941_pwrkey"
export SXMO_VOLUME_BUTTON="1:1:GPIO_Buttons 0:0:pm8941_resin"
export SXMO_ROTATION_GRAVITY="500"
export SXMO_ROTATION_THRESHOLD="60"
export SXMO_LED_WHITE_TYPE="kbd_backlight"
export SXMO_SYS_FILES="/sys/power/state /sys/power/mem_sleep /dev/rtc0"
export SXMO_SWAY_SCALE="2"
diff --git a/scripts/deviceprofiles/sxmo_deviceprofile_purism,librem5r4.sh b/scripts/deviceprofiles/sxmo_deviceprofile_purism,librem5r4.sh
index cfc11e6..feed0ae 100755
--- a/scripts/deviceprofiles/sxmo_deviceprofile_purism,librem5r4.sh
+++ b/scripts/deviceprofiles/sxmo_deviceprofile_purism,librem5r4.sh
@@ -5,10 +5,6 @@
export SXMO_SPEAKER="Speaker"
export SXMO_HEADPHONE="Headphone"
export SXMO_EARPIECE="Earpiece"
export SXMO_LED_RED_TYPE="status"
export SXMO_LED_GREEN_TYPE="status"
export SXMO_LED_BLUE_TYPE="status"
export SXMO_LED_WHITE_TYPE="torch"
export SXMO_SYS_FILES="/sys/power/state /sys/power/mem_sleep /dev/rtc0"
export SXMO_POWER_BUTTON="0:0:30370000.snvs:snvs-powerkey"
export SXMO_VOLUME_BUTTON="1:1:gpio-keys"
-- 
2.42.0

[sxmo-utils/patches/test.yml] build success

builds.sr.ht <builds@sr.ht>
Details
Message ID
<CV59BW5RMKMF.19Y3V5TVXISH0@cirno2>
In-Reply-To
<20230829185706.30016-2-contact@willowbarraco.fr> (view parent)
DKIM signature
missing
Download raw message
sxmo-utils/patches/test.yml: SUCCESS in 46s

[sxmo_led.sh switch to brightnessctl][0] from [Willow Barraco][1]

[0]: https://lists.sr.ht/~mil/sxmo-devel/patches/44136
[1]: contact@willowbarraco.fr

✓ #1049596 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1049596
Details
Message ID
<87il8jsr6y.fsf@momi.ca>
In-Reply-To
<20230829185706.30016-2-contact@willowbarraco.fr> (view parent)
DKIM signature
pass
Download raw message
Hi!

I like how much this simplifies our shell script. However, this patch
also adds one more dependency.

I would be willing to merge this if:

1. We can support rgb multi-intensity devices via brightnessctl https://lists.sr.ht/~mil/sxmo-devel/patches/44149
2.  We can fix https://gitlab.com/postmarketOS/pmbootstrap/-/issues/2257

I think we can fix 2 if we use Ellie's suggestion from that issue:

> I guess an alternate approach would be to use setuid and make sure it
> runs as its own user that is in the input group, even when launched by
> someone who doesn't have these permissions. That might be easier to
> implement, and sufficient if it doesn't need concurrent use and the
> complexity of dbus. Although then I guess it would need to be safe to
> launch it twice at once since unprivileged users could then just do
> that, I'm not familiar enough with the kernel device stuff to know if
> that would be safe to allow.

And brightnessctl readme says:

> Modifying brightness requires write permissions for device files or
> systemd support. brightnessctl accomplishes this (without using
> sudo/su/etc.) by either of the following means:
>
> 1. installing relevant udev rules to add permissions to backlight
> class devices for users in video and leds for users in input. (done by
> default)
> 2. installing brightnessctl as a suid binary.
> 3. using the systemd-logind API.


I dont want to deal with feedbackd issues going forward and this seems
like a simple enough solution.

Let me know what you think.

Thank you!
Anjandev
--
w:] www.momi.ca
pgp:] https://momi.ca/publickey.txt
Details
Message ID
<CWBFAOMGQY0G.2NEGTREPPBAFG@willowbarraco.fr>
In-Reply-To
<20230829185706.30016-2-contact@willowbarraco.fr> (view parent)
DKIM signature
pass
Download raw message
Applied!
Reply to thread Export thread (mbox)