my-env/install/composer

42 lines
1.3 KiB
Plaintext
Raw Normal View History

#!/bin/bash
##makedesc: Install composer (latest)
2022-01-09 08:56:25 +00:00
echo
echo "==============================================="
echo "Installing composer (latest)..."
2022-01-09 08:56:25 +00:00
echo "==============================================="
echo
installed() {
command -v "$1" >/dev/null 2>&1
}
2022-07-04 15:24:27 +00:00
!installed "php" && echo "WARNING: You need to have php installed"
if installed "composer"; then
echo "WARNING: Removing current composer to install its actual version"
sudo apt remove -y --autoremove composer
sudo rm -f /bin/composer
sudo rm -f /usr/bin/composer
sudo rm -f /usr/local/bin/composer
sudo rm -rf /usr/src/composer
fi
2022-07-04 15:24:27 +00:00
sudo mkdir -m 0777 -p /usr/src/composer
cd /usr/src/composer
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
sudo php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")"
if [ "$EXPECTED_CHECKSUM" != "$ACTUAL_CHECKSUM" ]; then
>&2 echo 'ERROR: Invalid installer checksum'
rm composer-setup.php
exit 1
fi
php composer-setup.php --quiet
sudo cp /usr/src/composer/composer.phar /usr/local/bin/composer
cd - >/dev/null
sudo rm -rf /usr/src/composer/
installed "composer" && composer --version