[SOLVED] How to change $PATH with saving a new $PATH after reboot

Post here if you are a new Porteus member and you're looking for some help.
Post Reply
User avatar
Blaze
DEV Team
DEV Team
Posts: 1429
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus 3.2 Cinnamon x86_64
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

[SOLVED] How to change $PATH with saving a new $PATH after reboot

Post#1 by Blaze » 03 Sep 2017, 15:31

Anybody knows how to change $PATH with saving a new $PATH after reboot?

I need to change $PATH for root user (for this app), like this:

Code: Select all

root@porteus:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
root@porteus:~# export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
root@porteus:~# echo $PATH
/opt/cprocsp/bin/amd64:/opt/cprocsp/sbin/amd64:/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
root@porteus:~#
but after reboot or after closing the terminal window my $PATH is set by default

Code: Select all

root@porteus:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
root@porteus:~#
Linux porteus 4.13.3-porteus #1 SMP PREEMPT Sat Sep 23 18:22:13 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
fanthom
Site Admin
Site Admin
Posts: 4592
Joined: 28 Dec 2010, 02:42
Distribution: Porteus Kiosk
Location: Poland, currently - Cork, IE
Contact:

How to change $PATH with saving a new $PATH after reboot

Post#2 by fanthom » 03 Sep 2017, 17:19

You need to edit /etc/profile and save somewhere (rootcopy, module, changes, etc):

Code: Select all

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts"

# For root users, ensure that /usr/local/sbin, /usr/sbin, and /sbin are in
# the $PATH.  Some means of connection don't add these by default (sshd comes
# to mind).
if [ "`id -u`" = "0" ]; then
  echo $PATH | grep /usr/local/sbin 1> /dev/null 2> /dev/null
  if [ ! $? = 0 ]; then
    PATH=/usr/local/sbin:/usr/sbin:/sbin:$PATH
  fi
fi
Please add [Solved] to your thread title if the solution was found.

User avatar
Blaze
DEV Team
DEV Team
Posts: 1429
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus 3.2 Cinnamon x86_64
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

How to change $PATH with saving a new $PATH after reboot

Post#3 by Blaze » 04 Sep 2017, 16:52

Hi fanthom.
I added this code:

Code: Select all

if [ "$USER" != "root" ]; then
  export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
fi
to /etc/profile after your code. After reboot it changed $PATH for guest, but I need to do this only for root user

Code: Select all

guest@porteus:~$ echo $PATH
/opt/cprocsp/bin/amd64:/opt/cprocsp/sbin/amd64:/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts
guest@porteus:~$ su
root@porteus:/home/guest# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
root@porteus:/home/guest#
any suggestion are welcome. Thanks.
Linux porteus 4.13.3-porteus #1 SMP PREEMPT Sat Sep 23 18:22:13 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
Ed_P
Contributor
Contributor
Posts: 3214
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

How to change $PATH with saving a new $PATH after reboot

Post#4 by Ed_P » 04 Sep 2017, 17:07

Blaze wrote:
04 Sep 2017, 16:52
I added this code:

Code: Select all

if [ "$USER" != "root" ]; then
  export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
fi
Try

Code: Select all

if [ "$USER" == "root" ]; then
  export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
fi
Ed

User avatar
Blaze
DEV Team
DEV Team
Posts: 1429
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus 3.2 Cinnamon x86_64
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

How to change $PATH with saving a new $PATH after reboot

Post#5 by Blaze » 04 Sep 2017, 18:36

Hi Ed_P.
No result for both guest and root users

Code: Select all

guest@porteus:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts
guest@porteus:~$ su
Пароль: 
root@porteus:/home/guest# cd
root@porteus:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
root@porteus:~# 
Linux porteus 4.13.3-porteus #1 SMP PREEMPT Sat Sep 23 18:22:13 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
Ed_P
Contributor
Contributor
Posts: 3214
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

How to change $PATH with saving a new $PATH after reboot

Post#6 by Ed_P » 04 Sep 2017, 19:08

:oops:

Ok this is what I normally use to check for a non-root user: (from Re: Script help (Post by brokenman #20035))

Code: Select all

if [ `whoami` != "root" ]; then
So I think you should try:

Code: Select all

if [ `whoami` == "root" ]; then
This may work also:

Code: Select all

if [ "$UID" -eq 0 ]; then
but I haven't tested.

Before your "if" put these in your script:

Code: Select all

echo USER=$USER
echo whoami=`whoami`
echo UID=$UID
read
Press Enter after reviewing the display.


-update-

FYI

Code: Select all

guest@porteus:~$ echo $USER
guest
guest@porteus:~$ echo $UID
1000
guest@porteus:~$ echo `whoami`
guest
guest@porteus:~$ su
Password: 
root@porteus:/home/guest# echo $USER
root
root@porteus:/home/guest# echo $UID
0
root@porteus:/home/guest# echo `whoami`
root
root@porteus:/home/guest# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin:/usr/lib64/java/bin:/usr/lib64/qt/bin
root@porteus:/home/guest# exit
exit
guest@porteus:~$ echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts:/usr/lib64/java/bin:/usr/lib64/qt/bin:/usr/lib64/java/bin:/usr/lib64/qt/bin:/usr/lib64/java/bin:/usr/lib64/qt/bin
guest@porteus:~$ 
Ed

User avatar
Blaze
DEV Team
DEV Team
Posts: 1429
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus 3.2 Cinnamon x86_64
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

How to change $PATH with saving a new $PATH after reboot

Post#7 by Blaze » 05 Sep 2017, 17:56

With these lines

Code: Select all

if [ `whoami` != "root" ]; then
  export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
fi

if [ `whoami` == "root" ]; then
  export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
fi

if [ "$UID" -eq 0 ]; then
  export PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH"
fi

Code: Select all

guest@porteus:~$ echo $PATH
/opt/cprocsp/bin/amd64:/opt/cprocsp/sbin/amd64:/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts
guest@porteus:~$ su
Пароль: 
root@porteus:/home/guest# echo $PATH
/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
root@porteus:/home/guest# 
Ed_P wrote:
04 Sep 2017, 19:08
Before your "if" put these in your script:

echo USER=$USER
echo whoami=`whoami`
echo UID=$UID
read

Press Enter after reviewing the display.
This is freezes boot up and Xorg does not started.
I logged as root and via vi removed these lines.
Now with Xorg all ok.

-update-

I found it in /etc/login.defs

Code: Select all

#
# REQUIRED  The default PATH settings, for superuser and normal users.
#
# (they are minimal, add the rest in the shell startup files)
ENV_SUPATH     PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
ENV_PATH       PATH=/usr/local/bin:/bin:/usr/bin
NOTE.
for root user need to tweak /etc/login.defs

Code: Select all

ENV_SUPATH     PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
for guest user need to tweak /etc/profile

Code: Select all

# Set the default system $PATH:
PATH="/usr/local/bin:/usr/bin:/bin:/usr/games:/opt/porteus-scripts"
A new issue. How I can add output of this variable $(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')

Code: Select all

root@porteus:~# echo $(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')
/opt/cprocsp/bin/amd64:/opt/cprocsp/sbin/amd64:
root@porteus:~#
to ENV_SUPATH PATH=HERE/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
Linux porteus 4.13.3-porteus #1 SMP PREEMPT Sat Sep 23 18:22:13 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
Ed_P
Contributor
Contributor
Posts: 3214
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

How to change $PATH with saving a new $PATH after reboot

Post#8 by Ed_P » 05 Sep 2017, 22:52

I would think this would be worth a shot.

Code: Select all

sudo echo "ENV_SUPATH PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH >> /etc/login.defs
Or not.

Code: Select all

guest@porteus:~$ sudo echo "ENV_SUPATH PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH >> /etc/login.defs
/bin/ls: cannot access '/opt/cprocsp/sbin/*': No such file or directory
/bin/ls: cannot access '/opt/cprocsp/bin/*': No such file or directory
bash: /etc/login.defs: Permission denied
guest@porteus:~$ sudo echo "ENV_SUPATH PATH="`/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':'`$PATH >> /etc/login.defs
/bin/ls: cannot access '/opt/cprocsp/sbin/*': No such file or directory
/bin/ls: cannot access '/opt/cprocsp/bin/*': No such file or directory
bash: /etc/login.defs: Permission denied
guest@porteus:~$ 

Code: Select all

guest@porteus:~$ su
Password:
root@porteus:/home/guest# echo "ENV_SUPATH PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')$PATH >> /etc/login.defs
/bin/ls: cannot access '/opt/cprocsp/sbin/*': No such file or directory
/bin/ls: cannot access '/opt/cprocsp/bin/*': No such file or directory
root@porteus:/home/guest# 
File got updated

Code: Select all

ENV_SUPATH PATH=/usr/local/sbin:/usr/local/bin:/sbin:/usr/sbin:/bin:/usr/bin
but not with your change. :wall:
Ed

User avatar
Blaze
DEV Team
DEV Team
Posts: 1429
Joined: 28 Dec 2010, 11:31
Distribution: ⟰ Porteus 3.2 Cinnamon x86_64
Location: ☭ Russian Federation, Lipetsk region, Dankov
Contact:

How to change $PATH with saving a new $PATH after reboot

Post#9 by Blaze » 06 Sep 2017, 17:41

Ed_P, I love sed :magic:

Code: Select all

su
toor
sed -i "s|ENV_SUPATH     PATH=|ENV_SUPATH     PATH="$(/bin/ls -d /opt/cprocsp/{s,}bin/*|tr '\n' ':')"|g" /etc/login.defs
Note. About

Code: Select all

/bin/ls: cannot access '/opt/cprocsp/sbin/*': No such file or directory
/bin/ls: cannot access '/opt/cprocsp/bin/*': No such file or directory
you are need to activate this kc1 app
Linux porteus 4.13.3-porteus #1 SMP PREEMPT Sat Sep 23 18:22:13 x86_64 Intel(R) Core(TM) i5-6600K CPU @ 3.50GHz GenuineIntel GNU/Linux
MS-7A12 » [AMD/ATI] Tobago PRO [Radeon R7 360 / R9 360 OEM] (rev 81) » Vengeance LPX 16GB DDR4 K2 3200MHz C16

User avatar
Ed_P
Contributor
Contributor
Posts: 3214
Joined: 06 Feb 2013, 22:12
Distribution: Cinnamon 3.2.2 64-bit ISO
Location: Western NY, USA

[SOLVED] How to change $PATH with saving a new $PATH after reboot

Post#10 by Ed_P » 07 Sep 2017, 00:15

I'm glad "we" were able to SOLVE it. :happy62:

I've heard of sed but have never used it myself.
Ed

Post Reply