my-env/install/composer
2023-04-18 10:22:01 +08:00

42 lines
1.1 KiB
Bash
Executable File

#!/bin/bash
##makedesc: Install composer (latest)
source `dirname $0`/../helpers || exit 255
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
title
require php
if installed "composer"; then
warn "WARNING: Removing current composer to install its actual version"
sudo apt remove -y --autoremove composer
sudo rm -f \
"$HOME/.local/bin/composer" \
/bin/composer \
/usr/bin/composer \
/usr/local/bin/composer \
/usr/src/composer \
"$HOME/.local/bin/composer"
fi
mkdir -p "$HOME/install" "$HOME/.local/bin"
download "https://getcomposer.org/installer" "$HOME/install/composer-setup.php" && \
php "$HOME/install/composer-setup.php" --install-dir="$HOME/.local/bin/composer"
[ $? = 0 ] && {
COMPOSER_GLOBAL_HOME="$($HOME/.local/bin/composer config -g home)"
NEWPATH="export PATH=\"$COMPOSER_GLOBAL_HOME/vendor/bin:\${PATH}\""
cat "$HOME/.profile" | grep -qoh "$NEWPATH" || {
$NEWPATH
echo "$NEWPATH" >> "$HOME/.profile"
}
echo
success "composer installed!"
composer --version
echo
}
source "$HOME/.profile"