tools.func: persist /usr/local/bin in shell PATHs (#11970)

This commit is contained in:
CanbiZ (MickLesk)
2026-02-16 10:30:05 +01:00
committed by GitHub
parent c975b25ad5
commit ae8dd5ba36
2 changed files with 21 additions and 3 deletions

View File

@@ -34,11 +34,19 @@ net_resolves() {
} }
ensure_usr_local_bin_persist() { ensure_usr_local_bin_persist() {
# Login shells: /etc/profile.d/
local PROFILE_FILE="/etc/profile.d/10-localbin.sh" local PROFILE_FILE="/etc/profile.d/10-localbin.sh"
if [ ! -f "$PROFILE_FILE" ]; then if [ ! -f "$PROFILE_FILE" ]; then
echo 'case ":$PATH:" in *:/usr/local/bin:*) ;; *) export PATH="/usr/local/bin:$PATH";; esac' >"$PROFILE_FILE" echo 'case ":$PATH:" in *:/usr/local/bin:*) ;; *) export PATH="/usr/local/bin:$PATH";; esac' >"$PROFILE_FILE"
chmod +x "$PROFILE_FILE" chmod +x "$PROFILE_FILE"
fi fi
# Non-login shells (pct enter): /root/.profile and /root/.bashrc
for rc_file in /root/.profile /root/.bashrc; do
if [ -f "$rc_file" ] && ! grep -q '/usr/local/bin' "$rc_file"; then
echo 'export PATH="/usr/local/bin:$PATH"' >>"$rc_file"
fi
done
} }
download_with_progress() { download_with_progress() {

View File

@@ -1851,16 +1851,26 @@ function download_with_progress() {
# Ensures /usr/local/bin is permanently in system PATH. # Ensures /usr/local/bin is permanently in system PATH.
# #
# Description: # Description:
# - Adds to /etc/profile.d if not present # - Adds to /etc/profile.d for login shells (SSH, noVNC)
# - Adds to /root/.bashrc for non-login shells (pct enter)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function ensure_usr_local_bin_persist() { function ensure_usr_local_bin_persist() {
local PROFILE_FILE="/etc/profile.d/custom_path.sh" # Skip on Proxmox host
command -v pveversion &>/dev/null && return
if [[ ! -f "$PROFILE_FILE" ]] && ! command -v pveversion &>/dev/null; then # Login shells: /etc/profile.d/
local PROFILE_FILE="/etc/profile.d/custom_path.sh"
if [[ ! -f "$PROFILE_FILE" ]]; then
echo 'export PATH="/usr/local/bin:$PATH"' >"$PROFILE_FILE" echo 'export PATH="/usr/local/bin:$PATH"' >"$PROFILE_FILE"
chmod +x "$PROFILE_FILE" chmod +x "$PROFILE_FILE"
fi fi
# Non-login shells (pct enter): /root/.bashrc
local BASHRC="/root/.bashrc"
if [[ -f "$BASHRC" ]] && ! grep -q '/usr/local/bin' "$BASHRC"; then
echo 'export PATH="/usr/local/bin:$PATH"' >>"$BASHRC"
fi
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------