diff options
-rw-r--r-- | Makefile | 4 | ||||
-rwxr-xr-x | zzz | 62 | ||||
-rw-r--r-- | zzz.8 | 88 |
3 files changed, 154 insertions, 0 deletions
diff --git a/Makefile b/Makefile index f4e15f7..532622c 100644 --- a/Makefile +++ b/Makefile @@ -12,10 +12,14 @@ install: install -m755 pause ${DESTDIR}/${PREFIX}/bin install -m755 suspend ${DESTDIR}/${PREFIX}/bin install -m755 shutdown.sh ${DESTDIR}/${PREFIX}/bin/shutdown + install -m755 zzz ${DESTDIR}/${PREFIX}/bin + ln -s zzz ${DESTDIR}/${PREFIX}/bin/ZZZ ln -s halt ${DESTDIR}/${PREFIX}/bin/poweroff ln -s halt ${DESTDIR}/${PREFIX}/bin/reboot install -d ${DESTDIR}/${PREFIX}/share/man/man1 install -m644 pause.1 ${DESTDIR}/${PREFIX}/share/man/man1 + install -d ${DESTDIR}/${PREFIX}/share/man/man8 + install -m644 zzz.8 ${DESTDIR}/${PREFIX}/share/man/man8 install -d ${DESTDIR}/etc/sv install -d ${DESTDIR}/etc/runit/runsvdir install -m755 ${SCRIPTS} ${DESTDIR}/etc/runit diff --git a/zzz b/zzz new file mode 100755 index 0000000..ead0051 --- /dev/null +++ b/zzz @@ -0,0 +1,62 @@ +#!/bin/sh +# zzz - really simple suspend script + +USAGE="Usage: ${0##*/} [-nSzZR] + -n dry run (sleep for 5s instead of suspend/hibernate) + -S Low-power idle (ACPI S0) + -z suspend to RAM (ACPI S3) [DEFAULT for zzz(8)] + -Z hibernate to disk & power off (ACPI S4) [DEFAULT for ZZZ(8)] + -R hibernate to disk & reboot" + +fail() { echo ${0##*/}: 1>&2 "$*"; exit 1; } + +export ZZZ_MODE=suspend +export ZZZ_HIBERNATE_MODE=platform + +case "$0" in + *ZZZ) ZZZ_MODE=hibernate;; +esac + +while getopts hnSzRZ: opt; do + case "$opt" in + n) ZZZ_MODE=noop;; + S) ZZZ_MODE=standby;; + z) ZZZ_MODE=suspend;; + Z) ZZZ_MODE=hibernate;; + R) ZZZ_MODE=hibernate; ZZZ_HIBERNATE_MODE=reboot;; + [h?]) fail "$USAGE";; + esac +done +shift $((OPTIND-1)) + +case "$ZZZ_MODE" in + suspend) grep -q mem /sys/power/state || fail "suspend not supported";; + hibernate) grep -q disk /sys/power/state || fail "hibernate not supported";; +esac + +test -w /sys/power/state || fail "sleep permission denied" + +( +flock -n 9 || fail "another instance of zzz is running" + +echo -n "Zzzz... " + +for hook in /etc/zzz.d/suspend/*; do + [ -x "$hook" ] && "$hook" +done + +case "$ZZZ_MODE" in + standby) echo -n freeze >/sys/power/state || fail "standby failed";; + suspend) echo -n mem >/sys/power/state || fail "suspend failed";; + hibernate) + echo $ZZZ_HIBERNATE_MODE >/sys/power/disk + echo -n disk >/sys/power/state || fail "hibernate failed";; + noop) sleep 5;; +esac + +for hook in /etc/zzz.d/resume/*; do + [ -x "$hook" ] && "$hook" +done + +echo "yawn." +) 9</sys/power diff --git a/zzz.8 b/zzz.8 new file mode 100644 index 0000000..e3fc5af --- /dev/null +++ b/zzz.8 @@ -0,0 +1,88 @@ +.Dd July 25, 2014 +.Dt ZZZ 8 +.Os Linux +.Sh NAME +.Nm zzz , +.Nm ZZZ +.Nd suspend or hibernate your computer +.Sh SYNOPSIS +.Nm zzz +.Op Fl nSzZR +.Nm ZZZ +.Op Fl nSzZR +.Sh DESCRIPTION +.Nm +is a simple script to suspend or hibernate your computer. +It supports hooks before and after suspending. +.Bl -tag -width indent +.It Fl n +dry-run mode. Instead of performing an ACPI action, +.Nm +will just sleep for a few seconds. +.It Fl S +Enter low-power idle mode (ACPI S0, kernel name "freeze"). +.It Fl z +Enter suspend to RAM mode (ACPI S3, kernel name "mem"). +This is the default for +.Nm zzz . +.It Fl Z +Enter hibernate to disk mode (ACPI S4, kernel name "disk") and power off. +This is the default for +.Nm ZZZ . +.It Fl R +Enter hibernate to disk mode and reboot. This can be used to switch +operating systems. +.El +.Sh FILES +Before suspending, +.Nm zzz +runs the executable files in +.Pa /etc/zzz.d/suspend +in alphanumeric order. +After suspending, +.Nm zzz +runs the executable files in +.Pa /etc/zzz.d/resume +in alphanumeric order (not in reverse order!). +.Pp +The environment variable +.Ev ZZZ_MODE +can be used in these hooks to differentiate between +.Ic standby , +.Ic suspend , +and +.Ic resume . +.Sh DIAGNOSTICS +.Bl -tag -width indent +.It suspend/hibernate not supported +The hardware does not support ACPI S3/S4 with this kernel. +.It sleep permission denied +You lack sufficent privilege to write to +.Pa /sys/power/state . +.It another instance of zzz is running +.Nm +locks +.Pa /sys/power +during operation. Perhaps a hook is stuck? +.It Zzzz... yawn. +The system has woken up again. Everything is fine. +You feel refreshed. +.Sh SEE ALSO +.Xr s2ram 8 , +.Xr s2disk 8 , +.Xr pm-action 8 , +OpenBSD's +.Xr apm 8 +.Sh HISTORY +A similar +.Nm apm +command appeared in +.Nx 1.3 +and +.Ox 1.2 . +.Sh AUTHOR +.An Christian Neukirchen , +.Mt chneukirchen@gmail.com . +.Sh LICENSE +.Nm +is in the public domain. |