On Thu, Apr 27, 2017 at 9:27 PM, Felix Dietrich <
felix.dietr...@sperrhaken.name> wrote:

> Kent West <we...@acu.edu> writes:
>
> > On Wed, Apr 26, 2017 at 4:52 PM, Kent West <we...@acu.edu> wrote:
> >     I've got 90% of it done, but I need it to logout after a certain
> >     time of inactivity, but only after the computer has been used at
> >     least once since the last start of X (otherwise it'll just be in a
> >     slow loop of restarting X).
> >
> >     - boot into X
> >     - sit idly for 20 minutes, 2 hours, 3 days, whatever, screensaver
> >       running, until a guest comes up and uses the kiosk
>
> Do you mean the display manager is running waiting for a user to log in,
> possibly allowing a passwordless guest login?


No. There is no login manager; the system boots straight into X, and fires
up Firefox to its home page, and then waits for a passerby to come use it
to web-browse.


> Upon login the display
> manager executes an initialisation script, possibly .xinitrc.  In this
> script you can set up the kiosk session:
>
>     - start the program/script that will forcibly log the user out once
>       a certain time has passed.
>     - start a program/script to monitor the xscreensavers state
>     - start some basic programs (window manager, panels) so that a user
>       can actually do something
>     - whatever else you can think of
>

Yes. This is exactly what I have done. What I needed (and have since solved
- below) was help working out the syntax of determining human interaction
with X.


>
> You may also want to consider that a user probably should not be able to
> edit the initialisation script (xinitrc) or kill the program/script that
> will exit the session automatically after a certain time has passed.
>

In my current setup, the current user can do either of these things, but
not permanently; his changes are lost upon a restart of X, so the changing
of .xinitrc is a non-issue. The ability to kill the script that will exit
the session automatically after a certain time is a bit more of an issue,
but not enough in my situation to warrant overthinking it at this time.
Meh, compromise.


>
> When using a display manager the FRESH_X variable might not be
> necessary.
>
> > In my .xinitrc, I have
> >
> > export FRESH_X=TRUE
> >
> > Then I want to have a script that sits and waits for a keypress or a
> > mouse activity; this is where I need the syntax help.
>
> When you refer to "script" do you mean a separate script file that you
> call or simply more commands following the shells "export" command?
>
> > When that script sees keyboard or mouse activity, it will export
> > FRESH_X=FALSE
>
> In case you are talking of a script file you run (instead of source [1])
> be aware that the value of environment variables is not shared among
> processes: a parent process can pass environment variables to a child
> process on execution, but once the child exists both parent and child
> have their own copy of the environment.
>

Yeah, this is part of what I was running into. But my solution turned out
to be exceptionally easy (it just took me 30 hours of tinkering to figure
it out, pfft).

>
>
>
> > But I need help with the syntax of checking for a keypress or mouse
> > activity. I've looked at xinput and xev and another tool something
> > like xenv, but I can't figure out the syntax in a bash if/then
> > statement.
>
> The following snipped can be used to block further script execution
> until xinput reports an event.  It reads lines from xinput until it
> encounters a line starting with "EVENT" using, instead of the "if"
> statement, the "case" statement [2] , which supports a simple form of
> pattern matching.
>
>     xinput --test-xi2 --root | while read line
>     do
>         case $line in
>         EVENT*)
>                 break
>                 ;;
>         esac
>     done
>


The problem is that xinput reports several EVENTs on startup of the
utility, so I had to figure out a way to do finer-grained testing. My
solution is below.


>
> > I'll configure the xscreensaver-command --watch to watch for the
> > screen saver to go BLANK, and when it does I check the status of
> > FRESH_X ; if FRESH_X is FALSE, and the screensaver activates, I can
> > set a 10-second time, check again to make sure the screensaver is
> > still active, and then run my logout.
>
> Searching the web, I found the xautolock [3] program.  You may be able
> to use its "-killer", "-killtime", "-locker", "-time" parameters to
> realise your kiosk idea and save you some scripting.
>
>

Had I seen this earlier, I would have looked into xautolock. But as it is,
here's my solution:

My kiosk user's .xinitrc:

=============
# Start watching for human interaction with this machine
/home/kiosk/bin/wipe_profile.sh &

 # Start xfce4
xfce4-session &

 # Start Firefox Extended Support Release; quit X when it quits
/usr/bin/firefox-esr
=============


And my wipe_profile.sh script (minus comments):

=============
kioskdir=/home/kiosk/
backupdir=/opt/kiosk/

rsync -a --delete $backupdir $homedir

xinput test-xi2 --root | egrep -q "EVENT type 2|EVENT type 6"

while true; do
 if [ "`xscreensaver-command -time | egrep -o '
blanked|non-blanked|locked'`" = " blanked" ];
 then # The screensaver is active; let's give the user 10 seconds to respond
       sleep 10
       if [ "`xscreensaver-command -time | egrep -o '
blanked|non-blanked|locked'`" = " blanked" ];
       then # The screensaver is still active; let's restart X.
#               echo RESTARTING X
               pkill -u kiosk
       fi
 fi
 sleep 1
done
=============

For comments and a full break-down of the entire process (minus printing to
Pharos/Uniprint, which I still have to solve), see

http://goshen.acu.edu/westk/DEBIAN-KIOSK/DebianKiosk.html


Happy hacking. :)
>

Thank you. It has been fun, and frustrating, too.



Footnotes:
[1] https://www.gnu.org/software/bash/manual/html_node/Bash-
Builtins.html#index-source

[2] https://www.gnu.org/software/bash/manual/html_node/
Conditional-Constructs.html#index-case

[3] https://packages.debian.org/jessie/xautolock

--
Felix Dietrich




-- 
Kent West                    <")))><
Westing Peacefully - http://kentwest.blogspot.com

Reply via email to