Okay yeppers here we go again, this one goes out to @CwF and right now inclined to think his username stands for
Come-on-man
w-haaaaa de-
F**k ..
Anyway, you-@CwF introduced an interesting idea in a trainwreck of a how-to exchange. The autologin + startx without a display manager madness. That being I hadn't considered that it could be used in the way he applied it, logging in multiple users on different tty's(gettys.) automatically. Do think it's a cool idea and so started dorking around and here's some of the results of said dorking ...
I switched over myself to the full method employed in the Gentoo wiki, works great, not that it's technically superior in any way to how it's advised in the Archwiki, nor the bastardized version of the topic I put up originally, which was a mixture of ripping off the Gentoo wiki and some snagged and tested line to automatically startx in .profile. Did so mostly to be different. From everything I've ever seen and have played with all of them, all work fine, can even mix + match the things, all accomplish the same thing. Autologin/startx no display manager.
At this point ... then thought while I'm being different why not endeavor to be even more different. Removed the line to startx from my users .profile file and cooked this nonsense up. Created a script in my usual preferred place, which is still /home/myusername/.bin/startx.sh , yep ... named it startx.sh. Make the thing executable with the usual "chmod +x startx.sh" and here's the contents of it.
Code: Select all
#!/bin/bash
echo
echo
read -n1 -p " To startx press 1 or any key to continue with command-line session. " XORG
if [[ $XORG =~ ^[1]$ ]]; then
[ "$(tty)" = "/dev/tty1" ] && exec startx
fi
echo
echo
Note: The above there is for tty1, if you were trying to autologin your user or other user accts you've setup on different/other tty's on your system, then yes ... change that as needed.
Added this line to the .profile file in my users home directory. To run a script when my user is logged into the OS. Just add it to the bottom of the file or you can wedge it in somewhere else, really doesn't matter as long as you don't screw up any of the other contents of the file, kay ? Don't copy and paste pieces over other crap in the file, delete stuff from it etc so forth. Anyway added the below to .profile.
Code: Select all
# Running a script at user login.
/home/myusername/.bin/startx.sh # That's the path to the dang script.
Which is what this does, when I boot-up the OS, my user is automatically logged into tty1 and when the .profile file gets sourced it runs that script. What it does is show me that dialogue in the script, the Press 1 to startx etc etc. If I press the number 1 key, that's what it does, starts Openbox for me, if I press any other key, keeps going in a command-line session, at any point I could just type "startx" to launch Openbox or another windows manager or desktop etc. So I got this all setup, rebooted and joy to the world, was greeted with my script asking me to press 1 if I wanted to startx, which I did, Openbox fired up and thought okay, now were/I'm getting somewhere, heel yeah! Opened a terminal typed "openbox --exit" to kill the X session and ? Nope, normal user prompt, because it's not a damn login shell, my wonderous bashy goodness didn't run and at this point decided screw this, it's time to whip out the big hammer.
Created a script at the following location, do this as root or with sudo privileges and I named it logout.sh, /usr/local/bin/logout.sh and added it to a file I have in /etc/sudoers.d/myfile I've discussed this before, very likely in this thread if not in one of the other monsters so not covering it again. If anyone is left with any doubts do not hesitate to enlist the help of google on the topic of how to add a script to a file in sudoers.d so that someone can run sudo commands + scripts-etc with sudo commands without having to enter a password.
That's what I did, in the file I added the path to the script /usr/local/bin/logout.sh at that point I can run that script using "sudo /usr/local/bin/logout.sh" in keybinds, panel launchers, terminals, menu entries etc etc without having to enter a password. Here's the contents of the logout.sh script.
Code: Select all
#!/bin/bash
pkill -KILL -u myusername
What the above does is kill off my user, smashes all processes, logs my user off and because things are setup to automatically log my user into that tty = tty1 here, as described in either of the autologin/startx no display manager how-to's found in tips/tricks section, my user is re-logged back into tty1 and I'm greeted with a fresh login shell and my beautiful scripty friend asking me to press 1 for X or any key for etc. In my case I'm using the windows manager Openbox and so added a custom keybind(key-combo)to run the script when pressed. Any and every Desktop or WM on planet earth should have an easy way to define custom keyboard shortcuts = keybinds, as noted using "sudo /usr/local/bin/logout.sh" in plenty of other stuff or all of them can also be used to run the script too, no password necessary. Here's the Openbox rc.xml file entry I'm using to run the script, when I press Alt + F9.
Code: Select all
<keybind key="A-F9">
<action name="Execute">
<startupnotify>
<enabled>true</enabled>
<name>force-logout</name>
</startupnotify>
<command>sudo /usr/local/bin/logout.sh</command>
</action>
</keybind>
So basically I've taken the automatically startx part out of things, clearly very simple to put it back, in my case I'll just remove the comments = # these things from in front of the lines to startx in the .profile file in users /home. Pretty much all this was done for the heel of it and think it's pretty cool, shrugs. Not much difference, if I want to log into a graphical desktop-etc I have to press one key at boot and there you have it folks.
FOOTNOTES: Other observations about this, if you did have it setup so that your or whatever other users are automatically logged into whichever tty's on the system, going further ... If you wanted to have a bunch of GUI apps run when that user starts X. Could just add those as .desktop files (in @CwF's case he's wanting to launch web-browser), could also run additional scripts this way too or by adding whatever apps or scripts you want to run when user starts X in Openbox or Fluxbox's autostart files. Other desktops should have similar functionality but what's outlined ... using .desktop files would work fine too. In others words just using the same methods to autostart or run stuff as a person would in any graphical session.
Another dorkish thing was thinking on this. If someone were going for super-secret, as follows but to me it looks ugly/sloppy. Just leaving the prompt empty, so someone only gets a flashing prompt. Rather than giving instructions on press this or that.
Code: Select all
#!/bin/bash
read -n1 -p " " XORG
if [[ $XORG =~ ^[1]$ ]]; then
[ "$(tty)" = "/dev/tty1" ] && exec startx
fi