#!/bin/bash

VERSION=$1

rm -rf editorconfig-checker-*.tar.?z go-modules-editorconfig-checker*

echo "Downloading editorconfig-checker-$VERSION..."

wget "https://github.com/editorconfig-checker/editorconfig-checker/archive/v$VERSION/editorconfig-checker-$VERSION.tar.gz"

tar xf editorconfig-checker-$VERSION.tar.gz
mkdir -p go-modules-editorconfig-checker-$VERSION

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

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

plzip -9 go-modules-editorconfig-checker-$VERSION.tar

gunzip editorconfig-checker-$VERSION.tar.gz
plzip -9 editorconfig-checker-$VERSION.tar

rm -rf editorconfig-checker-$VERSION
rm -rf go-modules-editorconfig-checker-$VERSION
