#!/usr/bin/env bash
set -euo pipefail

# Move the labeling db to local machine.
echo "Copying labeling.db..."
user=$(whoami)
sudo mkdir --parents /var/zoox-labeling
sudo chown ${user}:${user} /var/zoox-labeling
aws s3 cp s3://zoox-labeling-dev/reference-data-set/labeling.db /var/zoox-labeling
# Sync the reference dataset to my private bucket.
echo "Copying reference dataset..."
set +e
aws s3 sync s3://zoox-labeling-dev/reference-data-set s3://zoox-labeling-dev/"${user}"
retval=$?
set -e
if [ "${retval}" -ne "0" ]; then
  echo "Could not copy reference dataset on s3 to s3://zoox-labeling-dev/${user}. Ensure that you have r/w privileges to s3://zoox-labeling-dev/"
  exit 1
fi
cat <<EOF
Setup complete! Add:

  export LABELING_ENV=development

to your .bashrc to ensure that you login to the development environment whenever you open a new shell.
EOF
