From db09b9cc36a7e06de92f03d3427e6fbd0ad54f28 Mon Sep 17 00:00:00 2001 From: CanbiZ <47820557+MickLesk@users.noreply.github.com> Date: Mon, 4 Aug 2025 14:12:18 +0200 Subject: [PATCH] Composer: PATH Issues when updating (#6543) * Update build.func * Composer: Path Issues with old installs * Update build.func * comment --- misc/tools.func | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/misc/tools.func b/misc/tools.func index 752a63a47..f81cc6103 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -492,39 +492,50 @@ function setup_php() { fi fi } + # ------------------------------------------------------------------------------ -# Installs or updates Composer globally. +# Installs or updates Composer globally (robust, idempotent). # -# Description: -# - Downloads latest version from getcomposer.org -# - Installs to /usr/local/bin/composer +# - Installs to /usr/local/bin/composer +# - Removes old binaries/symlinks in /usr/bin, /bin, /root/.composer, etc. +# - Ensures /usr/local/bin is in PATH (permanent) # ------------------------------------------------------------------------------ function setup_composer() { local COMPOSER_BIN="/usr/local/bin/composer" export COMPOSER_ALLOW_SUPERUSER=1 + # Clean up old Composer binaries/symlinks (if any) + for old in /usr/bin/composer /bin/composer /root/.composer/vendor/bin/composer; do + [[ -e "$old" && "$old" != "$COMPOSER_BIN" ]] && rm -f "$old" + done + + # Ensure /usr/local/bin is in PATH for future logins (and current shell) + ensure_usr_local_bin_persist + export PATH="/usr/local/bin:$PATH" + # Check if composer is already installed if [[ -x "$COMPOSER_BIN" ]]; then local CURRENT_VERSION CURRENT_VERSION=$("$COMPOSER_BIN" --version | awk '{print $3}') $STD msg_info "Old Composer $CURRENT_VERSION found, updating to latest" else - msg_info "Setup Composer" + msg_info "Installing Composer" fi - # Download and install latest composer + # Download and install latest Composer curl -fsSL https://getcomposer.org/installer -o /tmp/composer-setup.php php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer >/dev/null 2>&1 - if [[ $? -ne 0 ]]; then - msg_error "Failed to install Composer" + if [[ ! -x "$COMPOSER_BIN" ]]; then + msg_error "Composer was not successfully installed (no binary at $COMPOSER_BIN)" return 1 fi chmod +x "$COMPOSER_BIN" - $STD composer diagnose - msg_ok "Setup Composer" + $STD "$COMPOSER_BIN" self-update --no-interaction || true # safe if already latest + $STD "$COMPOSER_BIN" diagnose + msg_ok "Composer is ready at $COMPOSER_BIN" } # ------------------------------------------------------------------------------