#!/usr/bin/env sh
set -eu

SCRIPT_DIR="$(CDPATH= cd -- "$(dirname "$0")" && pwd)"
REPO_ROOT="$(CDPATH= cd -- "${SCRIPT_DIR}/.." && pwd)"
TOOL_DIR="${REPO_ROOT}/tools/linux_rollout"
LOCAL_BIN="${HOME}/.local/bin"

if [ -d "${LOCAL_BIN}" ]; then
  PATH="${LOCAL_BIN}:${PATH}"
fi
export PATH

cd "${TOOL_DIR}"

if [ ! -d deps/yaml_elixir ] || [ ! -d deps/ymlr ]; then
  mix deps.get
fi

exec mix run -e 'LinuxRollout.CLI.main(System.argv())' -- "$@" --cwd "${REPO_ROOT}"
