HOW TO INVOKE ZZZ WITHOUT SUDO
       
       
       
       
       Notice
       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       Update: <2023-09-11 Mon 21:38>
       
       The method originally outlined in this article ("Learning to sleep")
       for invoking `zzz' without `sudo' is flawed. Because the `/sys/'
       folder is regenerate each boot, the group and permission modifications
       not persist through a reboot cycle. This is a lesson learned for me,
       and another interesting detail about Linux uncovered.
       
       A better way of making `zzz' easier to invoke (still with sudo,
       inevitably) is by adding your user to the `wheel' group and modifying
       `/etc/sudoers' to allow `wheel' group members to execute commands
       without a password.
       
       ,----
       | usermod -aG wheel roygbyte
       | ed /etc/sudoers
       | > 83
       | > s/#//
       | > wq
       | # For those not using ed(1): remove # from line that reads
       | # `#%wheel ALL=(ALL:ALL) NOPASSWD: ALL`
       `----
       
       You can test this by logging into a new shell or logging in/out of
       your X session.
       
       Adding an alias to `.bashrc' would make it possible to at least hide
       the use of `sudo', if that's still desired.
       
       ,----
       | alias zzz='sudo zzz'
       `----
       
       Easier still is to add a key binding to `/.config/i3/config' to sleep
       the computer while while in `i3':
       
       ,----
       | bindsym $mod+Shift+l exec sudo zzz
       `----
       
       
       Learning to sleep
       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       As mentioned above, this method doesn't work. I'm keeping it up
       anyways.
       
       `zzz' is a clever program for putting your computer to sleep. It has a
       cute name, a nice man page with descriptions of various computer sleep
       states, and straight forward error reporting. It was available to me
       out-of-the-box on Void, although I didn't find out about it right
       away.
       
       Before I started using `zzz', I would put my computer to sleep by
       writing directly to `/sys/power/state'. For instance:
       
       ,----
       | $ sudo echo -n disk > /sys/power/state
       `----
       
       Though arduous, learning this sequence of commands let me better
       understand how `/sys' files represent different parts of the computer,
       how writing to these files can cause certain things to happen, and how
       reading from these files can provide information about the system.
       
       Soon enough I needed a faster way to put my computer to sleep. I
       learned about `zzz' through a search or maybe the Void
       documentation. (I don't remember). I started using it right
       away. Immediately I got an error:
       
       ,----
       | $ zzz
       | zzz: sleep permission denied
       | # Error explained in man page: "You lack sufficent privilege to write to /sys/power/state."
       `----
       
       I got around this by invoking `zzz' using `sudo'. But typing my
       password in each time I wanted my computer to snooze became
       irritating. I figured there must be a better way!
       
       I'd been reading a bit about SysV during this time. Something must
       have clicked because I realized I could probably change the ownership
       permissions of the file in such a way that my account would be able to
       invoke `zzz' without `sudo'.
       
       On a lark, I started fooling around to see how to do this. First, I
       `ll''d the file in question, revealing `root:root' ownership and
       `rw-r--r--' permissions. That would explain the requirement for
       `sudo'. Next I looked into `/etc/groups' to see if there were any
       system-y type groups I could use in lieu of `root' for the file. I
       didn't find any, so I decided I'd create one called `sys'. I'd use
       this group to extend permissions for files in `/sys/*', starting with
       `power/state' and including other files over time as need be. Then it
       was a simple matter of invoking `chmod', `chown', and `usermod' to put
       everything together. See the next section for a step-by-step how-to.
       
       
       How-to
       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       Here's how I made `zzz' available to my user without having to invoke
       `sudo'.
       
       Frist, create a new group called `sys'. (You could use any group name,
       of course. `cis', `cyst', and `sis' are all great alternatives.)
       
       ,----
       | $ groupadd sys
       `----
       
       Add your user account into the group.
       
       ,----
       | $ usermod -aG sys roygbyte
       `----
       
       Change the group for `/sys/power/state'.
       
       ,----
       | $ chown :sys /sys/power/state
       `----
       
       Adjust the permissions of `/sys/power/state', adding write permissions
       for the `sys' group.
       
       ,----
       | $ chmod g+w /sys/power/state
       `----
       
       You should now have something like this:
       
       ,----
       | -rw-rw-r-- 1 root sys 4096 Aug 30 08:30 /sys/power/state
       `----
       
       You can test it worked by logging into a new shell.
       
       ,----
       | $ su roygbyte
       | $ groups
       | > roygbyte : roygbyte sys ...
       | $ zzz
       `----
       
       For the new group to be available in all existing logged in shells you
       must exit and log back into your session.
       
       That's it.
       
       Happy computer dreaming!
       
       
       Adding hooks
       ----------------------------------------------------------------------
       Hooks run as user
       zzz-user-hooks pxkg
       
       
       Colophon
       ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
       I was inspired to write this post by Solene, whose gopher hole
       includes lots of little computer hints and tutorials. Indeed--no bit
       of computer how-do'er-y is too small to be worth writing about!
       
       Thanks to feranur, luca, ahesford, from libera#voidlinux for improving
       this teeny article with suggestions, grammar-checks, and alternative
       approaches.