composer reworked

This commit is contained in:
Anthony Axenov 2024-07-31 23:23:55 +08:00
parent 79db21f336
commit f9f8f5b2dc
Signed by: anthony
GPG Key ID: EA9EC32FF7CCD4EC

View File

@ -1,56 +1,41 @@
#!/bin/bash #!/bin/bash
##makedesc: Install composer (latest) ##makedesc: Install composer (latest)
echo source `dirname $0`/../helpers || exit 255
echo "==============================================="
echo "Installing composer (latest)..."
echo "==============================================="
echo
# https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md # https://getcomposer.org/doc/faqs/how-to-install-composer-programmatically.md
installed() { title
command -v "$1" >/dev/null 2>&1
}
! installed "php" && echo "WARNING: You need php to be installed" require php
if installed "composer"; then if installed "composer"; then
echo "WARNING: Removing current composer to install its actual version" warn "WARNING: Removing current composer to install its actual version"
sudo apt remove -y --autoremove composer sudo apt remove -y --autoremove composer
sudo rm -f $HOME/.local/bin/composer sudo rm -f \
sudo rm -f /bin/composer "$HOME/.local/bin/composer" \
sudo rm -f /usr/bin/composer /bin/composer \
sudo rm -f /usr/local/bin/composer /usr/bin/composer \
sudo rm -f /usr/src/composer /usr/local/bin/composer \
rm $HOME/.local/bin/composer /usr/src/composer \
"$HOME/.local/bin/composer"
fi fi
mkdir -p $HOME/install $HOME/.local/bin mkdir -p "$HOME/install" "$HOME/.local/bin"
cd $HOME/install download "https://getcomposer.org/installer" "$HOME/install/composer-setup.php" && \
php "$HOME/install/composer-setup.php" --install-dir="$HOME/.local/bin/composer"
EXPECTED_CHECKSUM="$(php -r 'copy("https://composer.github.io/installer.sig", "php://stdout");')" [ $? = 0 ] && {
# php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');" COMPOSER_GLOBAL_HOME="$($HOME/.local/bin/composer config -g home)"
wget https://getcomposer.org/installer -O composer-setup.php NEWPATH="export PATH=\"$COMPOSER_GLOBAL_HOME/vendor/bin:\${PATH}\""
ACTUAL_CHECKSUM="$(php -r "echo hash_file('sha384', 'composer-setup.php');")" cat "$HOME/.profile" | grep -qoh "$NEWPATH" || {
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
cd - >/dev/null
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 $NEWPATH
echo "$NEWPATH" >> "${HOME}/.profile" echo "$NEWPATH" >> "$HOME/.profile"
}
echo
success "composer installed!"
composer --version
echo
} }
source "${HOME}/.profile"
echo
echo "Finish!"
composer --version
echo
source "$HOME/.profile"