my-env/install/composer

57 lines
1.7 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
sudo rm -f $HOME/.local/bin/composer
sudo rm -f /bin/composer
sudo rm -f /usr/bin/composer
sudo rm -f /usr/local/bin/composer
sudo rm -f /usr/src/composer
2022-07-12 15:20:11 +00:00
rm $HOME/.local/bin/composer
fi
2023-03-10 05:55:10 +00:00
mkdir -p $HOME/install $HOME/.local/bin
cd $HOME/install
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
mv -f $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
2023-03-10 05:55:10 +00:00
COMPOSER_GLOBAL_HOME="$($HOME/.local/bin/composer config -g home)"
2022-12-11 06:48:30 +00:00
NEWPATH="export PATH=\"$COMPOSER_GLOBAL_HOME/vendor/bin:\${PATH}\""
cat "${HOME}/.profile" | grep -qoh "$NEWPATH" || {
$NEWPATH
echo "$NEWPATH" >> "${HOME}/.profile"
}
2023-03-10 05:55:10 +00:00
source "${HOME}/.profile"
2022-12-11 06:48:30 +00:00
echo
echo "Finish!"
2023-04-11 15:43:14 +00:00
composer --version
2022-12-11 06:48:30 +00:00
echo