#!/bin/bash

#set -e
set -vx

echo -e "*****************************\n* Checkout TTF002 sources\n*****************************\n"
cd ${HOME}/dev || exit 1

git clone --recurse-submodules -b TTF0002 --single-branch https://forge.etsi.org/gitlab/ITS/ITS.git TTF0002_Its
cd /home/etsi/dev/TTF0002_Its/ttcn/LibIts
git checkout TTF0002
cd /home/etsi/dev/TTF0002_Its/scripts
chmod 775 *.bash devenv.bash.*
cd /home/etsi
ln -sf /home/etsi/dev/TTF0002_Its/scripts/devenv.bash.ubuntu /home/etsi/devenv.bash
ls -ltr /home/etsi

echo -e "*****************************\n* Init Workspace\n*****************************\n"
mkdir -p ${HOME}/dev/Workspace/TTF0002/bin/asn1
cd ${HOME}/dev/Workspace/TTF0002
ln -s ../../TTF0002_Its/testdata
ln -s ../../TTF0002_Its/data

echo -e "*****************************\n* Make ASN.1 sources\n*****************************\n"
cd ${HOME}/dev/Workspace/TTF0002/bin/asn1
make -f ../../../../TTF0002_Its/asn1/Makefile

echo -e "*****************************\n* Make Certificate generator \n*****************************\n"
# make V3 certificate generators
cd ${HOME}/dev/TTF0002_Its/tools/itscertgen/asn1certgen
make

# generate certificates
cd ${HOME}/dev/TTF0002_Its/data/v3
make

echo -e "*****************************\n* Install latest ETSI ITS plugtest certificates\n*****************************\n"
cp /home/etsi/dev/TTF0002_Its/data/v3/asn1c_cert.tar.bz2 /home/etsi/tmp
cd /home/etsi/tmp
tar xvjf ./asn1c_cert.tar.bz2

cd ${HOME}

exit 0
