Solved Calling 'startx' in .shrc - FreeBSD 11.1

TheUser

New Member

Thanks: 1
Messages: 4

#1
Hi!
I read the forum permanently, and I was able to configure autologin via reading responses to another user in this post:
https://forums.freebsd.org/threads/trouble-calling-startx-in-start-up-script.22304/#post-125992

Now after booting process my normal account is logged ok, but I need a .shrc working variant of this piece of code:

/home/usr/.cshrc

Code:
# WB: startx if it isn't already running
set XPID = `/usr/bin/pgrep xinit`
if ( { [ -n "$XPID" ] } ) then
  #echo "X is already running"
else
  startx
  logout
endif
Thanks!

Edit:
I found a solution: https://forums.freebsd.org/threads/calling-startx-in-shrc-freebsd-11-1.64866/#post-379885
 
Last edited:

thebardian

Member

Thanks: 26
Messages: 26

#3
This is what I use in bash and zsh, don't know if it helps, but ... ¯\_(ツ)_/¯

Code:
# auto startx
if [ `/usr/bin/tty` = '/dev/ttyv0' ]; then
startx &
fi
 
Last edited:
OP
OP
TheUser

TheUser

New Member

Thanks: 1
Messages: 4

#4
This is what I use in bash and zsh, don't know if it helps, but ... ¯\_(ツ)_/¯

Code:
# auto startx
if [ '/usr/bin/tty' = '/dev/ttyv0' ]; then
startx &
fi
Thanks for your answer! , I don't understand why your code does not work (my autologin is ok in /dev/ttyv0), if I set only
Code:
startx
in /home/usr/.shrc without a conditional check "if", this works ok but when a terminal is opened my X server restart. (obviously).

I've tried with this variation of code but I get the same result when a terminal is opened, the X server restarts:

Code:
set XPID = `/usr/bin/pgrep xinit`
if [ -n "$XPID" ]; then
  #echo "X is already running"
else
  startx
  logout
fi
 

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,346
Messages: 27,540

#6
Sure, but now you have to hack the auto-login functionality. If you install SLiM it's just a simple configuration change and you're done.
 

Sensucht94

Well-Known Member

Thanks: 327
Messages: 347

#7
Because I want to do it without install any display manager or extra packages, I only use openbox. :)
You can always attempt compiling/porting cdm, it's really nice and represents closest thing I think of to what you're looking for.

As for adding a startx-based script in .profile or shell's conf, I've done so in the past, but then I realised that the moment I've typed username and password, further typing 'startx' requires around 0.5'' ;)
 

SirDice

Administrator
Staff member
Administrator
Moderator

Thanks: 6,346
Messages: 27,540

#8
This:
Code:
if [ '/usr/bin/tty' = '/dev/ttyv0' ]; then
Appears to be a copy/paste problem, the first command /usr/bin/tty should be enclosed in backticks (`), not single quotes ('). Now it's just comparing two strings that are never the same and the test always evaluates to false. It should compare the output of the /usr/bin/tty command with the string /dev/ttyv0. Something has gone lost in translation ;)
Code:
if [ `/usr/bin/tty` = '/dev/ttyv0' ]; then
 

phoenix

Administrator
Staff member
Administrator
Moderator

Thanks: 1,165
Messages: 3,988

#9
This is one reason I really like the $( ) syntax over ` ` syntax for "execute this command and use the output as the value". Too many fonts make ` and ' look the same. And using " " for text strings.

Code:
if [ $( /usr/bin/tty ) = "/dev/ttyv0" ]; then
So much easier to read and understand. ;)
 
OP
OP
TheUser

TheUser

New Member

Thanks: 1
Messages: 4

#10
Hi again, phoenix SirDice :

I've been reading a lot about scripting since my last posting in the forum and I tried this simple script and it works. (It was so simple and I did not imagine it). I found the solution to auto startx at boot via .shrc - bourne shell startup file, autologin shell works perfect with this reference: https://forums.freebsd.org/threads/trouble-calling-startx-in-start-up-script.22304/#post-125992

put this code at the end of your .shrc file /home/yourusername/.shrc

Code:
r=`top | grep Xorg`
if [ "$r" ]; then
    echo "Xorg is already running."
else
    echo "Xorg is not running."
    startx &
fi
Now when I turn on the pc this boot ok, auto-log in shell ok, auto start X server ok, and the script prevent Xorg restart if I open a terminal.

Sure, but now you have to hack the auto-login functionality. If you install SLiM it's just a simple configuration change and you're done.
not needed! :D

It works with my normal user too.

Thanks to all!
 
Top