#!/usr/bin/env bash
# set env var image to specify another docker image
: "${image:=docker.io/martinlaurent/ascli}"
# set env var version to specify another image version (default: latest version)
: "${version:=latest}"
# set env var imgtag to specify a specific image/version
: "${imgtag=$image:$version}"
# set env var `docker` to podman, to use podman
: "${docker:=docker}"
# set env var `docker_args` to add options to docker run (then, transform this var into array) # spellcheck disable=SC2086
read -a add_dock_args <<< $docker_args
# set env var ASCLI_HOME to set the config folder on host
: "${ASCLI_HOME:=$HOME/.aspera/ascli}"
# main config folder for ascli in container (same value as in `Dockerfile`)
ascli_home_container=/home/cliuser/.aspera/ascli
if test ! -d "$ASCLI_HOME";then
	echo "creating folder: $ASCLI_HOME"
	# create it if necessary to allow mounting the volume in container
	mkdir -p "$ASCLI_HOME"
fi
exec $docker run \
--rm \
--tty \
--interactive \
--user root \
--env ASCLI_HOME="$ascli_home_container" \
--volume "$ASCLI_HOME:$ascli_home_container:z" \
"${add_dock_args[@]}" \
"$imgtag" \
"$@"