#!/bin/bash

# this command is ran from the root of the deadlock-extension
#   given one argument (the path to the mission directory)


# generate the recorder
cd src/recorder/ || (echo "src/recorder/ not found! Are you running from deadlock extension directory?" && return 1)
npm install
cd ../../
npm run build-recorder

# remove container
docker rm -f test-recorder

# if you want to delete the image, uncomment the following line
# docker rmi "$(docker images | grep 'registry.takima.io/deadlock/deadlock-challenges/code_desktop_exemple')"

PP=(docker run --name test-recorder --privileged
    -v \""$1"/.config\":\"/home/config/\"
    -v \""$1"/mounted\":\"/home/deadlock/mission/\"
    -v \""$HOME"/.deadlock/.ssh\":\"/tmp/.ssh\"
    -v \""$(pwd)"/out/recorder.js\":\"/deadlock/recorder.js\"
    registry.takima.io/deadlock/deadlock-challenges/code_desktop_exemple:0.1)

eval "${PP[*]}"