#!/usr/bin/env bash
# A simple script to upload diffmerge debian to s3. To upload a new version
# 1. Download the diffmerge debian
# 2. Update `diffmerge_deb_file` variable to the new version
# 3. Run this script to upload to s3
# 4. Update vars/main.yaml

set -euo pipefail
diffmerge_deb_file="diffmerge_4.2.0.697.stable_amd64.deb"

tmp_dir=$(mktemp -d)
data=()

sha_256="$(sha256sum "${diffmerge_deb_file}" | awk '{print $1}')"
s3_url="s3://zoox-third-party/${sha_256}/${diffmerge_deb_file}"
if aws s3 ls "${s3_url}" > /dev/null ; then
    echo "WARNING: ${diffmerge_deb_file} is already in S3. Run 'aws s3 rm ${s3_url}' if you'd like to re-upload."
    echo ""
else
    aws s3 cp --quiet "${diffmerge_deb_file}" "s3://zoox-third-party/${sha_256}/${diffmerge_deb_file}" --grants read=uri=http://acs.amazonaws.com/groups/global/AllUsers
fi

data+=("url: https://s3-us-west-1.amazonaws.com/zoox-third-party/${sha_256}/${diffmerge_deb_file}, SHA256: ${sha_256}")


echo "Uploaded urls and their SHAs are "
printf '%s\n' "${data[@]}"
