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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 56 additions & 12 deletions packages/b/bash/files/profile/10-path.sh
Original file line number Diff line number Diff line change
@@ -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.


export PATH="/usr/sbin:/usr/bin"
if [ -d "/usr/local/sbin" ]; then
export PATH="$PATH:/usr/local/sbin"
fi
PREFIX_PATH=
POSTFIX_PATH=

if [ -d "/usr/local/bin" ]; then
export PATH="$PATH:/usr/local/bin"
fi
# PATH exists, only append missing stuff to it
if [[ -n "${PATH}" ]]; then

if [ -d "$HOME/bin" ]; then
export PATH="$HOME/bin:$PATH"
fi
echo "DEBUG: Starting \$PATH: ${PATH}"

for d in "/usr/sbin" "/usr/bin" "/usr/local/sbin" "/usr/local/bin"; do
# respect user path ordering if the element is already in $PATH
if [[ "${PATH}" =~ "${d}" ]]; then
:
echo "DEBUG: Skipping ${d} as it is already in \$PATH"
else
POSTFIX_PATH="${POSTFIX_PATH}:${d}"
echo "DEBUG: Added ${d} to \$POSTFIX_PATH, \$POSTFIX_PATH is now: ${POSTFIX_PATH}"
fi
done

for d in "${HOME}/.local/bin" "${HOME}/bin"; do
# respect user path ordering if the element is already in $PATH
if [[ "${PATH}" =~ "${d}" ]]; then
:
echo "DEBUG: Skipping ${d} as it is already in \$PATH"
else
PREFIX_PATH="${d}:${PREFIX_PATH}"
echo "DEBUG: Added ${d} to \$PREFIX_PATH, \$PREFIX_PATH is now: ${PREFIX_PATH}"
fi
done

# this should adequately respect existing path definitions
PATH="${PREFIX_PATH}${PATH}${POSTFIX_PATH}"

else
# PATH does NOT exist, build it from scratch.

if [ -d "$HOME/.local/bin" ]; then
export PATH="$HOME/.local/bin:$PATH"
echo "DEBUG: \$PATH is empty, building a default \$PATH ..."

DEFAULT_PATH="/usr/sbin:/usr/bin"
if [[ -d "/usr/local/sbin" ]]; then
DEFAULT_PATH="${DEFAULT_PATH}:/usr/local/sbin"
fi

if [[ -d "/usr/local/bin" ]]; then
DEFAULT_PATH="${DEFAULT_PATH}:/usr/local/bin"
fi

if [[ -d "$HOME/bin" ]]; then
DEFAULT_PATH="${HOME}/bin:${DEFAULT_PATH}"
fi

if [[ -d "$HOME/.local/bin" ]]; then
DEFAULT_PATH="${HOME}/.local/bin:${DEFAULT_PATH}"
fi

PATH="${DEFAULT_PATH}"
fi

export PATH="${PATH}"
echo "DEBUG: \$PATH is now: ${PATH}"

# End /usr/share/defaults/etc/profile.d/10-path.sh
2 changes: 1 addition & 1 deletion packages/b/bash/package.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name : bash

Check notice on line 1 in packages/b/bash/package.yml

View workflow job for this annotation

GitHub Actions / Checks

This package is included in the ISO. Consider validating the functionality in a newly built ISO.
version : 5.2.26
release : 80
release : 81
source :
- https://ftp.gnu.org/gnu/bash/bash-5.2.21.tar.gz : c8e31bdc59b69aaffc5b36509905ba3e5cbb12747091d27b4b977f078560d5b8
license :
Expand Down
12 changes: 6 additions & 6 deletions packages/b/bash/pspec_x86_64.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<Name>bash</Name>
<Homepage>https://www.gnu.org/software/bash</Homepage>
<Packager>
<Name>Troy Harvey</Name>
<Email>harveydevel@gmail.com</Email>
<Name>Rune Morling</Name>
<Email>ermo@serpentos.com</Email>
</Packager>
<License>GPL-3.0-or-later</License>
<PartOf>system.base</PartOf>
Expand Down Expand Up @@ -133,7 +133,7 @@
</Description>
<PartOf>programming.devel</PartOf>
<RuntimeDependencies>
<Dependency release="80">bash</Dependency>
<Dependency release="81">bash</Dependency>
</RuntimeDependencies>
<Files>
<Path fileType="header">/usr/include/bash/alias.h</Path>
Expand Down Expand Up @@ -199,12 +199,12 @@
</Files>
</Package>
<History>
<Update release="80">
<Update release="81">
<Date>2024-06-25</Date>
<Version>5.2.26</Version>
<Comment>Packaging update</Comment>
<Name>Troy Harvey</Name>
<Email>harveydevel@gmail.com</Email>
<Name>Rune Morling</Name>
<Email>ermo@serpentos.com</Email>
</Update>
</History>
</PISI>