sxmo: inline the sxmo_suspend.sh script

this is exactly how it presently appears upstream (less shebang/comment changes)
This commit is contained in:
Colin 2023-10-08 01:57:01 +00:00
parent b6d2fbdf6d
commit 47e23c1ff3
2 changed files with 45 additions and 0 deletions

View File

@ -87,6 +87,11 @@ let
src = ./hooks;
pkgs = [ "superd" "xdg-user-dirs" ];
};
suspend = pkgs.static-nix-shell.mkBash {
pname = "sxmo_suspend.sh";
src = ./hooks;
pkgs = [ "coreutils" "util-linux" ];
};
};
in
{
@ -176,6 +181,7 @@ in
"sxmo_hook_postwake.sh" = "${hookPkgs.postwake}/bin/sxmo_hook_postwake.sh";
"sxmo_hook_rotate.sh" = "${hookPkgs.rotate}/bin/sxmo_hook_rotate.sh";
"sxmo_hook_start.sh" = "${hookPkgs.start}/bin/sxmo_hook_start.sh";
"sxmo_suspend.sh" = "${hookPkgs.suspend}/bin/sxmo_suspend.sh";
};
description = ''
extra hooks to add with higher priority than the builtins

View File

@ -0,0 +1,39 @@
#!/usr/bin/env nix-shell
#!nix-shell -i bash -p coreutils -p util-linux
# yeah, this isn't technically a hook, but the hook infrastructure isn't actually
# restricted to stuff that starts with sxmo_hook_ ...
#
# this script is only called by sxmo_autosuspend, which is small, so if i wanted to
# be more proper i could instead re-implement autosuspend + integrations.
. sxmo_common.sh
sxmo_log "going to suspend to crust"
YEARS8_TO_SEC=268435455
suspend_time=99999999 # far away
mnc="$(sxmo_hook_mnc.sh)"
if [ -n "$mnc" ] && [ "$mnc" -gt 0 ] && [ "$mnc" -lt "$YEARS8_TO_SEC" ]; then
if [ "$mnc" -le 15 ]; then # cronjob imminent
sxmo_wakelock.sh lock sxmo_waiting_cronjob infinite
exit 1
else
suspend_time=$((mnc - 10))
fi
fi
sxmo_log "calling suspend with suspend_time <$suspend_time>"
start="$(date "+%s")"
rtcwake -m mem -s "$suspend_time" || exit 1
#We woke up again
time_spent="$(( $(date "+%s") - start ))"
if [ "$((time_spent + 15))" -ge "$suspend_time" ]; then
sxmo_wakelock.sh lock sxmo_waiting_cronjob infinite
fi
sxmo_hook_postwake.sh