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

bash: Build new PATH the smart way #3096

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft

Conversation

ermo
Copy link
Contributor

@ermo ermo commented Jun 25, 2024

Summary
The goal with this PR is to ensure that any existing user-set PATH is respected to the widest extent possible. Any elements of the default PATH which have not already been added, will be added to the new PATH in (what I hope to be) a sane way.

In the case of no user-set PATH, prepare a sane default PATH.

I have left the debug statements in for now to provide visibility to the various test cases. Naturally, these debug statements will need to disappear before the commit is merged to main.

Test Plan

Open a new virtual terminal with the new 10-path.sh file in place in /usr/share/defaults/etc/profile.d/

Checklist

  • Package was built and tested against unstable

**Summary**
The goal with this PR is to ensure that any existing user-set PATH is
respected to the widest extent possible. Any elements of the default PATH
which have not already been added, will be added to the new PATH in (what
I hope to be) a sane way.

In the case of no user-set PATH, prepare a sane default PATH.

I have left the debug statements in for now to provide visibility to
the various test cases. Naturally, these debug statements will need to
disappear before the commit is merged to main.

Signed-off-by: Rune Morling <ermo@serpentos.com>
@silkeh silkeh self-requested a review August 18, 2024 19:47
@ermo ermo added Topic: Platform Integration Integration of various components within Solus Topic: Plumbing Core components labels Oct 20, 2024
@ermo ermo added this to the Solus 4.7 milestone Oct 20, 2024
Copy link
Member

@silkeh silkeh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I'm missing from the PR description is where the user's $PATH would be coming from. It's can't be set by the user's Bash config (see Bash Startup Files):

When Bash is invoked [...] it first reads and executes commands from the file /etc/profile, if that file exists.

The linked issue could be resolved as follows, which keeps this file much simpler and (importantly) more predictable for the user:

if [ -z ${PATH+x} ]
then
  # Insert old implementation here
fi

Edit: the issue describes that path would be overridden somewhere else though, so I think its probably worthwhile to figure out where.

@@ -1,20 +1,64 @@
# Begin /usr/share/defaults/etc/profile.d/10-path.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

File should start with a shebang to clarify that this is a bash script:

Suggested change
# Begin /usr/share/defaults/etc/profile.d/10-path.sh
#!/usr/bin/env bash
# Begin /usr/share/defaults/etc/profile.d/10-path.sh

Additionally, please pass the file through shellcheck.

@ermo ermo marked this pull request as draft November 9, 2024 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Topic: Platform Integration Integration of various components within Solus Topic: Plumbing Core components
Projects
Status: Needs More Info
Development

Successfully merging this pull request may close these issues.

2 participants