composer reworked
This commit is contained in:
parent
79db21f336
commit
f9f8f5b2dc
@ -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
|
$NEWPATH
|
||||||
>&2 echo 'ERROR: Invalid installer checksum'
|
echo "$NEWPATH" >> "$HOME/.profile"
|
||||||
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)"
|
echo
|
||||||
NEWPATH="export PATH=\"$COMPOSER_GLOBAL_HOME/vendor/bin:\${PATH}\""
|
success "composer installed!"
|
||||||
cat "${HOME}/.profile" | grep -qoh "$NEWPATH" || {
|
composer --version
|
||||||
$NEWPATH
|
echo
|
||||||
echo "$NEWPATH" >> "${HOME}/.profile"
|
|
||||||
}
|
}
|
||||||
source "${HOME}/.profile"
|
|
||||||
|
|
||||||
echo
|
|
||||||
echo "Finish!"
|
|
||||||
composer --version
|
|
||||||
echo
|
|
||||||
|
|
||||||
|
source "$HOME/.profile"
|
||||||
|
Loading…
Reference in New Issue
Block a user