my-env/install/composer-clean

43 lines
1.4 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
2022-07-12 15:20:11 +00:00
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
2022-01-09 08:56:25 +00:00
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
2022-07-12 15:20:11 +00:00
sudo rm /bin/composer
sudo rm /usr/bin/composer
sudo rm /usr/local/bin/composer
sudo rm /usr/src/composer
rm $HOME/.local/bin/composer
fi
2022-07-12 15:20:11 +00:00
mkdir -p $HOME/install && cd $HOME/install
# mkdir -p $HOME/.local/bin
2022-07-04 15:24:27 +00:00
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')"
2022-07-12 15:20:11 +00:00
# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
wget https://getcomposer.org/installer -O composer-setup.php
2022-07-04 15:24:27 +00:00
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
2022-07-12 15:20:11 +00:00
cp $HOME/install/composer.phar $HOME/.local/bin/composer
2022-07-04 15:24:27 +00:00
cd - >/dev/null
installed "composer" && composer --version