~mil/sxmo-devel

sxmo-utils: sxmo_run_periodically.sh: improvement v1 APPLIED

This relies on the previous patchset that implements sxmo_sleep.
#1214380 test.yml success
sxmo-utils/patches/test.yml: SUCCESS in 23s

[sxmo_run_periodically.sh: improvement][0] from [Willow Barraco][1]

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

✓ #1214380 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1214380
I've also applied this one.

To be noted that the patches also include a breaking change on
sxmo_wakelock.sh, because it moves the "locking awake" behavior to a
separate script.
Export patchset (mbox)
How do I use this?

Copy & paste the following snippet into your terminal to import this patchset into git:

curl -s https://lists.sr.ht/~mil/sxmo-devel/patches/51660/mbox | git am -3
Learn more about email & git

[PATCH sxmo-utils 1/2] sxmo_run_periodically.sh: rework argument parsing Export this patch

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
---
 configs/default_hooks/sxmo_hook_screenoff.sh |  3 +-
 scripts/core/sxmo_run_periodically.sh        | 35 ++++++++++++++++----
 2 files changed, 31 insertions(+), 7 deletions(-)

diff --git a/configs/default_hooks/sxmo_hook_screenoff.sh b/configs/default_hooks/sxmo_hook_screenoff.sh
index d222cdca..7b14820b 100755
--- a/configs/default_hooks/sxmo_hook_screenoff.sh
+++ b/configs/default_hooks/sxmo_hook_screenoff.sh
@@ -23,7 +23,8 @@ sxmo_wm.sh dpms on
sxmo_wm.sh inputevent touchscreen off

if [ -e "$XDG_CACHE_HOME"/sxmo/sxmo.nosuspend ]; then
	sxmo_jobs.sh start periodic_blink sxmo_run_periodically.sh - 2 sxmo_led.sh blink red blue
	sxmo_jobs.sh start periodic_blink \
		sxmo_run_periodically.sh -w 2 -- sxmo_led.sh blink red blue
fi

case "$SXMO_WM" in
diff --git a/scripts/core/sxmo_run_periodically.sh b/scripts/core/sxmo_run_periodically.sh
index 2ded8a80..84bbc16a 100755
--- a/scripts/core/sxmo_run_periodically.sh
+++ b/scripts/core/sxmo_run_periodically.sh
@@ -2,13 +2,36 @@
# SPDX-License-Identifier: AGPL-3.0-only
# Copyright 2022 Sxmo Contributors

if [ "$1" = "-" ]; then
	waitfirst=1
	shift
fi
usage() {
	cat <<-EOF >&2
		Usage: $(basename "$0") [-w] <timeout> [--] <cmd...>
	EOF
	exit 1
}

timeout="$1"
shift
while [ -n "$*" ]; do
	case "$1" in
		"--")
			shift
			break;
			;;
		"-w")
			waitfirst=1
			shift
			;;
		*)
			if [ -n "$timeout" ]; then
				break;
			fi
			timeout="$1"
			shift
			;;
	esac
done

if [ -z "$timeout" ] || [ -z "$*" ]; then
	usage
fi

finish() {
	[ -n "$CMDPID" ] && kill "$CMDPID"
-- 
2.45.0

[PATCH sxmo-utils 2/2] sxmo_run_periodically.sh: let user choose the clockid Export this patch

This relies on the previous patchset that implement sxmo_sleep. It
become possible for the user to write a simple daemon that trigger
a command periodically, and waking up the device.

Signed-off-by: Willow Barraco <contact@willowbarraco.fr>
---
 scripts/core/sxmo_run_periodically.sh | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/scripts/core/sxmo_run_periodically.sh b/scripts/core/sxmo_run_periodically.sh
index 84bbc16a..f8233900 100755
--- a/scripts/core/sxmo_run_periodically.sh
+++ b/scripts/core/sxmo_run_periodically.sh
@@ -4,7 +4,7 @@

usage() {
	cat <<-EOF >&2
		Usage: $(basename "$0") [-w] <timeout> [--] <cmd...>
		Usage: $(basename "$0") [-w] [-c <clock-name>] <timeout> [--] <cmd...>
	EOF
	exit 1
}
@@ -19,6 +19,10 @@ while [ -n "$*" ]; do
			waitfirst=1
			shift
			;;
		"-c")
			clockname="$2"
			shift 2
			;;
		*)
			if [ -n "$timeout" ]; then
				break;
@@ -42,7 +46,7 @@ finish() {
trap 'finish' TERM INT

if [ -n "$waitfirst" ]; then
	sleep "$timeout" &
	sxmo_sleep ${clockname:+-c $clockname} "$timeout" &
	SLEEPPID="$!"
	wait "$SLEEPPID"
	unset SLEEPPID
@@ -54,7 +58,7 @@ while : ; do
	wait "$CMDPID"
	unset CMDPID

	sleep "$timeout" &
	sxmo_sleep ${clockname:+-c $clockname} "$timeout" &
	SLEEPPID="$!"
	wait "$SLEEPPID"
	unset SLEEPPID
-- 
2.45.0
sxmo-utils/patches/test.yml: SUCCESS in 23s

[sxmo_run_periodically.sh: improvement][0] from [Willow Barraco][1]

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

✓ #1214380 SUCCESS sxmo-utils/patches/test.yml https://builds.sr.ht/~mil/job/1214380
I've also applied this one.

To be noted that the patches also include a breaking change on
sxmo_wakelock.sh, because it moves the "locking awake" behavior to a
separate script.