Skip to content

Commit

Permalink
Add install-composer.sh script.
Browse files Browse the repository at this point in the history
  • Loading branch information
reynoldsalec committed Nov 8, 2023
1 parent 2b90dab commit 274b32d
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions scripts/install-composer.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/bin/sh

set -e

VERSION="$1"

# NOTE: we should have better protections here
php -r "copy('https://getcomposer.org/installer', '/tmp/composer-setup.php');"

# Allow for a few convenience install methods
if [ "$VERSION" = '1-latest' ]; then
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --1
elif [ "$VERSION" = '1' ]; then
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --1
elif [ "$VERSION" = '2-latest' ]; then
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --2
elif [ "$VERSION" = '2' ]; then
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --2
elif [ "$VERSION" = 'preview' ]; then
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --preview
elif [ "$VERSION" = 'snapshot' ]; then
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --snapshot
else
php /tmp/composer-setup.php --install-dir=/usr/local/bin --filename=composer --version="$VERSION"
fi

# Remove the setup script
php -r "unlink('/tmp/composer-setup.php');"

# Check if anything is installed globally
if [ -f /var/www/.composer/composer.json ]; then
# If this is version 2 then let's make sure hirak/prestissimo is removed
if composer --version 2>/dev/null | grep -E "Composer (version )?2." > /dev/null; then
composer global remove hirak/prestissimo
fi
fi

0 comments on commit 274b32d

Please sign in to comment.