#!/bin/bash

VERSION=$1

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

echo "Downloading gdu-$VERSION..."

wget "https://github.com/dundee/gdu/archive/v$VERSION/gdu-$VERSION.tar.gz"

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

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

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

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

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

rm -rf gdu-$VERSION
rm -rf go-modules-gdu-$VERSION
