From c51414257e6d91861bb1830c9d7c9fd9042fdb02 Mon Sep 17 00:00:00 2001 From: Maarten van Gompel Date: Mon, 15 Mar 2021 13:11:41 +0100 Subject: [PATCH] changed sxmo-pinephone openrc script to be device-agnostic and invoke a sxmo-setpermissions.sh instead #169 --- Makefile | 2 +- configs/openrc/sxmo-pinephone | 6 ------ configs/openrc/sxmo-setpermissions | 5 +++++ scripts/core/sxmo_setpermissions.sh | 30 +++++++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 7 deletions(-) delete mode 100644 configs/openrc/sxmo-pinephone create mode 100644 configs/openrc/sxmo-setpermissions create mode 100755 scripts/core/sxmo_setpermissions.sh diff --git a/Makefile b/Makefile index 63b9553..3564d12 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ install: $(PROGRAMS) cd configs && find . -type f -exec install -D -m 0644 "{}" "$(DESTDIR)$(PREFIX)/share/sxmo/{}" \; && cd .. # Configs - install -D -m 0755 -t $(DESTDIR)/etc/init.d configs/openrc/sxmo-pinephone + install -D -m 0755 -t $(DESTDIR)/etc/init.d configs/openrc/sxmo-setpermissions install -D -m 0644 -t $(DESTDIR)/etc/alsa/conf.d/ configs/alsa/alsa_sxmo_enable_dmix.conf diff --git a/configs/openrc/sxmo-pinephone b/configs/openrc/sxmo-pinephone deleted file mode 100644 index f6d68f3..0000000 --- a/configs/openrc/sxmo-pinephone +++ /dev/null @@ -1,6 +0,0 @@ -#!/sbin/openrc-run - -description="Enable user access to pinephone hardware kernel interface" - -command="chmod" -command_args="a+rw /sys/module/8723cs/parameters/rtw_scan_interval_thr /sys/power/state /sys/devices/platform/soc/1f00000.rtc/power/wakeup /sys/power/mem_sleep /sys/bus/usb/drivers/usb/unbind /sys/bus/usb/drivers/usb/bind /dev/rtc0 /sys/devices/platform/soc/1f03400.rsb/sunxi-rsb-3a3/axp221-pek/power/wakeup /sys/class/wakeup/*" diff --git a/configs/openrc/sxmo-setpermissions b/configs/openrc/sxmo-setpermissions new file mode 100644 index 0000000..b46aa45 --- /dev/null +++ b/configs/openrc/sxmo-setpermissions @@ -0,0 +1,5 @@ +#!/sbin/openrc-run + +description="Set user permissions to aspects of the hardware kernel interface" + +command="/usr/bin/sxmo_setpermissions.sh" diff --git a/scripts/core/sxmo_setpermissions.sh b/scripts/core/sxmo_setpermissions.sh new file mode 100755 index 0000000..6d30f75 --- /dev/null +++ b/scripts/core/sxmo_setpermissions.sh @@ -0,0 +1,30 @@ +#!/usr/bin/env sh + +# This script is executed as root +# from the init process and sets +# some device-specific permissions + +DEVICE="unknown" + +#Detecting device +if [ -e /sys/firmware/devicetree/base ]; then + if grep -q pinephone compatible; then + DEVICE="pinephone" + fi +fi + +pinephone_files="/sys/module/8723cs/parameters/rtw_scan_interval_thr /sys/power/state /sys/devices/platform/soc/1f00000.rtc/power/wakeup /sys/power/mem_sleep /sys/bus/usb/drivers/usb/unbind /sys/bus/usb/drivers/usb/bind /dev/rtc0 /sys/devices/platform/soc/1f03400.rsb/sunxi-rsb-3a3/axp221-pek/power/wakeup" + +if [ "$DEVICE" = "pinephone" ]; then + files="$pinephone_files" +else + #guess a few that are hopefully fairly generic: + files="/sys/power/state /sys/power/mem_sleep /sys/bus/usb/drivers/usb/unbind /sys/bus/usb/drivers/usb/bind /dev/rtc0" + echo "Warning: SXMO is running on an unknown device, things may not work as expected!">&2 +fi + +for file in $files; do + [ -e "$file" ] && chmod a+rw "$file" +done + +chmod a+rw /sys/class/wakeup/*