#!/bin/bash
source "$ROOT_PATH"/scripts/common.sh
echo "##################### UPLOAD TO S3 ##########################"

echo_green "Uploading artifact to the S3 bucket begins"

if [[ "${REPO_NAME}" == 'sx-core-route-controller' ]]; then
  rc_output_package="routecontroller/${ENV_NAME}/${NEW_VERSION}/rc_output.tar.gz"
  aws s3 cp $rc_output_package s3://${SOURCE_BUCKET}/${BUCKET_UPLOAD_PATH}/${NEW_VERSION}.tar.gz || handle_error "failed to upload artifact to ${SOURCE_BUCKET}"
  aws s3 sync s3://${SOURCE_BUCKET} s3://${DESTINATION_BUCKET} --exclude "*" --include "${BUCKET_UPLOAD_PATH}/*" || handle_error "failed to replicate artifact to ${DESTINATION_BUCKET}"
else
  aws s3 cp "${NEW_VERSION}.tar.gz" s3://p81-core/hatunnel/ || handle_error "failed to upload artifact to p81-core bucket"
fi