#!/bin/bash

VERSION=$1

rm -rf gmailctl-*.tar.?z go-modules-gmailctl*

echo "Downloading gmailctl-$VERSION..."

wget "https://github.com/mbrt/gmailctl/archive/v$VERSION/gmailctl-$VERSION.tar.gz"

tar xf gmailctl-$VERSION.tar.gz
mkdir -p go-modules-gmailctl-$VERSION

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

cd go-modules-gmailctl-$VERSION/pkg/mod/cache/
  mv download go-modules-gmailctl-$VERSION
  tar cf ../../../../go-modules-gmailctl-$VERSION.tar go-modules-gmailctl-$VERSION
cd ../../../../

plzip -9 go-modules-gmailctl-$VERSION.tar

gunzip gmailctl-$VERSION.tar.gz
plzip -9 gmailctl-$VERSION.tar

rm -rf gmailctl-$VERSION
rm -rf go-modules-gmailctl-$VERSION
