#!/bin/bash

VERSION=$1

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

echo "Downloading trivy-$VERSION..."

wget "https://github.com/aquasecurity/trivy/archive/v$VERSION/trivy-$VERSION.tar.gz"

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

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

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

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

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

rm -rf trivy-$VERSION
rm -rf go-modules-trivy-$VERSION
