WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: PS1 prompter colour, from /etc/.profile is not used properly.  (Read 3233 times)

Offline nick65go

  • Hero Member
  • *****
  • Posts: 799
PS1 prompter colour, from /etc/.profile is not used properly.
« on: August 11, 2020, 04:38:05 PM »
this piece of code, from /etc/.profile is not used properly.
Code: [Select]
# Prompt format for Ash (Bash use /etc/bashrc).
#
if [ "`id -u`" -eq 0 ]; then
    # Light red and blue colored prompt.
    #PS1='\e[1;31m\u@\h\e[0m:\e[1;34m\w\e[0m\# '
     PS1='\u@\h:\w\# '
else
    # Light green and blue colored prompt.
     PS1='\e[1;32m\u@\h\e[0m:\e[1;34m\w\e[0m\$ '
    #PS1='\u@\h:\w\$ '
fi


the colors (red for root, green for tc user) are not shown in aterm, neither in real terminal/console (Alt+F1). because the /etc/skel/.profile will overwrite them with simple code
Code: [Select]
# Environment variables and prompt for Ash SHell
# or Bash. Default is a classic prompt.
#
PS1='\u@\h:\w\$ '
export PS1

Maybe for tc user is better to have directly in /etc/skel/.profile
Code: [Select]
# Light green and blue colored prompt.
PS1='\e[1;32m\u@\h\e[0m:\e[1;34m\w\e[0m\$ '


Also, I can not activate the red color root-user. Using "sudo su" will not help. I can not login as root (by default), because /etc/passwrd

I can leave without these nice colors. But the idea is about the audit of TC script code.

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #1 on: August 11, 2020, 11:53:15 PM »
I think we can leave those in, they can be examples.

Thanks for looking over the scripts.
The only barriers that can stop you are the ones you create yourself.

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11178
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #2 on: August 12, 2020, 06:06:52 AM »
Hi nick65go
...  because the /etc/skel/.profile will overwrite them with simple code ...
User configuration settings are supposed to override system wide settings. That allows users to configure their preferences.

Quote
... Also, I can not activate the red color root-user. Using "sudo su" will not help. I can not login as root (by default), because /etc/passwrd ...
Did you try modifying the  /root/.profile  file? You will also need to backup  /root  if you make changes to it.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 799
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #3 on: August 12, 2020, 09:27:31 AM »
Hi Rich,I know that /home/.profile will take precedence over /etc/profile; and if I change something in /home/tc then I would need to backup it etc. I just highlighted that the code in /etc/.profile is NEVER used for prompter color. That code section can be deleted (curaga advised me that it can stay, as demo).

Also, I manually add a line in /root/.profile as
Code: [Select]
tc@box:~$ cat /root/.profile
#!/bin/sh
PS1='\e[1;31m\u@\h\e[0m:\e[1;34m\w\e[0m\# '
but the problem is (as I said it previously) that I can not login as root user. I tried to add a password to user root. It complaint that I need a strong one, so I chose one as "ABC123456789!" (with out " ")
Code: [Select]
tc@box:~$ sudo su
root@box:/home/tc# passwd
Changing password for root
New password:
Retype password:
passwd: password for root changed by root
root@box:/home/tc# exit
tc@box:~$ login
box login: root
Login incorrect
box login: ^C
tc@box:~$

I think it is because something/somewhere not allow me as user root, just sudo su:
Code: [Select]
tc@box:~$ sudo su
root@box:/home/tc# cat /etc/passwd
root:x:0:0:root:/root:/bin/sh
lp:x:7:7:lp:/var/spool/lpd:/bin/sh
nobody:x:65534:65534:nobody:/nonexistent:/bin/false
tc:x:1001:50:Linux User,,,:/home/tc:/bin/sh
root@box:/home/tc#
root@box:/home/tc# cat /etc/shadow
root:$1$fXlnzkxU$li.1CDsMnFto.iMldZZNy1:18486:0:99999:7:::
lp:*:13510:0:99999:7:::
nobody:*:13509:0:99999:7:::
tc::13646:0:99999:7:::
root@box:/home/tc#

PS: in aterm says "login incorrect"; but in real console (crt+alt+f1) it accepts the password but instantly switch back to tc user.All was done live, no backup for /root, I just test from Xorg+flwm+aterm.

UPDATES: deleted everything from /root/.profile (keep just row with PS1); and now I can login from console (ctlr+alt+f1) with red color.But from Xorg (back with ctrl+alt+f2) still login error. I will exit from Xorg (crtl+alt+backspace) and come back here to report again.
« Last Edit: August 12, 2020, 09:50:39 AM by nick65go »

Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #4 on: August 12, 2020, 09:50:33 AM »
Check root's files in /root. It redirects to user tc on purpose, for the boot autologin.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 799
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #5 on: August 12, 2020, 09:59:09 AM »
@curaga: correct! so I delete all from /root/.profile (keep just row with PS1). yes, I know it is crazy, just for testing. With this new  /root/.profile I can login as root, and stay as root (red prompter), in console. Then from console I login as tc user, so I arrived in Xorg automatically. now in aterm as tc user I try login as root, and
Code: [Select]
tc@box:~$ login root
Login incorrect
box login:
box login: ^C
tc@box:~$


Offline curaga

  • Administrator
  • Hero Member
  • *****
  • Posts: 10957
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #6 on: August 12, 2020, 11:27:15 PM »
I don't think login is intended to work at a terminal like that. "su - root" Switches User to - login shell for root.
The only barriers that can stop you are the ones you create yourself.

Offline nick65go

  • Hero Member
  • *****
  • Posts: 799
Re: PS1 prompter colour, from /etc/.profile is not used properly.
« Reply #7 on: August 15, 2020, 02:51:54 PM »
finally i managed, to log as tc user (green) and as user root (red).

So, 3 small things should be updated in /etc/profile:
1. proper comment of # Light red (not green) and blue colored prompt.
2. activate (uncoment) first PS1 line
3. comment out second PS1 line.
Code: [Select]
# Prompt format for Ash (Bash use /etc/bashrc).
if [ "`id -u`" -eq 0 ]; then
    # Light red and blue colored prompt.
    PS1='\e[1;31m\u@\h\e[0m:\e[1;34m\w\e[0m\# '
     #PS1='\u@\h:\w\# '

2 things in /home/$user/.profile:
1. comment out first PS1 line.
2. activate /insert second  PS1 line
Code: [Select]
# Environment variables and prompt for Ash SHell or Bash. Default is a classic prompt.
# PS1='\u@\h:\w\$ '
PS1='\e[1;32m\u@\h\e[0m:\e[1;34m\w\e[0m\$ '

for ~/.profile is no problem, because it can be saved in mydata.gz
but for /etc/profile, maybe a remaster is in need. or else boot parameters "nologin +superuser" (aka root) has no red color, because /etc/profile is sourced imediatly after /init, no chance to be (eventually) restored from mydata.gz also. I did a remaster and is working.

Regarding login as root, staring as tc-user in a aterm-shell in Xorg, is OK. (my mistake, sorry).
The proper command I should issue is:
Code: [Select]
tc@box:~$ sudo login -f root
   ( '>')
  /) TC (\   Core is distributed with ABSOLUTELY NO WARRANTY.
 (/-_--_-\)           www.tinycorelinux.net

root@box:~#
PS: neither tc-user, nor root-user need a password, it works without both passwords.
« Last Edit: August 15, 2020, 03:15:18 PM by nick65go »