shell/install/composer

55 lines
1.6 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-12-10 13:59:01 +00:00
! installed "php" && echo "WARNING: You need php to be installed"
2022-07-04 15:24:27 +00:00
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
2022-12-11 06:48:30 +00:00
COMPOSER_GLOBAL_HOME="$(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
echo "Finish!"
echo
composer --version