#!/bin/bash

VERSION=$1

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

echo "Downloading buildah-$VERSION..."

wget "https://github.com/containers/buildah/archive/v$VERSION/buildah-$VERSION.tar.gz"

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

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

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

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

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

rm -rf buildah-$VERSION
rm -rf go-modules-buildah-$VERSION
