Composer: PATH Issues when updating (#6543)

* Update build.func

* Composer: Path Issues with old installs

* Update build.func

* comment
This commit is contained in:
CanbiZ 2025-08-04 14:12:18 +02:00 committed by GitHub
parent 9f933c1e56
commit db09b9cc36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -492,39 +492,50 @@ function setup_php() {
fi fi
fi fi
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
# Installs or updates Composer globally. # Installs or updates Composer globally (robust, idempotent).
# #
# Description: # - Installs to /usr/local/bin/composer
# - Downloads latest version from getcomposer.org # - Removes old binaries/symlinks in /usr/bin, /bin, /root/.composer, etc.
# - Installs to /usr/local/bin/composer # - Ensures /usr/local/bin is in PATH (permanent)
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------
function setup_composer() { function setup_composer() {
local COMPOSER_BIN="/usr/local/bin/composer" local COMPOSER_BIN="/usr/local/bin/composer"
export COMPOSER_ALLOW_SUPERUSER=1 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 # Check if composer is already installed
if [[ -x "$COMPOSER_BIN" ]]; then if [[ -x "$COMPOSER_BIN" ]]; then
local CURRENT_VERSION local CURRENT_VERSION
CURRENT_VERSION=$("$COMPOSER_BIN" --version | awk '{print $3}') CURRENT_VERSION=$("$COMPOSER_BIN" --version | awk '{print $3}')
$STD msg_info "Old Composer $CURRENT_VERSION found, updating to latest" $STD msg_info "Old Composer $CURRENT_VERSION found, updating to latest"
else else
msg_info "Setup Composer" msg_info "Installing Composer"
fi fi
# Download and install latest composer # Download and install latest Composer
curl -fsSL https://getcomposer.org/installer -o /tmp/composer-setup.php 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 php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer >/dev/null 2>&1
if [[ $? -ne 0 ]]; then if [[ ! -x "$COMPOSER_BIN" ]]; then
msg_error "Failed to install Composer" msg_error "Composer was not successfully installed (no binary at $COMPOSER_BIN)"
return 1 return 1
fi fi
chmod +x "$COMPOSER_BIN" chmod +x "$COMPOSER_BIN"
$STD composer diagnose $STD "$COMPOSER_BIN" self-update --no-interaction || true # safe if already latest
msg_ok "Setup Composer" $STD "$COMPOSER_BIN" diagnose
msg_ok "Composer is ready at $COMPOSER_BIN"
} }
# ------------------------------------------------------------------------------ # ------------------------------------------------------------------------------