|
| 1 | +#!/bin/bash |
| 2 | +set -e |
| 3 | + |
| 4 | +# Get the parent directory of where this script is. |
| 5 | +SOURCE="${BASH_SOURCE[0]}" |
| 6 | +while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done |
| 7 | +DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )" |
| 8 | + |
| 9 | +# Change into that dir because we expect that |
| 10 | +cd $DIR |
| 11 | + |
| 12 | +# Determine the version that we're building based on the contents |
| 13 | +# of packer/version.go. |
| 14 | +VERSION=$(grep "const Version " version.go | sed -E 's/.*"(.+)"$/\1/') |
| 15 | +VERSIONDIR="${VERSION}" |
| 16 | +PREVERSION=$(grep "const VersionPrerelease " version.go | sed -E 's/.*"(.*)"$/\1/') |
| 17 | +if [ ! -z $PREVERSION ]; then |
| 18 | + PREVERSION="${PREVERSION}.$(date -u +%s)" |
| 19 | + VERSIONDIR="${VERSIONDIR}-${PREVERSION}" |
| 20 | +fi |
| 21 | + |
| 22 | +echo "Version: ${VERSION} ${PREVERSION}" |
| 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 | +echo "Arch: ${XC_ARCH}" |
| 29 | +echo "OS: ${XC_OS}" |
| 30 | + |
| 31 | +# Make sure that if we're killed, we kill all our subprocseses |
| 32 | +trap "kill 0" SIGINT SIGTERM EXIT |
| 33 | + |
| 34 | +# This function builds whatever directory we're in... |
| 35 | +goxc \ |
| 36 | + -arch="$XC_ARCH" \ |
| 37 | + -os="$XC_OS" \ |
| 38 | + -d="${DIR}/pkg" \ |
| 39 | + -pv="${VERSION}" \ |
| 40 | + -pr="${PREVERSION}" \ |
| 41 | + $XC_OPTS \ |
| 42 | + go-install \ |
| 43 | + xc |
| 44 | + |
| 45 | +# Zip all the packages |
| 46 | +mkdir -p ./pkg/${VERSIONDIR}/dist |
| 47 | +for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do |
| 48 | + PLATFORM_NAME=$(basename ${PLATFORM}) |
| 49 | + ARCHIVE_NAME="${VERSIONDIR}_${PLATFORM_NAME}" |
| 50 | + |
| 51 | + if [ $PLATFORM_NAME = "dist" ]; then |
| 52 | + continue |
| 53 | + fi |
| 54 | + |
| 55 | + pushd ${PLATFORM} |
| 56 | + zip ${DIR}/pkg/${VERSIONDIR}/dist/${ARCHIVE_NAME}.zip ./* |
| 57 | + popd |
| 58 | +done |
| 59 | + |
| 60 | +# Make the checksums |
| 61 | +pushd ./pkg/${VERSIONDIR}/dist |
| 62 | +shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS |
| 63 | +popd |
| 64 | + |
| 65 | +exit 0 |
0 commit comments