#!/bin/bash

VERSION=$1

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

echo "Downloading hugo-$VERSION..."

wget "https://github.com/gohugoio/hugo/archive/v$VERSION/hugo-$VERSION.tar.gz"

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

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

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

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

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

rm -rf hugo-$VERSION
rm -rf go-modules-hugo-$VERSION
