#!/bin/sh

# This script installs all the required dependencies and command line tools to convert IFC files into XKT files,
# so that the BIM models can be viewed via the Xeokit BIM viewer.
#
# Run this script on your worker container like this to enable your Docker based development setup to convert IFC
# files to XKT:
# $ docker compose exec -u root worker setup-bim

apt-get install -y wget unzip

tmpdir=$(mktemp -d)
cd $tmpdir

# Install XKT converter
npm install -g @xeokit/xeokit-gltf-to-xkt@1.3.1

# Install COLLADA2GLTF
wget --no-verbose --tries 3 https://github.com/KhronosGroup/COLLADA2GLTF/releases/download/v2.1.5/COLLADA2GLTF-v2.1.5-linux.zip
unzip -q COLLADA2GLTF-v2.1.5-linux.zip
mv COLLADA2GLTF-bin "/usr/local/bin/COLLADA2GLTF"

# IFCconvert
wget --no-verbose --tries 3 https://s3.amazonaws.com/ifcopenshell-builds/IfcConvert-v0.7.11-fea8e3a-linux64.zip
unzip -q IfcConvert-v0.7.11-fea8e3a-linux64.zip
mv IfcConvert "/usr/local/bin/IfcConvert"

wget --no-verbose --tries 3 https://github.com/opf/xeokit-metadata/releases/download/v1.1.0/xeokit-metadata-linux-x64.tar.gz
tar -zxvf xeokit-metadata-linux-x64.tar.gz
chmod +x xeokit-metadata-linux-x64/xeokit-metadata
cp -r xeokit-metadata-linux-x64/ "/usr/lib/xeokit-metadata"
ln -s /usr/lib/xeokit-metadata/xeokit-metadata /usr/local/bin/xeokit-metadata

cd /
rm -rf $tmpdir
