github.com/tonnydourado/packer@v0.6.1-0.20140701134019-5d0cd9676a37/scripts/devcompile.sh (about) 1 #!/bin/bash 2 # 3 # This script only builds the application from source. 4 set -e 5 6 NO_COLOR="\x1b[0m" 7 OK_COLOR="\x1b[32;01m" 8 ERROR_COLOR="\x1b[31;01m" 9 WARN_COLOR="\x1b[33;01m" 10 11 # http://stackoverflow.com/questions/4023830/bash-how-compare-two-strings-in-version-format 12 verify_go () { 13 if [[ $1 == $2 ]]; then 14 return 0 15 fi 16 17 local IFS=. 18 local i ver1=($1) ver2=($2) 19 20 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do 21 ver1[i]=0 22 done 23 24 for ((i=0; i<${#ver1[@]}; i++)); do 25 if [[ -z ${ver2[i]} ]]; then 26 ver2[i]=0 27 fi 28 if ((10#${ver1[i]} > 10#${ver2[i]})); then 29 echo -e "${ERROR_COLOR}==> Required Go version $1 not installed. Found $2 instead" 30 exit 1 31 fi 32 done 33 } 34 35 GO_MINIMUM_VERSION=1.2 36 GO_INSTALLED_VERSION=$(go version | cut -d ' ' -f 3) 37 GO_INSTALLED_VERSION=${GO_INSTALLED_VERSION#"go"} 38 39 echo -e "${OK_COLOR}==> Verifying Go" 40 verify_go $GO_MINIMUM_VERSION $GO_INSTALLED_VERSION 41 42 # Get the parent directory of where this script is. 43 SOURCE="${BASH_SOURCE[0]}" 44 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 45 DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" 46 47 # Change into that directory 48 cd $DIR 49 50 # Compile the thing 51 export XC_ARCH=$(go env GOARCH) 52 export XC_OS=$(go env GOOS) 53 ./scripts/compile.sh 54 55 # Move all the compiled things to the PATH 56 case $(uname) in 57 CYGWIN*) 58 GOPATH="$(cygpath $GOPATH)" 59 ;; 60 esac 61 IFS=: MAIN_GOPATH=( $GOPATH ) 62 cp pkg/${XC_OS}_${XC_ARCH}/* ${MAIN_GOPATH}/bin 63 cp pkg/${XC_OS}_${XC_ARCH}/* ./bin