#!/bin/sh
# Emergency recovery inside the container or local checkout.
set -eu

DATA_DIR="${LUMINARY_DATA:-/data}"
REPO_DIR="${LUMINARY_HOME:-/opt/luminary}"

if [ -x /usr/local/bin/luminary-recover ]; then
  exec /usr/local/bin/luminary-recover -data-dir "$DATA_DIR" "$@"
fi

if [ -x "${REPO_DIR}/luminary-recover" ]; then
  exec "${REPO_DIR}/luminary-recover" -data-dir "$DATA_DIR" "$@"
fi

if [ -f "${REPO_DIR}/go.mod" ]; then
  cd "$REPO_DIR"
  export CGO_ENABLED=0
  exec go run ./cmd/luminary-recover -data-dir "$DATA_DIR" "$@"
fi

echo "luminary-recover binary not found" >&2
exit 1
