Install composer srcipt

A bash script that will install composer in the bin dir of your choice for the user of your choice. <br/> <br/> Usage Example : ./install-composer.bash /usr/bin root <br/> will install composer in /usr/bin for the root user. Then the command \"composer\" wil lbe available on the whole system
#!/bin/bash BIN_DIRECTORY=$1 USER=$2 usage () { echo "Usage : $0 bin_directory owner" } if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" exit 1 fi if [ "$#" -lt 2 ] ; then echo "Error: bad command usage" usage exit 1 fi if [ ! -d $BIN_DIRECTORY ] ; then echo "Error: Bin directory doesnt exist" usage exit 1 fi if [ -f "$BIN_DIRECTORY/composer" ] ; then echo "Error: composer file already exist in bin directory" exit 1 fi if [ `grep -c "^$USER:" /etc/passwd` -ne 1 ] ; then echo "Error: user $USER doesnt exists" usage exit 1 fi if ! type "php" > /dev/null ; then echo "Error: php is not installed" fi TMP_DIR=$(mktemp -d /tmp/installcomposer.tpm.XXXXXXXXXX) || { echo "Error: failed to create tmp dir"; exit 1; } wget -O $TMP_DIR/installer https://getcomposer.org/installer (cd $TMP_DIR ; php installer) if [ ! -f "$TMP_DIR/composer.phar" ] ; then echo "Error: cant install composer" exit 1 fi mv "$TMP_DIR/composer.phar" "$BIN_DIRECTORY/composer" chown $USER:$USER $BIN_DIRECTORY/composer chmod +x $BIN_DIRECTORY/composer echo "Done"

Url: http://git.io/yyxOXQ

Language: Shell | User: souf | Created: Oct 6, 2013 | Tags: php composer bash