Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

$PATH set in .bashrc not helping on Debian system #26

Closed
shlozm opened this issue Dec 25, 2023 · 16 comments
Closed

$PATH set in .bashrc not helping on Debian system #26

shlozm opened this issue Dec 25, 2023 · 16 comments

Comments

@shlozm
Copy link

shlozm commented Dec 25, 2023

I'm so sorry I didn't test properly.

Although echo $PATH in the terminal gives correct result, unless the $PATH is set correctly in .profile gimp will still not run, at least on my system.
I edited .profile for myself, so I'm fine, I just wanted to let you know that the issue could still be present on Debian systems even after the fix. Perhaps because $PATH set in .bashrc is only recognized by bash on the host system and the Archimage still sees the user-wide $PATH set by .profile.

Once again I apologize. I should have tried to run gimp, all I did was check the $PATH...

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

Try to install bubblewrap as I have said previously, JuNest is higly depending on it

@shlozm
Copy link
Author

shlozm commented Dec 25, 2023

Try to install bubblewrap as I have said previously, JuNest is higly depending on it

I did that ! First thing I tried, it is currently installed. And I rebooted the system for good measure. 'echo $PATH' is good, but gimp won't start, however, if I set $PATH correctly in .profile gimp will start even without bubblewrap.

I just tested removing the $PATH setting from .profile and gimp starts. It's the fact that the Debian default .profile sets the $PATH with .local/bin first that's the problem

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

No way... so should I patch also ~/.profile to solve this?

@shlozm
Copy link
Author

shlozm commented Dec 25, 2023

No way... so should I patch also ~/.profile to solve this?

I'm wondering if there's a setting I need for bubblewrap?

Would it be so bad to just comment out those lines in .profile and let the user know that?

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

I think I should add this

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
fi

and change the previous function like this

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
fi

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

This must be the new function

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $(! grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
fi

what do you think about?

@shlozm
Copy link
Author

shlozm commented Dec 25, 2023

This must be the new function

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $(! grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
fi

what do you think about?

For some reason it's not editing .profile at all I'm not familiar enough with sed to figure out why

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

Because I forgot to remove the "!"

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $( grep -q '$HOME/.local/bin:$PATH' $HOME/.profile); then
		sed -i 's#$HOME/.local/bin:$PATH#$PATH:$HOME/.local/bin#g' $HOME/.profile
	fi
fi

sorry!

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

Or to be more specific:

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $( grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
fi

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

To made people aware about this change, I've converted all this into a function (so it is easier to surf the script):

function _no_sudo(){
	if [ -n "$SUDO_COMMAND" ]; then 
		printf "\n WARNING: You don't need to use SUDO for this.\n\n"; 
		exit 1; 
	fi
}

function _patch_bashrc_and_profile(){
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $( grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
}

if [ $AMCLI == appman ] 2>/dev/null; then
	_no_sudo
	_patch_bashrc_and_profile
fi

@shlozm
Copy link
Author

shlozm commented Dec 25, 2023

Or to be more specific:

if [ $AMCLI == appman ] 2>/dev/null; then
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $( grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
fi

It works. Here is my $PATH
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/sz/.local/bin:/home/sz/.local/bin:/home/sz/.local/bin

.local/bin is repeated 3 times at the end, because it's set in .profile and then in .bashrc, and .bashrc gets sourced twice, (maybe once in the tty at login and again when I open my terminal)

It's not a problem, but the old code for what's added to .bashrc avoids repeating the .local/bin at the end. I would think to keep the old code as well would be better.

Another thing, it probably won't work until the user logs out and .profile gets sourced, maybe add 'source .profile'?

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

function _no_sudo(){
	if [ -n "$SUDO_COMMAND" ]; then 
		printf "\n WARNING: You don't need to use SUDO for this.\n\n"; 
		exit 1; 
	fi
}

function _patch_bashrc_and_profile(){
	if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
		echo 'export PATH=$(echo $PATH | tr ":" "\n" | grep -v "/.local/bin" | tr "\n" ":" | sed ''s/.$//'')' >> $HOME/.bashrc
		echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
	fi
	if $( grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
		sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
	fi
}

if [ $AMCLI == appman ] 2>/dev/null; then
	_no_sudo
	_patch_bashrc_and_profile
fi

so I must keep that line

echo 'export PATH=$(echo $PATH | tr ":" "\n" | grep -v "/.local/bin" | tr "\n" ":" | sed ''s/.$//'')' >> $HOME/.bashrc

to made the echo $PATH output shown without dupes.

Is it ok now?

@shlozm
Copy link
Author

shlozm commented Dec 25, 2023

I will test

Good now
echo $PATH
/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/sz/.local/bin

AND gimp runs without logging out, however I had to close the terminal in order that .bashrc gets sourced. Maybe add 'source $HOME/.bashrc' to the function?

Because otherwise when a user runs appman for the first time and installs gimp and tries to run gimp (without closing the terminal and opening again) it won't run. I tried.

@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

Maybe add 'source $HOME/.bashrc' to the function?

Honestly, this is a change that I would have liked to avoid, I don't want to make AppMan criticizable as happened with SystemD in the past.

Because otherwise when a user runs appman for the first time and installs gimp and tries to run gimp (without closing the terminal and opening again) it won't run. I tried.

It's a risk I'd rather take, just because of what I just said.

EDIT: also because this is an issue that affects only those with a minimal Debian installation, normally using a complete DE all this does not happens, so I have changed this function for a few of you.

Anyway... is the launcher (the .desktop file) working?

@shlozm
Copy link
Author

shlozm commented Dec 25, 2023

if $(! grep -q 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin' $HOME/.bashrc); then
echo 'export PATH=$(echo $PATH | tr ":" "\n" | grep -v "/.local/bin" | tr "\n" ":" | sed ''s/.$//'')' >> $HOME/.bashrc
echo -e 'export PATH=$PATH:$(xdg-user-dir USER)/.local/bin\n' >> $HOME/.bashrc
fi
if $( grep -q 'PATH="$HOME/.local/bin:$PATH"' $HOME/.profile); then
sed -i 's#PATH="$HOME/.local/bin:$PATH"#PATH="$PATH:$HOME/.local/bin"#g' $HOME/.profile
fi

Yes everything works .desktop and terminal. It works without closing the terminal as well, even though echo $PATH doesn't change until the terminal is closed, so there's no reason to add 'source .bashrc'

I believe this is totally solved. Thank you

ivan-hc added a commit that referenced this issue Dec 25, 2023
Some systems, including minimal Debian installations, have set the output of $PATH in the ~/.profile file to make "$HOME/.local/bin" appear as the first selection, thus depriving it of priority over other other $PATH, i.e.:

`/home/$USER/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games`

With this function, the line in the ~/.profile file will be corrected by changing

`PATH="$HOME/.local/bin:$PATH"`

in

`PATH="$PATH:$HOME/.local/bin"`

and in addition to the ~/.bashrc modification (see previous commit), the output of `echo $PATH` will be this:

`/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/$USER/.local/bin`

See #26
ivan-hc added a commit to ivan-hc/AM that referenced this issue Dec 25, 2023
Some systems, including minimal Debian installations, have set the output of $PATH in the ~/.profile file to make "$HOME/.local/bin" appear as the first selection, thus depriving it of priority over other other $PATH, i.e.:

`/home/$USER/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games`

With this function, the line in the ~/.profile file will be corrected by changing

`PATH="$HOME/.local/bin:$PATH"`

in

`PATH="$PATH:$HOME/.local/bin"`

and in addition to the ~/.bashrc modification (see previous commit), the output of `echo $PATH` will be this:

`/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/$USER/.local/bin`

See ivan-hc/AppMan#26
@ivan-hc
Copy link
Owner

ivan-hc commented Dec 25, 2023

Merry christmas

@ivan-hc ivan-hc closed this as completed Dec 25, 2023
ivan-hc added a commit to ivan-hc/AM that referenced this issue Dec 26, 2023
Changed the "_patch_bashrc_and_profile" function to only modify the ~/.profile file if the output of `echo $PATH` places $HOME/.local/bin first in the $PATH list.

Only systems that need it will be affected by this patch, while all systems will only have two lines added to the bottom of the ~/.bashrc file.

See the previous commits listed at ivan-hc/AppMan#25 and ivan-hc/AppMan#26
ivan-hc added a commit that referenced this issue Dec 26, 2023
Changed the "_patch_bashrc_and_profile" function to only modify the ~/.profile file if the output of `echo $PATH` places $HOME/.local/bin first in the $PATH list.

Only systems that need it will be affected by this patch, while all systems will only have two lines added to the bottom of the ~/.bashrc file.

See the previous commits listed at #25 and #26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants