#!/bin/bash

VERSION=$1

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

echo "Downloading gcx-$VERSION..."

wget "https://github.com/grafana/gcx/archive/v$VERSION/gcx-$VERSION.tar.gz"

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

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

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

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

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

rm -rf gcx-$VERSION
rm -rf go-modules-gcx-$VERSION
