commit 2c83fd2738335161f5bb45a6dda9e72034333c6d
parent e88aef5553dccb0685ad0a0cdaadac7a15805f90
Author: Cem Keylan <cem@ckyln.com>
Date: Mon, 3 Feb 2020 12:15:35 +0300
add nap-hooks
Diffstat:
3 files changed, 62 insertions(+), 1 deletion(-)
diff --git a/README b/README
@@ -20,7 +20,7 @@ there is only one but I will be publishing others.
nap
---
-Literally Leah's zzz with only suspend feature.
+Literally Leah's zzz[1] with only suspend feature.
It is compatible with zzz so it can read zzz.d
Why don't I add hybernation stuff? Because my
computer cannot hybernate.
@@ -35,3 +35,25 @@ To install run, as root if necessary
This will create the /etc/zzz.d directories and
install nap
+
+
+nap-hooks
+---------
+
+POSIX-compliant and simplified zzz-user-hooks[2].
+Does not support Wayland. Works with sbase-ubase.
+Is a shell script instead of a bash script. 32
+lines of shell code instead of 112.
+
+To install run, as root if necessary
+
+ make -C nap-hooks install
+
+This will create /etc/zzz.d/resume/99-onresume and
+/etc/zzz.d/suspend/99-onsuspend
+
+You can add user hooks to ~/.onsuspend and
+~/.onresume to get them working.
+
+[1]: http://git.vuxu.org/runit-void/tree/zzz
+[2]: https://github.com/bahamas10/zzz-user-hooks
diff --git a/nap-hooks/Makefile b/nap-hooks/Makefile
@@ -0,0 +1,7 @@
+install:
+ install -Dm755 user-hooks ${DESTDIR}/etc/zzz.d/resume/99-onresume
+ install -Dm755 user-hooks ${DESTDIR}/etc/zzz.d/suspend/99-onsuspend
+
+uninstall:
+ rm -f ${DESTDIR}/etc/zzz.d/resume/99-onresume \
+ ${DESTDIR}/etc/zzz.d/suspend/99-onsuspend
diff --git a/nap-hooks/user-hooks b/nap-hooks/user-hooks
@@ -0,0 +1,32 @@
+#!/usr/bin/env sh
+
+# POSIX compliant version of Dave Eddy's
+# zzz-user hooks.
+
+out() { printf '\033[1;36m-> \033[m%s\n' "$@" ;}
+error() { printf '\033[1;31m-> \033[mError: %s\n' "$@" >&2 ;}
+die() { error "$1" ; exit 1 ;}
+
+for sock in /tmp/.X11-unix/X* ; do
+ uid=$(stat -t "$sock" | cut -d ' ' -f 6)
+ user="$(grep ":$uid:" /etc/passwd | cut -d ':' -f 1)"
+ [ "$user" ] || die "User of $sock could not be found"
+ display=${sock##*/}
+ display=":${display#X}"
+done
+
+home="$(grep ":$uid:" /etc/passwd | cut -d ':' -f 6 )"
+[ "$home" ] && [ -d "$home" ] || die "Could not find user's home directory"
+env="DISPLAY=$display"
+[ -e "$home/.Xauthority" ] && env="$env XAUTHORITY=$home/.Xauthority" || error "Could not find user's Xauthority file"
+
+case ${0##*/} in
+ 99-onresume)
+ out "On resume"
+ su -c "$env $home/.onresume" "$user"
+ ;;
+ 99-onsuspend)
+ out "On suspend"
+ su -c "$env $home/.onsuspend" "$user"
+ ;;
+esac