#! /bin/sh
SOLO_NAME=${SOLO_NAME-agoric}
SOLO_HOME=${SOLO_HOME-$SOLO_NAME}
PORT=${PORT-8000}
HOST_PORT=${HOST_PORT-$PORT}
IMAGE=agoric/cosmic-swingset-solo:latest
case "$1" in
--pull)
  shift
  docker pull "$IMAGE"
  ;;
esac

if test "$1" = shell; then
  FLAGS=--entrypoint=/bin/bash
  ARGS=
  shift
else
  set dummy setup --webport=$PORT --webhost=0.0.0.0 ${1+"$@"}
  shift
fi
exec docker run \
  -p127.0.0.1:$HOST_PORT:$PORT \
  --volume=ag-solo-state:/usr/src/app/solo \
  --volume=$HOME/.agoric:/root/.agoric \
  -eAG_SOLO_BASEDIR="$SOLO_HOME" \
  --rm -it $FLAGS \
  "$IMAGE" ${1+"$@"}
