2013-06-20 01:20:52 -04:00
|
|
|
#!/bin/bash
|
|
|
|
set -e
|
|
|
|
|
2013-06-20 01:44:02 -04:00
|
|
|
# Get the parent directory of where this script is.
|
2013-06-20 01:20:52 -04:00
|
|
|
SOURCE="${BASH_SOURCE[0]}"
|
|
|
|
while [ -h "$SOURCE" ] ; do SOURCE="$(readlink "$SOURCE")"; done
|
2013-06-20 01:44:02 -04:00
|
|
|
DIR="$( cd -P "$( dirname "$SOURCE" )/.." && pwd )"
|
|
|
|
|
|
|
|
# Change into that dir because we expect that
|
|
|
|
cd $DIR
|
2013-06-20 01:20:52 -04:00
|
|
|
|
|
|
|
# Determine the version that we're building based on the contents
|
|
|
|
# of packer/version.go.
|
|
|
|
VERSION=$(grep "const Version " packer/version.go | sed -E 's/.*"(.+)"$/\1/')
|
2013-06-20 03:01:12 -04:00
|
|
|
VERSIONDIR="${VERSION}"
|
2013-06-28 10:35:24 -04:00
|
|
|
PREVERSION=$(grep "const VersionPrerelease " packer/version.go | sed -E 's/.*"(.*)"$/\1/')
|
2013-06-20 01:20:52 -04:00
|
|
|
if [ ! -z $PREVERSION ]; then
|
|
|
|
PREVERSION="${PREVERSION}.$(date -u +%s)"
|
2013-06-20 03:01:12 -04:00
|
|
|
VERSIONDIR="${VERSIONDIR}-${PREVERSION}"
|
2013-06-20 01:20:52 -04:00
|
|
|
fi
|
|
|
|
|
|
|
|
echo "Version: ${VERSION} ${PREVERSION}"
|
|
|
|
|
2013-07-16 17:36:54 -04:00
|
|
|
# Determine the arch/os combos we're building for
|
|
|
|
XC_ARCH=${XC_ARCH:-"386 amd64 arm"}
|
|
|
|
XC_OS=${XC_OS:-linux darwin windows freebsd openbsd}
|
|
|
|
|
|
|
|
echo "Arch: ${XC_ARCH}"
|
|
|
|
echo "OS: ${XC_OS}"
|
|
|
|
|
2013-06-20 01:20:52 -04:00
|
|
|
# This function builds whatever directory we're in...
|
|
|
|
xc() {
|
|
|
|
goxc \
|
2013-07-16 17:36:54 -04:00
|
|
|
-arch="$XC_ARCH" \
|
|
|
|
-os="$XC_OS" \
|
2013-06-20 01:20:52 -04:00
|
|
|
-d="${DIR}/pkg" \
|
|
|
|
-pv="${VERSION}" \
|
|
|
|
-pr="${PREVERSION}" \
|
|
|
|
go-install \
|
|
|
|
xc
|
|
|
|
}
|
|
|
|
|
2013-06-20 03:01:12 -04:00
|
|
|
# This function waits for all background tasks to complete
|
|
|
|
waitAll() {
|
|
|
|
RESULT=0
|
|
|
|
for job in `jobs -p`; do
|
|
|
|
wait $job
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
RESULT=1
|
|
|
|
fi
|
|
|
|
done
|
|
|
|
|
|
|
|
if [ $RESULT -ne 0 ]; then
|
|
|
|
exit $RESULT
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2013-06-20 01:40:30 -04:00
|
|
|
# Make sure that if we're killed, we kill all our subprocseses
|
|
|
|
trap "kill 0" SIGINT SIGTERM EXIT
|
|
|
|
|
2013-06-20 01:20:52 -04:00
|
|
|
# Build our root project
|
2013-06-20 01:40:30 -04:00
|
|
|
xc &
|
2013-06-20 01:20:52 -04:00
|
|
|
|
|
|
|
# Build all the plugins
|
|
|
|
for PLUGIN in $(find ./plugin -mindepth 1 -maxdepth 1 -type d); do
|
|
|
|
PLUGIN_NAME=$(basename ${PLUGIN})
|
2013-06-20 01:40:30 -04:00
|
|
|
(
|
2013-06-20 01:20:52 -04:00
|
|
|
pushd ${PLUGIN}
|
|
|
|
xc
|
|
|
|
popd
|
2013-06-28 22:05:03 -04:00
|
|
|
find ./pkg \
|
|
|
|
-type f \
|
|
|
|
-name ${PLUGIN_NAME} \
|
|
|
|
-execdir mv ${PLUGIN_NAME} packer-${PLUGIN_NAME} ';'
|
|
|
|
find ./pkg \
|
|
|
|
-type f \
|
|
|
|
-name ${PLUGIN_NAME}.exe \
|
|
|
|
-execdir mv ${PLUGIN_NAME}.exe packer-${PLUGIN_NAME}.exe ';'
|
2013-06-20 01:40:30 -04:00
|
|
|
) &
|
|
|
|
done
|
|
|
|
|
2013-06-20 03:01:12 -04:00
|
|
|
waitAll
|
|
|
|
|
|
|
|
# Zip all the packages
|
|
|
|
mkdir -p ./pkg/${VERSIONDIR}/dist
|
|
|
|
for PLATFORM in $(find ./pkg/${VERSIONDIR} -mindepth 1 -maxdepth 1 -type d); do
|
|
|
|
PLATFORM_NAME=$(basename ${PLATFORM})
|
|
|
|
ARCHIVE_NAME="${VERSIONDIR}_${PLATFORM_NAME}"
|
|
|
|
|
|
|
|
if [ $PLATFORM_NAME = "dist" ]; then
|
|
|
|
continue
|
2013-06-20 01:40:30 -04:00
|
|
|
fi
|
2013-06-20 03:01:12 -04:00
|
|
|
|
|
|
|
(
|
|
|
|
pushd ${PLATFORM}
|
2013-06-28 10:34:15 -04:00
|
|
|
zip ${DIR}/pkg/${VERSIONDIR}/dist/${ARCHIVE_NAME}.zip ./*
|
2013-06-20 03:01:12 -04:00
|
|
|
popd
|
|
|
|
) &
|
2013-06-20 01:20:52 -04:00
|
|
|
done
|
2013-06-20 01:40:30 -04:00
|
|
|
|
2013-06-20 03:01:12 -04:00
|
|
|
waitAll
|
|
|
|
|
2013-06-24 18:13:59 -04:00
|
|
|
# Make the checksums
|
|
|
|
pushd ./pkg/${VERSIONDIR}/dist
|
2013-06-28 10:37:57 -04:00
|
|
|
shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS
|
2013-06-24 18:13:59 -04:00
|
|
|
popd
|
|
|
|
|
2013-06-20 03:01:12 -04:00
|
|
|
exit 0
|