github.com/sneal/packer@v0.5.2/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 ]] 14 then 15 return 0 16 fi 17 local IFS=. 18 local i ver1="$1" ver2="$2" 19 20 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)) 21 do 22 ver1[i]=0 23 done 24 for ((i=0; i<${#ver1[@]}; i++)) 25 do 26 if [[ -z ${ver2[i]} ]] 27 then 28 ver2[i]=0 29 fi 30 if ((10#${ver1[i]} > 10#${ver2[i]})) 31 then 32 echo -e "${ERROR_COLOR}==> Required Go version $1 not installed. Found $2 instead" 33 exit 1 34 fi 35 done 36 } 37 38 GO_MINIMUM_VERSION=1.2 39 GO_INSTALLED_VERSION=$(go version | cut -d ' ' -f 3) 40 GO_INSTALLED_VERSION=${GO_INSTALLED_VERSION#"go"} 41 42 echo -e "${OK_COLOR}==> Verifying Go" 43 verify_go $GO_MINIMUM_VERSION $GO_INSTALLED_VERSION 44 45 # Get the parent directory of where this script is. 46 SOURCE="${BASH_SOURCE[0]}" 47 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 48 DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" 49 50 # Change into that directory 51 cd $DIR 52 53 # Compile the thing 54 export XC_ARCH=$(go env GOARCH) 55 export XC_OS=$(go env GOOS) 56 ./scripts/compile.sh 57 58 # Move all the compiled things to the PATH 59 case $(uname) in 60 CYGWIN*) 61 GOPATH="$(cygpath $GOPATH)" 62 ;; 63 esac 64 IFS=: MAIN_GOPATH=( $GOPATH ) 65 cp pkg/${XC_OS}_${XC_ARCH}/* ${MAIN_GOPATH}/bin