#!/usr/bin/env sh

declare -a premium_checks_dirs=(
"1.1.10"
"1.4.1"
"1.4.2"
"1.5.1"
"2.1.1"
"2.1.2"
"2.1.3"
"2.1.4"
"2.1.5"
"2.1.6"
"2.1.7"
"2.1.8"
"2.2.10"
"2.2.3.identical"
"2.2.4.identical"
"2.2.5.identical"
"2.2.6"
"2.2.6.identical"
"2.2.8"
"2.2.8.identical"
"2.2.9"
)

declare -a cloud_providers=("aws" "azure" "gcp" "dev")

wget https://github.com/trento-project/runner/archive/refs/tags/$1.tar.gz
mv $1.tar.gz runner-$1.tar.gz
tar -xvzf runner-$1.tar.gz
rm -rf runner-$1.tar.gz

GIT_SSL_NO_VERIFY=true git clone https://gitlab.suse.de/trento-project/trento-premium.git

cd runner-$1

for check in "${premium_checks_dirs[@]}"
do
  cp -rf ../trento-premium/runner/ansible/roles/checks/$check runner/ansible/roles/checks/
done

for cloud_provider in "${cloud_providers[@]}"
do
  cp -f ../trento-premium/runner/ansible/vars/$cloud_provider/20-premium.yml runner/ansible/vars/$cloud_provider/
done

go mod download
go mod vendor

tar -cvzf vendor.tar.gz vendor/
mv vendor.tar.gz ../
rm -rf vendor/

cd ..
tar -cvzf runner-$1.tar.gz runner-$1/
rm -rf runner-$1
rm -rf trento-premium

