packer-cn/scripts/dist.sh

68 lines
1.5 KiB
Bash
Raw Normal View History

#!/bin/bash
set -e
2013-06-20 01:44:02 -04:00
# Get the parent directory of where this script is.
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
# 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/')
if [ ! -z $PREVERSION ]; then
PREVERSION="${PREVERSION}.$(date -u +%s)"
2013-06-20 03:01:12 -04:00
VERSIONDIR="${VERSIONDIR}-${PREVERSION}"
fi
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-11-18 13:28:45 -05:00
# Compile the main project
./scripts/compile.sh
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 03:01:12 -04:00
# Zip all the packages
2013-11-18 13:28:45 -05:00
mkdir -p ./pkg/dist
for PLATFORM in $(find ./pkg -mindepth 1 -maxdepth 1 -type d); do
2013-06-20 03:01:12 -04:00
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-11-18 13:28:45 -05:00
zip ${DIR}/pkg/dist/${ARCHIVE_NAME}.zip ./*
2013-06-20 03:01:12 -04:00
popd
) &
done
2013-06-20 01:40:30 -04:00
2013-06-20 03:01:12 -04:00
waitAll
# Make the checksums
2013-11-18 13:28:45 -05:00
pushd ./pkg/dist
shasum -a256 * > ./${VERSIONDIR}_SHA256SUMS
popd
2013-06-20 03:01:12 -04:00
exit 0