su - -c mc not respecting custom root prompt anymore...

This forum is dedicated to basic help and support :

Ask here your questions about basic installation and usage of Mageia. For example you may post here all your questions about getting Mageia isos and installing it, configuring your printer, using your word processor etc.

Try to ask your questions in the right sub-forum with as much details as you can gather. the more precise the question will be, the more likely you are to get a useful answer

su - -c mc not respecting custom root prompt anymore...

Postby jtwdyp » Sep 21st, '13, 08:35

I've been using "konsole -e" to open an konsole window to a password protected root mc shell for years. Usually with a keybinding.

But something changed with my mageia application of this.

It was my understanding that the option "-" in the su command
Code: Select all
su - -c mc

was supposed to simulate a login shell which would should, amongst other things, result in my custom root $PS1 prompt being used.

But while this works that way with my other distros, and I think used to work on Mageia:

Code: Select all
JtWdyP -> ~
> konsole -e su - "-c mc"
JtWdyP -> ~
>


It no longer respects the $PS1 var exported from my root .bashrc on mageia.

Since I use that prompt as a visual cue that the shell involved had root permissions. {Which reminds me NOT to use it for regular user commands...} I had to resort to this form:

Code: Select all
JtWdyP -> ~
> konsole -e su - "-c /root/bin/medosumcFIX"
JtWdyP -> ~
> X Error: BadWindow (invalid Window parameter) 3
  Major opcode: 20 (X_GetProperty)
  Resource id:  0x1e00017
X Error: BadWindow (invalid Window parameter) 3
  Major opcode: 20 (X_GetProperty)
  Resource id:  0x1e00017

JtWdyP -> ~
>


Where the file "/root/bin/medosumcFIX" is a copy of the part of root's .bashrc from which the $PS1 var was already exported...

That worked! Though when I closed the resulting root "mc" shell {and it's konsole session terminated} The shell from which I called it, displayed an error??

My question is: Is there some new security policy in mageia that prevents the "su - -c mc" form from honoring the custom PS1 prompt? And if so, why???

I note that the custom PS1 prompt is respected if instead, I simply use:

Code: Select all
JtWdyP -> ~
> konsole -e su -
JtWdyP -> ~
>


But I explicitly use mc, because I tweaked my root's mc configs to use a distinctive background color that works even better than the PS1 prompt at reminding me that it's a root shell (unless, of course, I hit ^O and toggle to the large command window where the prompt is my only clue...
--
JtWdyP
User avatar
jtwdyp
 
Posts: 88
Joined: Jun 10th, '13, 08:30

Re: su - -c mc not respecting custom root prompt anymore...

Postby djennings » Sep 22nd, '13, 12:44

The only thing that has changed recently is that when starting a shell from within mc the commands in /etc/mc/mc-bashrc are executed so that the HISTCONTROL environment variable can be correctly set See Bug 1304 https://bugs.mageia.org/show_bug.cgi?id=1304

If you wished you could set your PS1 variable in there, or you could drop a file in /etc/profile.d
User avatar
djennings
 
Posts: 613
Joined: Jun 2nd, '11, 23:51
Location: Wokingham, UK

Re: su - -c mc not respecting custom root prompt anymore...

Postby jtwdyp » Sep 30th, '13, 10:38

djennings wrote:The only thing that has changed recently is that when starting a shell from within mc the commands in /etc/mc/mc-bashrc are executed so that the HISTCONTROL environment variable can be correctly set


Thanks for the info. Though I'm still somewhat confused... It dosen't happen if I type bash on mc's command line. It doesn't happen if I open a konsole, (with or without su) Then start mc after the konsole is initialized.

It DOES happen if the call to initialize mc is preceded by an "su - " or "sudo -i" command in the same cli string such as any of these:
Code: Select all
xterm -e su - -c mc
su - -c "konsole -e mc"
su - -c mc
sudo -i mc


All of which are supposed to emulate a login shell, right?

If you wished you could set your PS1 variable in there, or you could drop a file in /etc/profile.d


Except of course that the whole point was that my root prompt is distinctly different in appearance from my user prompt. And I think setting PS1 in /etc/mc/mc-bashrc or /etc/profile.d would also affect my normal users prompt??

That's a moot point though as my script does get the job done...
--
JtWdyP
User avatar
jtwdyp
 
Posts: 88
Joined: Jun 10th, '13, 08:30

Re: su - -c mc not respecting custom root prompt anymore...

Postby doktor5000 » Sep 30th, '13, 20:27

Why not simply install colorprompt? Does the job fine, green prompt for users, red prompt for root, and easy to install:
urpmi colorprompt
Cauldron is not for the faint of heart!
Caution: Hot, bubbling magic inside. May explode or cook your kittens!
----
Disclaimer: Beware of allergic reactions in answer to unconstructive complaint-type posts
User avatar
doktor5000
 
Posts: 18066
Joined: Jun 4th, '11, 10:10
Location: Leipzig, Germany

Re: su - -c mc not respecting custom root prompt anymore...

Postby jtwdyp » Oct 1st, '13, 17:17

to be sure, My root prompt does use color...
The pertinant part is set thus:
Code: Select all
#set prompt color blue, PWD, color reset, newline
#then set color black background with red distinctive text string, another color reset, and "=-> "
export PS1='\[\033[01;34m\] \w \[\033[00m\]
\[\033[40;01;31m\]UnderTree\[\033[00m\]=-> '


And as long as I'm doing that, I'm also fixing my custom $PATH so that root's bin scripts don't require absolute pathnames...
Code: Select all
/root/bin1st:/usr/local/sbin:/usr/sbin:/usr/local/bin:/usr/bin:/usr/lib64/qt4/bin:/root/bin2nd:/root/bin
--
JtWdyP
User avatar
jtwdyp
 
Posts: 88
Joined: Jun 10th, '13, 08:30

Re: su - -c mc not respecting custom root prompt anymore...

Postby piomiq2 » Sep 22nd, '14, 23:31

Hi

I was struggling also with properly running mc as root from konsole. I found some work around on this issue.
I'm starting mc in this way:
Code: Select all
su -c mc

I've fixed: /etc/mc/mc-bashrc in this way:
Code: Select all
#. /etc/bashrc
. $HOME/.bashrc


In every .bashrc located at home directories for every users (including root) I have such code:
Code: Select all
# Source global definitions
if [ -f /etc/bashrc ]; then
    . /etc/bashrc
fi


Thanks that main bashrc is everytime loaded when I start mc session in konsole.
Before this change .bashrc located in home directory didn't load.
piomiq2
 
Posts: 1
Joined: Sep 22nd, '14, 23:13


Return to Basic support

Who is online

Users browsing this forum: No registered users and 1 guest