#!/usr/bin/env bash

set -euo pipefail
set -x

# upload new version of bazel
script_dir="$(dirname "$(readlink --canonicalize "${BASH_SOURCE[0]}")")"
deb="$1"
bazel_sha="$(sha256sum "$deb" | awk '{ print $1; }')"
s3_path="zoox-third-party/$bazel_sha/$(basename "$deb")"

aws --endpoint-url=https://z3.zooxlabs.com \
    --profile z3 \
    s3 cp "$deb" "s3://$s3_path" \
    --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers

echo "---

# name of the bazel deb
bazel_deb: \"$(basename "$deb")\"

# sha of the bazel deb
bazel_sha: \"$bazel_sha\"" > "$script_dir/vars/bazel.yml"
