Happier with kdesudo

Duncan 1i5t5.duncan at cox.net
Wed Jan 9 14:26:44 GMT 2013


Duncan posted on Wed, 09 Jan 2013 11:55:17 +0000 as excerpted:

>>> My suspend/hibernate solution is something I scripted myself,
>> 
>> I may be interested in that, if it's little trouble.
> 
> I'll followup with an explanation and attach it.

Keep in mind that I wrote this for me, then generalized it a bit, set
it up to use a config file, etc.  However, I've only run it here so
I've not actually tested the generalization beyond my own two machines
(netbook and workstation), and in any case, it is still designed with
gentoo in mind, so assumes things like self-compiled kernels that have
the suspend-to partition already set (and no initrd), that gentoo's
openrc is the init system in use (in particular, it's NOT systemd
ready, tho that bit can be simply ignored, as it's an option that
doesn't have to be enabled), etc.

That said, as the script is much shorter than the general suspend
script many distros package (and that's available from
suspend.sourceforge.net ) and is reasonably well commented, it should
be a reasonable start, easier to modify than to start from scratch, for
someone looking to write their own script, or useful for those simply
wanting to have something to compare against the big long general
purpose script in the above package, and possibly use as a pattern for
their own, learning from both.

As I mentioned in the above post, the idea is to put the script itself 
somewhere on your main partition, where it'll be accessible regardless
of what optional partitions you might have mounted.  However, it does
NOT need to be in your path, altho the access/execute (and possibly
SUID/SGID if you intend to run it directly as non-root, owner root, of
course) permissions should be set as appropriate.  Then, create
symlinks to it called s2standby, s2ram, s2disk, s2both, as desired, and
stick THEM in your path.  

Up near the top of the script, set the suspend.conf path to point to 
wherever you put that.  I'll attach my suspend.conf as well, but while 
it's commented, it's NOT generalized.  You'll need to change many of
the suspend.conf settings to something appropriate for your system.

If you set SUSP_VT to anything other than 0 (thus enabling that
feature), there are two arguably semi-exotic executables that the
script calls, fgconsole and chvt, at least here on gentoo, both part of
the kbd package.  The clear executable, from ncurses, is also used, but
ncurses is a pretty basic package so likely installed.  If these aren't 
available, you may need to install their package, or simply disable
(set to 0) that feature.  The in-script default is 0/disabled, but it
may be set in the config file.

The script also uses the "logger" executable, but that's part of the 
standard util-linux package, so chances are you have it installed.

Other than that, bash (the script specifically uses bashisms like [[ ]] 
tests, so a non-bash shell will likely have trouble with it, but it 
shebangs /bin/bash so...), and the swapon and swapoff commands (util-
linux), are used, but these are pretty standard so unlikely to be an 
issue.

One other possibly unusual bit to note:  The config file is actually 
simply sourced into the main script, so standard shell features may be 
used for a "dynamic" config.  As you'll not reading it, I've taken 
advantage of that here, to be able to use the same config file for both 
my (HOSTTYPE=x86_64) workstation, and my (32-bit-only-atom-based 
HOSTTYPE=i686) netbook, with slightly different settings for each and 
detection using the bash HOSTTYPE variable.  If you wanted, you could
do similar, keying if you wish on some other var, as long as it's set
in the environment that the script and thus the config file inherit.

Other than that, the script is pretty much just bash logic, with output 
to the appropriate /sys/power/* files to tell the kernel what to
suspend to, the size of the suspend image if it's written to disk, and
to trigger the actual suspend when it's time.  The /sys/power/* files
are all documented in the the various files in the kernel's
Documentation/power/ subdir, if you'd like to read them for yourself.
That's what I did, first writing a tiny script, that gradually grew,
but it's still way shorter and easier to hack on than the huge suspend
script at the link above, especially since I already had a working
script and basic understanding of how it worked, before I even looked
at the above (tho I did take a couple hints from it once I did look at
it, I think that's where I got the idea for the vt switch and
suspend/resume hooks, for instance).

OK, now to do the attachment dance and send...

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: suspend.conf
URL: <http://mail.kde.org/pipermail/kde/attachments/20130109/3a45c8de/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: suspend
URL: <http://mail.kde.org/pipermail/kde/attachments/20130109/3a45c8de/attachment-0001.ksh>
-------------- next part --------------
___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.


More information about the kde mailing list