2015-01-09 13:38:36 -08:00
|
|
|
#!/bin/bash
|
|
|
|
|
|
2015-01-23 15:01:10 -08:00
|
|
|
set -eu
|
2015-01-09 13:38:36 -08:00
|
|
|
|
2015-02-11 10:54:36 -08:00
|
|
|
: ${AWS_BOX_RELEASE_ACCESS_KEY:=}
|
|
|
|
|
: ${AWS_BOX_RELEASE_SECRET_KEY:=}
|
|
|
|
|
if [[ -z "${AWS_BOX_RELEASE_ACCESS_KEY}" || -z "${AWS_BOX_RELEASE_SECRET_KEY}" ]]; then
|
|
|
|
|
echo "AWS_BOX_RELEASE_ACCESS_KEY and AWS_BOX_RELEASE_SECRET_KEY env is not set"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
2015-01-10 21:37:31 -08:00
|
|
|
|
2015-01-22 15:46:04 -08:00
|
|
|
# Only GNU getopt supports long options. OS X comes bundled with the BSD getopt
|
|
|
|
|
# brew install gnu-getopt to get the GNU getopt on OS X
|
|
|
|
|
[[ $(uname -s) == "Darwin" ]] && GNU_GETOPT="/usr/local/opt/gnu-getopt/bin/getopt" || GNU_GETOPT="getopt"
|
|
|
|
|
readonly GNU_GETOPT
|
|
|
|
|
|
|
|
|
|
args=$(${GNU_GETOPT} -o "" -l "revision:" -n "$0" -- "$@")
|
|
|
|
|
eval set -- "${args}"
|
|
|
|
|
|
|
|
|
|
commitish="HEAD"
|
|
|
|
|
|
|
|
|
|
while true; do
|
|
|
|
|
case "$1" in
|
|
|
|
|
--revision) commitish="$2"; shift 2;;
|
|
|
|
|
--) break;;
|
|
|
|
|
*) echo "Unknown option $1"; exit 1;;
|
|
|
|
|
esac
|
|
|
|
|
done
|
|
|
|
|
|
2015-01-21 14:29:45 -08:00
|
|
|
readonly SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")"/.. && pwd)"
|
|
|
|
|
readonly TMPDIR=${TMPDIR:-/tmp} # why is this not set on mint?
|
2015-01-09 13:38:36 -08:00
|
|
|
|
2015-01-22 15:46:04 -08:00
|
|
|
version=$(cd "${SOURCE_DIR}" && git rev-parse "${commitish}")
|
2015-01-21 15:52:10 -08:00
|
|
|
bundle_dir=$(mktemp -d -t box 2>/dev/null || mktemp -d box-XXXXXXXXXX --tmpdir=$TMPDIR)
|
|
|
|
|
bundle_file="${TMPDIR}/box-${version}.tar.gz"
|
2015-01-09 13:38:36 -08:00
|
|
|
|
2015-01-21 14:29:45 -08:00
|
|
|
chmod "o+rx,g+rx" "${bundle_dir}" # otherwise extracted tarball director won't be readable by others/group
|
|
|
|
|
echo "Checking out code [${version}] into ${bundle_dir}"
|
|
|
|
|
(cd "${SOURCE_DIR}" && git archive --format=tar HEAD | (cd "${bundle_dir}" && tar xf -))
|
2015-01-09 13:38:36 -08:00
|
|
|
|
|
|
|
|
echo "Installing modules"
|
2015-01-21 14:29:45 -08:00
|
|
|
cd "${bundle_dir}" && npm install --production
|
2015-01-09 13:38:36 -08:00
|
|
|
|
2015-01-21 14:29:45 -08:00
|
|
|
cd "${bundle_dir}" && tar czvf "${bundle_file}" .
|
2015-01-09 13:38:36 -08:00
|
|
|
|
|
|
|
|
echo "Uploading bundle to S3"
|
2015-02-11 10:54:36 -08:00
|
|
|
s3cmd --acl-public --access_key="${AWS_BOX_RELEASE_ACCESS_KEY}" --secret_key="${AWS_BOX_RELEASE_SECRET_KEY}" --no-mime-magic put "${bundle_file}" "s3://cloudron-releases/box-${version}.tar.gz"
|
2015-01-09 13:38:36 -08:00
|
|
|
|
2015-01-21 14:29:45 -08:00
|
|
|
echo "Cleaning up ${bundle_dir}"
|
|
|
|
|
rm -rf "${bundle_dir}" "${bundle_file}"
|
2015-01-09 13:38:36 -08:00
|
|
|
|