#!/bin/bash

VERSION=$1

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

echo "Downloading xq-$VERSION..."

wget "https://github.com/sibprogrammer/xq/archive/v$VERSION/xq-$VERSION.tar.gz"

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

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

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

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

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

rm -rf xq-$VERSION
rm -rf go-modules-xq-$VERSION
