#!/bin/bash

set -eu

bindir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
rootdir="$( cd $bindir/.. && pwd )"

system=$(uname -s)

if [ "$system" = "Darwin" ]; then
  bin=$rootdir/target/cli/darwin/conduit
elif [ "$system" = "Linux" ]; then
  bin=$rootdir/target/cli/linux/conduit
else
  echo "unknown system: $system" >&2
  exit 1
fi

# build conduit executable if it does not exist
if [ ! -f $bin ]; then
  $bindir/docker-build-cli-bin >/dev/null
fi

exec $bin "$@"
