Skip to content

Instantly share code, notes, and snippets.

@john-clark
Created May 10, 2023 18:50
Show Gist options
  • Save john-clark/059fb041d2e9a5d4098c8e7dcb2748e8 to your computer and use it in GitHub Desktop.
Save john-clark/059fb041d2e9a5d4098c8e7dcb2748e8 to your computer and use it in GitHub Desktop.
Install composer into user home bin
#!/bin/bash
#
if [ ! -f "$HOME/bin/composer.phar" ]; then
sudo apt-get update | grep -P "\d\K upgraded"
sudo apt-get -y install curl php-cli php-mbstring git unzip | grep -P "\d\K installed"
if [[ ! -f "composer-setup.php" ]]; then
php -r "copy('https://getcomposer.org/installer', 'composer-setup.php');"
fi
HASH="$(wget -q -O - https://composer.github.io/installer.sig)"
HASHFILE=$(php -r "echo hash_file('SHA384','composer-setup.php');")
RESULT=$(php -r "if ('$HASHFILE' === '$HASH') { echo 'verified'; } else { echo 'corrupt'; }")
if [ "$RESULT" != "verified" ]; then
echo "Installer corrupted";
exit 1;
else
[ ! -d "$HOME/bin" ] && mkdir $HOME/bin
sudo php composer-setup.php --install-dir="$HOME/bin"
fi
rm composer-setup.php
else
ALIAS_STRING="alias composer=$HOME/bin/composer.phar"
ALIAS_FILE="$HOME/.bash_aliases"
[ ! -f "$ALIAS_FILE" ] && touch $ALIAS_FILE
grep -q -x -F "$ALIAS_STRING" "$ALIAS_FILE" || echo $ALIAS_STRING>>$ALIAS_FILE
fi
echo "now type: source ~/.profile"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment