Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Locked thread
MrDeSaussure
Jul 20, 2008
I'm finishing up a Raspberry Pi box for a good friend of mine.

I've installed Raspbian Jessie, and installed the ONLY program that I want it to run. Nethack.

This works fine, I got the controls and things hooked up how I/he wants it.

My only problem is, I cannot for the life of me figure out how to get it to boot directly into Nethack without having to go through a login prompt, or enter the "nethack" command to start the game. I want this to feel like a "console" version of nethack. Power it on, and in less than 10 seconds, you are at the prompt to play.

Any input would be VERY appreciated, and I'd totally be good with throwing a few bucks at you.

Adbot
ADBOT LOVES YOU

CaptainSarcastic
Jul 6, 2013



There should be a display manager that brings up the login prompt, and it should be possible to set it to auto-login the default user. I'm used to using KDM for KDE, and haven't used the distro you are working with specifically.

Assuming it hits a desktop then it should be possible to set Nethack to autostart using the session manager.

telcoM
Mar 21, 2009
Fallen Rib

MrDeSaussure posted:

I'm finishing up a Raspberry Pi box for a good friend of mine.

I've installed Raspbian Jessie, and installed the ONLY program that I want it to run. Nethack.

This works fine, I got the controls and things hooked up how I/he wants it.

This will be one of these things that is actually fairly simple to do, but explaining it will be a huge wall of text.

I assume you've already done something similar to:
code:
$ sudo update-alternatives --config nethack
and selected "nethack-x11.sh" to make the plain "nethack" command
always start the graphical version. If not, substitute your preferred
nethack start command to "nethack" in the nethack-forever script below.

First, to prevent the default "pi" user from easily undoing our work,
we want to make our changes to system-wide settings, which requires being root.
So use "sudo -i" to become root.

We will need a script that keeps restarting nethack forever. That's easy.
code:
# nano /usr/local/bin/nethack-forever
Type in the following script:
code:
#!/bin/sh
while true
do
    nethack
done
To exit the "nano" editor, press Ctrl-X, then answer Y to the
"Save your changes?" question, and just press enter to accept the original
filename. (Remember this. We will be using nano several more times.)

Make the script executable:
code:
# chmod a+x /usr/local/bin/nethack-forever
Now, we want to have that script run when the default user "pi" logs in graphically, and we want to remove all other functions from the user interface.

First, a little bit of background:
The component that is responsible for the actual graphical X11 logins is called "display manager", as it also restarts the display server if it dies for any reason. In Raspbian Jessie, the display manager is specified by file /etc/X11/default-display-manager. By default, it is set to "/usr/sbin/lightdm", and lightdm is already configured to auto-login the default user named "pi".

The actual login session is handled by a "session manager", which is essentially just a process (or a series of processes) started by the display manager and running as the appropriate user. Once the session manager process dies, the display manager will reset the display server and prepare for a next login. In Raspbian Jessie, the default session manager is /usr/bin/x-session-manager, which is a symlink to /etc/alternatives/x-session-manager, which is a symlink to /usr/sbin/startlxde-pi, which is a script that will prepare the environment and then start the actual session manager process.

(The symlinks are part of the so-called "alternatives system": Debian and Raspbian includes several programs that can be used as X11 session managers, and /usr/bin/x-session-manager is the Debian standard name for starting up the system default X11 session manager. The /etc/alternatives/x-session-manager symlink can be changed by the sysadmin to specify the desired default session manager program... the users can optionally override the default using another mechanism if the sysadmin has not forbidden that.)

The important part of the /usr/sbin/startlxde-pi script is the last line:
code:
# Start the LXDE session
exec /usr/bin/lxsession -s LXDE-pi -e LXDE
The option "-s LXDE-pi" sounds like it tells the session manager to run a specific type of session.

Now, where would those be defined?
code:
# find / -name '*LXDE-pi*'
/etc/xdg/lxpanel/profile/LXDE-pi
/etc/xdg/pcmanfm/LXDE-pi
/etc/xdg/lxsession/LXDE-pi
Aha! /etc/xdg/lxsession/LXDE-pi seems to be related to the lxsession, and the other two are easily explained by checking their man pages: "lxpanel" is the menu at the top of the screen, and "pcmanfm" is the file manager - i.e. responsible for things like the trashcan icon on the desktop. So, the plan is to disable both of them.

Turns out /etc/xdg/lxsession/LXDE-pi is a directory, which contains three things:
  • autokey.sh, which is a script. That's nice to know: we can make our session execute scripts by just plopping them here.
  • autostart: This does not exactly look like a shell script, more like just a list of commands to run for the session. It includes three things:
    - @lxpanel --profile LXDE-pi
    - @pcmanfm --desktop --profile LXDE-pi
    - @xscreensaver -no-splash
  • desktop.conf, which seems to be the main session configuration file.

Cool, by removing or commenting out lxpanel and pcmanfm from autostart, we should remove all the desktop icons and the top menu. We can also remove the screensaver here if we want; it's actually a matter of preference.

But by pressing the right mouse button on empty desktop background, there is a menu that allows starting a web browser or a terminal. We need to disable those too.
After a bit of googling, grepping and experimentation, it turns out this menu is defined in file /etc/xdg/openbox/menu.xml. Edit it so that it contains only the following:
code:
<?xml version="1.0" encoding="UTF-8"?>

<openbox_menu xmlns="http://openbox.org/"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://openbox.org/
                file:///usr/share/openbox/menu.xsd">

<menu id="root-menu" label="Openbox 3">
  <item label="Restart">
    <action name="Restart" />
  </item>
  <separator />
  <item label="Exit">
    <action name="Exit" />
  </item>
</menu>

</openbox_menu>
We can make our own custom session definition, so that updates won't overwrite our settings. (Too bad I could not figure out how to do that for the menu.xml too)
Let's do that:
code:
# cd /etc/xdg/lxsession
# cp -r LXDE-pi LXDE-nethack
# cd LXDE-nethack
# nano autostart
Remove the @lxpanel... and @pcmanfm... lines from here.
As the last (or only, if you remove the screensaver line too) line, write:
code:
@/usr/local/bin/nethack-forever
Now we have our custom configuration, but how to activate it?

/usr/bin/startlxde-pi was the "keystone" of the session. Let's make a copy of it, and modify it a little:
code:
# cp /usr/bin/startlxde-pi /usr/local/bin/startlxde-nethack
# nano /usr/local/bin/startlxde-nethack
Change the last two lines to:
code:
# Start a custom LXDE session that runs only Nethack
exec /usr/bin/lxsession -s LXDE-nethack -e LXDE
Now, let's add our custom session as the highest-priority alternative for x-session-manager:
code:
# update-alternatives --verbose --install /usr/bin/x-session/manager x-session-manager /usr/local/bin/startlxde-nethack 4000
You can verify that it's set with "update-alternatives --display x-session-manager" and, if necessary, switch back and forth with this configuration and the normal behavior with "update-alternatives --config x-session-manager".

And that's it!

If you run into trouble, you can press Ctrl-Alt-F1 to get a text-mode shell session, which you can use to fix any typos you might have made.
If NetHack keeps dying and restarting continuously, you might want to take a look at /home/pi/.xsession-errors and /home/pi/.cache/lxsession/LXDE-nethack/run.log: any error messages from GUI programs run by the "pi" user will go into either of those files.

  • Locked thread