github.com/sneal/packer@v0.5.2/scripts/compile.sh (about) 1 #!/bin/bash 2 # 3 # This script compiles Packer for various platforms (specified by the 4 # PACKER_OS and PACKER_ARCH environmental variables). 5 set -e 6 7 NO_COLOR="\x1b[0m" 8 OK_COLOR="\x1b[32;01m" 9 ERROR_COLOR="\x1b[31;01m" 10 WARN_COLOR="\x1b[33;01m" 11 12 # Get the parent directory of where this script is. 13 SOURCE="${BASH_SOURCE[0]}" 14 while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done 15 DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" 16 17 # Change into that directory 18 cd $DIR 19 20 # Get the git commit 21 GIT_COMMIT=$(git rev-parse HEAD) 22 GIT_DIRTY=$(test -n "`git status --porcelain`" && echo "+CHANGES" || true) 23 24 # Determine the arch/os combos we're building for 25 XC_ARCH=${XC_ARCH:-"386 amd64 arm"} 26 XC_OS=${XC_OS:-linux darwin windows freebsd openbsd} 27 28 # Make sure that if we're killed, we kill all our subprocseses 29 trap "kill 0" SIGINT SIGTERM EXIT 30 31 echo -e "${OK_COLOR}==> Installing dependencies to speed up builds...${NO_COLOR}" 32 go get ./... 33 34 echo -e "${OK_COLOR}==> Beginning compile...${NO_COLOR}" 35 rm -rf pkg/ 36 gox \ 37 -os="${XC_OS}" \ 38 -arch="${XC_ARCH}" \ 39 -ldflags "-X github.com/mitchellh/packer/packer.GitCommit ${GIT_COMMIT}${GIT_DIRTY}" \ 40 -output "pkg/{{.OS}}_{{.Arch}}/packer-{{.Dir}}" \ 41 ./... 42 43 # Make sure "packer-packer" is renamed properly 44 for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do 45 set +e 46 mv ${PLATFORM}/packer-packer ${PLATFORM}/packer 2>/dev/null 47 mv ${PLATFORM}/packer-packer.exe ${PLATFORM}/packer.exe 2>/dev/null 48 set -e 49 done 50 51 # Reset signal trapping to avoid "Terminated: 15" at the end 52 trap - SIGINT SIGTERM EXIT