From ff5263981b24d5fffac194a94c657e7eb6a7f4ee Mon Sep 17 00:00:00 2001 From: "CanbiZ (MickLesk)" <47820557+MickLesk@users.noreply.github.com> Date: Tue, 20 Jan 2026 14:59:41 +0100 Subject: [PATCH] core: implement ensure_profile_loaded function (#10999) --- misc/build.func | 2 ++ misc/core.func | 30 ++++++++++++++++++++++++++++-- 2 files changed, 30 insertions(+), 2 deletions(-) diff --git a/misc/build.func b/misc/build.func index ba3a8fa27..0eb8ba065 100644 --- a/misc/build.func +++ b/misc/build.func @@ -2843,6 +2843,7 @@ start() { elif [ ! -z ${PHS_SILENT+x} ] && [[ "${PHS_SILENT}" == "1" ]]; then VERBOSE="no" set_std_mode + ensure_profile_loaded update_script cleanup_lxc else @@ -2868,6 +2869,7 @@ start() { exit ;; esac + ensure_profile_loaded update_script cleanup_lxc fi diff --git a/misc/core.func b/misc/core.func index d6d4555cc..c306d9363 100644 --- a/misc/core.func +++ b/misc/core.func @@ -38,8 +38,6 @@ load_functions() { icons default_vars set_std_mode - # Note: get_lxc_ip() is NOT called here automatically - # Call it explicitly when you need LOCAL_IP variable } # ------------------------------------------------------------------------------ @@ -129,6 +127,34 @@ icons() { HOURGLASS="${TAB}⏳${TAB}" } +# ------------------------------------------------------------------------------ +# ensure_profile_loaded() +# +# - Sources /etc/profile.d/*.sh scripts if not already loaded +# - Fixes PATH issues when running via pct enter/exec (non-login shells) +# - Safe to call multiple times (uses guard variable) +# - Should be called in update_script() or any script running inside LXC +# ------------------------------------------------------------------------------ +ensure_profile_loaded() { + # Skip if already loaded or running on Proxmox host + [[ -n "${_PROFILE_LOADED:-}" ]] && return + command -v pveversion &>/dev/null && return + + # Source all profile.d scripts to ensure PATH is complete + if [[ -d /etc/profile.d ]]; then + for script in /etc/profile.d/*.sh; do + [[ -r "$script" ]] && source "$script" + done + fi + + # Also ensure /usr/local/bin is in PATH (common install location) + if [[ ":$PATH:" != *":/usr/local/bin:"* ]]; then + export PATH="/usr/local/bin:$PATH" + fi + + export _PROFILE_LOADED=1 +} + # ------------------------------------------------------------------------------ # default_vars() #