Last active
April 18, 2017 14:26
-
-
Save lucky-J/3f6b77e7f3ca745651abc5079a7cfbf8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| #build php project with composer | |
| APP_ROOT=$(pwd); | |
| SRC='';#put source here | |
| DST='';#put destination here | |
| DIRS=();#put directories here | |
| FILES=();#put files here | |
| START=`date +%s`; | |
| function make_dirs() { | |
| for item in ${DIRS[*]} | |
| do | |
| EXISTS=`ls | grep "$item"` | |
| if [[ EXISTS -eq "" ]]; then | |
| mkdir "$item" 2> /dev/null | |
| printf " %s\n Created directory " $item | |
| fi | |
| done | |
| } | |
| function copy_files() { | |
| for item in ${FILES[*]} | |
| do | |
| #copy files from source to destination | |
| cp "$SRC/$item $DST"; | |
| done | |
| printf " %s\n All files were copied \n" | |
| } | |
| function print_composer_instruction() { | |
| printf " %s\n TO install composer run following command: " | |
| printf "\ncd ~ | |
| curl -sS https://getcomposer.org/installer | php | |
| sudo mv composer.phar /usr/bin/composer | |
| \n" | |
| } | |
| #run composer | |
| function run_composer() { | |
| EXISTS=`find $APP_ROOT -maxdepth 1 -type f -name "composer.json"`; | |
| if [[ ! -z "$EXISTS" ]]; then | |
| $1 install | |
| else | |
| printf " %s\n File composer.json not found. Exiting... \n" | |
| exit 1; | |
| fi | |
| } | |
| #check composer is installed | |
| function check_composer_installed() { | |
| #check conposer global | |
| COMPOSER=`which composer`; | |
| EXISTS=$?; | |
| if [[ $EXISTS -eq 0 ]]; then | |
| echo "$COMPOSER " | |
| run_composer "$COMPOSER" | |
| return "0"; | |
| else | |
| #check composer local if global not found | |
| L_COMPOSER1=`find $APP_ROOT -maxdepth 1 -type f -name "composer"` | |
| L_COMPOSER2=`find $APP_ROOT -maxdepth 1 -type f -name "composer.phar"` | |
| if [[ -z $L_COMPOSER1 ]]; then | |
| if [[ -z $L_COMPOSER2 ]]; then | |
| print_composer_instruction | |
| exit 1; | |
| else | |
| run_composer $L_COMPOSER2; | |
| return 0; | |
| fi | |
| else | |
| run_composer $L_COMPOSER1; | |
| return 0; | |
| fi | |
| fi | |
| } | |
| make_dirs | |
| copy_files | |
| check_composer_installed | |
| END=`date +%s`; | |
| function build_duration() { | |
| DURATION=$((END-START)) | |
| echo "Duration: " "$DURATION" " seconds"; | |
| } | |
| build_duration |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment