#!/usr/bin/env bash

set -euo pipefail
set -x

# upload new version of java
script_dir="$(dirname "$(readlink --canonicalize "${BASH_SOURCE[0]}")")"
deb="$1"
java_version="$(dpkg-deb --showformat='${Version}' --show "$deb")"
java_sha="$(sha256sum "$deb" | awk '{ print $1; }')"
s3_path="zoox-third-party/$java_sha/$(basename "$deb")"

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

echo "---

# name of the java deb
java_deb: \"$(basename "$deb")\"

# sha of the java deb
java_sha: \"$java_sha\"

# java version
java_version: \"$java_version\"" > "$script_dir/vars/java.yml"
