#!/bin/bash

VERSION=$1

rm -rf okta-aws-cli-*.tar.?z go-modules-okta-aws-cli*

echo "Downloading okta-aws-cli-$VERSION..."

wget "https://github.com/okta/okta-aws-cli/archive/v$VERSION/okta-aws-cli-$VERSION.tar.gz"

tar xf okta-aws-cli-$VERSION.tar.gz
mkdir -p go-modules-okta-aws-cli-$VERSION

cd okta-aws-cli-$VERSION
  export GOPATH=$(realpath ../go-modules-okta-aws-cli-$VERSION)
  go mod download
cd ..

cd go-modules-okta-aws-cli-$VERSION/pkg/mod/cache/
  mv download go-modules-okta-aws-cli-$VERSION
  tar cf ../../../../go-modules-okta-aws-cli-$VERSION.tar go-modules-okta-aws-cli-$VERSION
cd ../../../../

plzip -9 go-modules-okta-aws-cli-$VERSION.tar

gunzip okta-aws-cli-$VERSION.tar.gz
plzip -9 okta-aws-cli-$VERSION.tar

rm -rf okta-aws-cli-$VERSION
rm -rf go-modules-okta-aws-cli-$VERSION
